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

Function batch_distances

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

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)

Source from the content-addressed store, hash-verified

16/// Returns a Vec of distances, one per candidate, in the same order.
17/// Processes candidates in batches for better cache behavior.
18pub 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///

Callers 1

Calls 3

collectMethod · 0.80
distanceFunction · 0.50
iterMethod · 0.45

Tested by 1