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

Function maxsim

nodedb-vector/src/multivec/scoring.rs:45–57  ·  view source on GitHub ↗

Compute the MaxSim score between a query multi-vector and a document multi-vector. `score(Q, D) = Σᵢ maxⱼ sim(qᵢ, dⱼ)` Returns 0.0 if either side is empty.

(query: &[Vec<f32>], doc: &[Vec<f32>], metric: DistanceMetric)

Source from the content-addressed store, hash-verified

43///
44/// Returns 0.0 if either side is empty.
45pub fn maxsim(query: &[Vec<f32>], doc: &[Vec<f32>], metric: DistanceMetric) -> f32 {
46 if query.is_empty() || doc.is_empty() {
47 return 0.0;
48 }
49 query
50 .iter()
51 .map(|q| {
52 doc.iter()
53 .map(|d| dist_to_sim(scalar_distance(q, d, metric), metric))
54 .fold(f32::NEG_INFINITY, f32::max)
55 })
56 .sum()
57}
58
59/// Budgeted MaxSim: only uses the first `budget` query vectors (Matryoshka
60/// ordering). When `budget` equals or exceeds `query.len()` this is

Calls 6

dist_to_simFunction · 0.85
scalar_distanceFunction · 0.85
sumMethod · 0.80
foldMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45