pub fn maxsim(query_tokens: &[&[f32]], doc_tokens: &[&[f32]]) -> f32Available on crate feature
maxsim only.Expand description
MaxSim: sum over query tokens of max dot product with any doc token.
§Arguments
query_tokens- Query token embeddings (first argument = query)doc_tokens- Document token embeddings
§Returns
Sum of maximum similarities. Returns 0.0 if either input is empty.
§Complexity
- Time: O(|Q| x |D| x dim)
- Space: O(1)
§SIMD Optimization
Automatically dispatches to AVX-512 or AVX2 optimized kernels on x86_64 that process multiple vectors without repeated dispatch overhead.
§Example
use innr::maxsim;
// Query: two tokens [1,0] and [0,1]
// Doc: three tokens, best matches are doc[0] for q[0], doc[1] for q[1]
let q1 = [1.0f32, 0.0];
let q2 = [0.0f32, 1.0];
let d1 = [0.9f32, 0.1]; // best match for q1
let d2 = [0.1f32, 0.9]; // best match for q2
let d3 = [0.5f32, 0.5];
let query: &[&[f32]] = &[&q1, &q2];
let doc: &[&[f32]] = &[&d1, &d2, &d3];
let score = maxsim(query, doc);
// score = max(0.9, 0.1, 0.5) + max(0.1, 0.9, 0.5) = 0.9 + 0.9 = 1.8
assert!((score - 1.8).abs() < 0.01);