maxsim

Function maxsim 

Source
pub fn maxsim(
    query: &MultiVectorEmbedding,
    document: &MultiVectorEmbedding,
) -> f32
Expand description

Compute the MaxSim score between a query and document multi-vector.

MaxSim sums the maximum dot product for each query token across all document tokens:

MaxSim(Q, D) = sum_{q_i in Q} max_{d_j in D} (q_i · d_j)

§Arguments

  • query - Query multi-vector embedding (per-token embeddings)
  • document - Document multi-vector embedding (per-token embeddings)

§Returns

The MaxSim score (higher is more similar).

§Panics

Panics if query and document have different dimensions.

§Example

use manifoldb_vector::ops::maxsim::maxsim;
use manifoldb_vector::types::MultiVectorEmbedding;

let query = MultiVectorEmbedding::new(vec![
    vec![1.0, 0.0, 0.0],  // Query token 1
    vec![0.0, 1.0, 0.0],  // Query token 2
]).unwrap();

let doc = MultiVectorEmbedding::new(vec![
    vec![1.0, 0.0, 0.0],  // Doc token 1 (matches query token 1)
    vec![0.0, 0.5, 0.5],  // Doc token 2
    vec![0.0, 0.0, 1.0],  // Doc token 3
]).unwrap();

let score = maxsim(&query, &doc);
// Query token 1: max with doc tokens = 1.0 (with doc token 1)
// Query token 2: max with doc tokens = 0.5 (with doc token 2)
// Total MaxSim = 1.0 + 0.5 = 1.5
assert!((score - 1.5).abs() < 1e-6);