pub struct SDCTable<const M: usize, const NBITS: usize>{ /* private fields */ }Expand description
Precomputed centroid-to-centroid distances for Symmetric Distance Computation (SDC).
SDC enables fast distance computation between two PQ codes without needing the original vectors. During quantizer training, we precompute squared L2 distances between all pairs of centroids in each subspace.
Table layout: table[m * ksub * ksub + i * ksub + j] is the squared distance
between centroid i and centroid j in subspace m.
The const generics must match the ProductQuantizer configuration:
- M: number of subquantizers
- NBITS: bits per centroid index
Implementations§
Source§impl<const M: usize, const NBITS: usize> SDCTable<M, NBITS>
impl<const M: usize, const NBITS: usize> SDCTable<M, NBITS>
Sourcepub fn from_centroids(centroids: &[f32], dsub: usize) -> Self
pub fn from_centroids(centroids: &[f32], dsub: usize) -> Self
Create an SDCTable from centroids using squared L2 distance.
§Arguments
centroids- Flat centroid storage: M * ksub * dsub floatsdsub- Dimension of each subspace
Sourcepub fn from_centroids_with_distance(
centroids: &[f32],
dsub: usize,
subspace_distance: impl Fn(&[f32], &[f32]) -> f32,
) -> Self
pub fn from_centroids_with_distance( centroids: &[f32], dsub: usize, subspace_distance: impl Fn(&[f32], &[f32]) -> f32, ) -> Self
Create an SDCTable from centroids using a custom subspace distance function.
The distance function receives two subvector slices of length dsub
and returns a non-negative distance value.
§Arguments
centroids- Flat centroid storage: M * ksub * dsub floatsdsub- Dimension of each subspacesubspace_distance- Distance function for subvector pairs
Sourcepub fn distance(
&self,
code1: &PQCode<M, NBITS>,
code2: &PQCode<M, NBITS>,
) -> f32
pub fn distance( &self, code1: &PQCode<M, NBITS>, code2: &PQCode<M, NBITS>, ) -> f32
Compute approximate squared L2 distance between two PQ codes.
This is the core of SDC: sum precomputed centroid-to-centroid distances for each subspace.
Sourcepub fn table_data(&self) -> &[f32]
pub fn table_data(&self) -> &[f32]
Access the raw table data for serialization.