Precompute all pairwise distances between selected neighbors and a candidate. For the diversity heuristic: given a candidate and the currently selected set, compute `distance(candidate, selected[i])` for all i. Returns true if the candidate is "diverse" (closer to query than to every selected neighbor).
(
candidate_vec: &[f32],
candidate_dist_to_query: f32,
selected_vecs: &[&[f32]],
metric: DistanceMetric,
)
| 29 | /// Returns true if the candidate is "diverse" (closer to query than to |
| 30 | /// every selected neighbor). |
| 31 | pub fn is_diverse_batched( |
| 32 | candidate_vec: &[f32], |
| 33 | candidate_dist_to_query: f32, |
| 34 | selected_vecs: &[&[f32]], |
| 35 | metric: DistanceMetric, |
| 36 | ) -> bool { |
| 37 | for selected in selected_vecs { |
| 38 | let dist_to_selected = distance(candidate_vec, selected, metric); |
| 39 | if candidate_dist_to_query > dist_to_selected { |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | true |
| 44 | } |
| 45 | |
| 46 | #[cfg(test)] |
| 47 | mod tests { |
nothing calls this directly
no test coverage detected