Expand description
Distance computation for multi-vector representations.
The fallback path uses a double-loop kernel over
InnerProduct; the factory
returns cache-tiled SIMD kernels selected by MaxSimIsa.
§Example
use diskann_quantization::multi_vector::{
distance::{Chamfer, MaxSim, QueryMatRef},
MatRef, Standard,
};
use diskann_vector::{DistanceFunctionMut, PureDistanceFunction};
// Query: 2 vectors of dim 3 (wrapped as QueryMatRef)
let query_data = [1.0f32, 0.0, 0.0, 0.0, 1.0, 0.0];
let query: QueryMatRef<_> = MatRef::new(
Standard::new(2, 3).unwrap(),
&query_data,
).unwrap().into();
// Doc: 2 vectors of dim 3
let doc_data = [1.0f32, 0.0, 0.0, 0.0, 0.0, 1.0];
let doc = MatRef::new(
Standard::new(2, 3).unwrap(),
&doc_data,
).unwrap();
// Chamfer distance (sum of max similarities)
let chamfer_dist = Chamfer::evaluate(query, doc);
// MaxSim (per-query-vector scores)
let mut scores = vec![0.0f32; 2];
let mut max_sim = MaxSim::new(&mut scores);
max_sim.evaluate(query, doc);
// scores[0] = -1.0 (query[0] matches doc[0]: negated max inner product)
// scores[1] = 0.0 (query[1] has no good match: max IP was 0)Structs§
- BoxErase
- Default boxing
Eraseimpl. - Chamfer
- Asymmetric Chamfer distance for multi-vector similarity.
- MaxSim
- Computes per-query-vector maximum similarities to document vectors.
- NotSupported
- Returned by
build_max_simwhen the requested ISA cannot be produced on the current host (e.g. x86_64 V4 requested on a non-AVX512 CPU, or Neon requested on x86_64). - Query
MatRef - A query matrix view for asymmetric distance functions.
Enums§
- MaxSim
Error - Error type for
MaxSimoperations. - MaxSim
Isa - Instruction Set Architecture (ISA) selector for which multi-vector MaxSim kernel to build.
Traits§
- Erase
- “Bring your own type erasure” visitor: the factory hands a concrete
kernel to
Erase::erase, which decides how to package it (e.g. asBox<dyn MaxSimKernel<T>>viaBoxErase, a chamfer-only closure, a batched evaluator, …). - MaxSim
Element - Scalar element types accepted by
build_max_sim. - MaxSim
Kernel - Object-safe interface for computing per-query MaxSim scores.
Functions§
- build_
max_ sim - Build a multi-vector MaxSim kernel for any
MaxSimElementtype.