Skip to main content

diskann_quantization/multi_vector/distance/
mod.rs

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license.
3
4//! Distance computation for multi-vector representations.
5//!
6//! The fallback path uses a double-loop kernel over
7//! [`InnerProduct`](diskann_vector::distance::InnerProduct); the factory
8//! returns cache-tiled SIMD kernels selected by [`MaxSimIsa`].
9//!
10//! # Example
11//!
12//! ```
13//! use diskann_quantization::multi_vector::{
14//!     distance::{Chamfer, MaxSim, QueryMatRef},
15//!     MatRef, Standard,
16//! };
17//! use diskann_vector::{DistanceFunctionMut, PureDistanceFunction};
18//!
19//! // Query: 2 vectors of dim 3 (wrapped as QueryMatRef)
20//! let query_data = [1.0f32, 0.0, 0.0, 0.0, 1.0, 0.0];
21//! let query: QueryMatRef<_> = MatRef::new(
22//!     Standard::new(2, 3).unwrap(),
23//!     &query_data,
24//! ).unwrap().into();
25//!
26//! // Doc: 2 vectors of dim 3
27//! let doc_data = [1.0f32, 0.0, 0.0, 0.0, 0.0, 1.0];
28//! let doc = MatRef::new(
29//!     Standard::new(2, 3).unwrap(),
30//!     &doc_data,
31//! ).unwrap();
32//!
33//! // Chamfer distance (sum of max similarities)
34//! let chamfer_dist = Chamfer::evaluate(query, doc);
35//!
36//! // MaxSim (per-query-vector scores)
37//! let mut scores = vec![0.0f32; 2];
38//! let mut max_sim = MaxSim::new(&mut scores);
39//! max_sim.evaluate(query, doc);
40//! // scores[0] = -1.0 (query[0] matches doc[0]: negated max inner product)
41//! // scores[1] =  0.0 (query[1] has no good match: max IP was 0)
42//! ```
43
44mod factory;
45mod fallback;
46mod isa;
47mod kernel;
48mod kernels;
49mod max_sim;
50
51pub use factory::{MaxSimElement, build_max_sim};
52pub use fallback::QueryMatRef;
53pub use isa::{MaxSimIsa, NotSupported};
54pub use kernel::{BoxErase, Erase, MaxSimKernel};
55pub use max_sim::{Chamfer, MaxSim, MaxSimError};