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)
| 43 | /// |
| 44 | /// Returns 0.0 if either side is empty. |
| 45 | pub 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 |