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

Function is_diverse_batched

nodedb-vector/src/batch_distance.rs:31–44  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

29/// Returns true if the candidate is "diverse" (closer to query than to
30/// every selected neighbor).
31pub 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)]
47mod tests {

Callers

nothing calls this directly

Calls 1

distanceFunction · 0.50

Tested by

no test coverage detected