Brute-force top-k by L2-squared.
(vecs: &[Vec<f32>], query: &[f32], k: usize)
| 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 |