Compute distances from a query vector to multiple candidate vectors. Returns a Vec of distances, one per candidate, in the same order. Processes candidates in batches for better cache behavior.
(query: &[f32], candidates: &[&[f32]], metric: DistanceMetric)
| 16 | /// Returns a Vec of distances, one per candidate, in the same order. |
| 17 | /// Processes candidates in batches for better cache behavior. |
| 18 | pub fn batch_distances(query: &[f32], candidates: &[&[f32]], metric: DistanceMetric) -> Vec<f32> { |
| 19 | candidates |
| 20 | .iter() |
| 21 | .map(|candidate| distance(query, candidate, metric)) |
| 22 | .collect() |
| 23 | } |
| 24 | |
| 25 | /// Precompute all pairwise distances between selected neighbors and a candidate. |
| 26 | /// |