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

Function top1_recall_on_training_set

nodedb-codec/src/vector_quant/opq.rs:405–439  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

403
404 #[test]
405 fn top1_recall_on_training_set() {
406 let vecs = tiny_dataset();
407 let codec = train_tiny();
408 let refs: Vec<&[f32]> = vecs.iter().map(|v| v.as_slice()).collect();
409 let encoded: Vec<_> = refs.iter().map(|v| codec.encode(v)).collect();
410
411 let mut correct = 0usize;
412 for (i, v) in refs.iter().enumerate() {
413 let query = codec.prepare_query(v);
414 let best = encoded
415 .iter()
416 .enumerate()
417 .min_by(|(_, a), (_, b)| {
418 codec
419 .exact_asymmetric_distance(&query, a)
420 .partial_cmp(&codec.exact_asymmetric_distance(&query, b))
421 .unwrap_or(std::cmp::Ordering::Equal)
422 })
423 .map(|(idx, _)| idx)
424 .unwrap_or(usize::MAX);
425 if best == i {
426 correct += 1;
427 }
428 }
429 let recall = correct as f64 / vecs.len() as f64;
430 // SVD-Procrustes converges to ~70% on this minimum-size synthetic set
431 // (n=10, dim=8, m=2, k=4: 4 bits per vector, codespace collisions
432 // inevitable). Empirical measurements on SIFT1M with realistic
433 // (m=8, k=256, dim=128) routinely hit ≥0.95 — see bench harness.
434 assert!(
435 recall >= 0.70,
436 "top-1 recall on training set too low: {correct}/{} = {recall:.2}",
437 vecs.len()
438 );
439 }
440
441 #[test]
442 fn more_iterations_reduce_reconstruction_error() {

Callers

nothing calls this directly

Calls 10

tiny_datasetFunction · 0.85
train_tinyFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
as_sliceMethod · 0.45
encodeMethod · 0.45
prepare_queryMethod · 0.45
partial_cmpMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected