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

Function ground_truth

nodedb-vector/src/codec_index/search.rs:213–221  ·  view source on GitHub ↗

Brute-force top-k by L2-squared.

(vecs: &[Vec<f32>], query: &[f32], k: usize)

Source from the content-addressed store, hash-verified

211
212 /// Brute-force top-k by L2-squared.
213 fn ground_truth(vecs: &[Vec<f32>], query: &[f32], k: usize) -> Vec<u32> {
214 let mut scored: Vec<(f32, u32)> = vecs
215 .iter()
216 .enumerate()
217 .map(|(i, v)| (l2_squared(query, v), i as u32))
218 .collect();
219 scored.sort_unstable_by(|a, b| a.0.total_cmp(&b.0));
220 scored.into_iter().take(k).map(|(_, id)| id).collect()
221 }
222
223 // ── Sq8 round-trip ────────────────────────────────────────────────────────
224

Calls 4

collectMethod · 0.80
l2_squaredFunction · 0.50
iterMethod · 0.45
takeMethod · 0.45

Tested by 2