MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / train

Method train

nodedb-vector/src/rerank/codecs/bbq.rs:237–255  ·  view source on GitHub ↗

Calibrate from a sample of vectors. Validates that: - `samples` is non-empty. - Every sample has length `self.dim`. On success, stores the calibrated codec; subsequent `encode` / `distance_prepared` calls will succeed.

(&mut self, samples: &[&[f32]])

Source from the content-addressed store, hash-verified

235 /// On success, stores the calibrated codec; subsequent `encode` /
236 /// `distance_prepared` calls will succeed.
237 fn train(&mut self, samples: &[&[f32]]) -> Result<(), RerankError> {
238 if samples.is_empty() {
239 return Err(RerankError::BadInput(
240 "bbq train: empty sample set".to_string(),
241 ));
242 }
243 for s in samples {
244 if s.len() != self.dim {
245 return Err(RerankError::BadInput(format!(
246 "bbq train: sample has len {} but codec dim is {}",
247 s.len(),
248 self.dim
249 )));
250 }
251 }
252 let codec = BbqCodec::calibrate(samples, self.dim, self.oversample);
253 self.codec = Some(codec);
254 Ok(())
255 }
256}
257
258// ── Tests ─────────────────────────────────────────────────────────────────────

Callers 3

trainedFunction · 0.45

Calls 3

to_stringMethod · 0.80
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by 2