pub fn sparse_dot(a: &[(u32, f32)], b: &[(u32, f32)]) -> f32Expand description
Compute the dot product of two learned-sparse vectors.
Each input is a list of (term_id, weight) pairs. The result sums
weight_a * weight_b over terms present in both. Inputs need not be sorted;
duplicate term ids within a vector are summed. The two vectors must come from
the same model — term ids are not comparable across models.
§Examples
use uni_xervo::score::sparse_dot;
let a = vec![(1u32, 0.5f32), (4, 2.0)];
let b = vec![(4u32, 1.0f32), (9, 3.0)];
// only term 4 overlaps: 2.0 * 1.0 = 2.0
assert!((sparse_dot(&a, &b) - 2.0).abs() < 1e-6);