pub fn max_sim(query: &[Vec<f32>], doc: &[Vec<f32>]) -> f32Expand description
Compute the MaxSim late-interaction score between query and document tokens.
Late interaction (ColBERT) scores a query against a document as the sum, over each query token, of that token’s maximum similarity to any document token. Similarity is the dot product, so pre-normalized (unit-norm) per-token vectors — uni-xervo’s default — make it cosine similarity.
All vectors are expected to share the same dimensionality; mismatched
vectors are scored over their shared prefix. Returns 0.0 when either side
has no tokens.
§Examples
use uni_xervo::score::max_sim;
let query = vec![vec![1.0, 0.0], vec![0.0, 1.0]];
let doc = vec![vec![1.0, 0.0], vec![0.5, 0.5]];
// token 0 best-matches doc[0] (1.0); token 1 best-matches doc[1] (0.5).
assert!((max_sim(&query, &doc) - 1.5).abs() < 1e-6);