pub struct PQDistanceTable<S: EmbeddingSpace, const M: usize, const NBITS: usize>{ /* private fields */ }Expand description
Precomputed distance table for Asymmetric Distance Computation (ADC).
Given a query vector, this table stores the squared distance from each query subvector to each centroid in that subspace. During search, the distance to an encoded vector is computed by summing table lookups.
Table layout: table[m * ksub + k] is the distance from query subvector
m to centroid k in subspace m.
The const generics must match the ProductQuantizer configuration:
- M: number of subquantizers
- NBITS: bits per centroid index
Implementations§
Source§impl<S: EmbeddingSpace, const M: usize, const NBITS: usize> PQDistanceTable<S, M, NBITS>
impl<S: EmbeddingSpace, const M: usize, const NBITS: usize> PQDistanceTable<S, M, NBITS>
pub fn new(table: Vec<S::DistanceValue>, ksub: usize) -> Self
Sourcepub fn distance(&self, code: &PQCode<M, NBITS>) -> S::DistanceValue
pub fn distance(&self, code: &PQCode<M, NBITS>) -> S::DistanceValue
Compute approximate distance to an encoded vector using table lookups.
This is the core of ADC: instead of computing the full distance, we sum precomputed partial distances from each subspace.
pub fn m(&self) -> usize
pub fn ksub(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<S, const M: usize, const NBITS: usize> Freeze for PQDistanceTable<S, M, NBITS>
impl<S, const M: usize, const NBITS: usize> RefUnwindSafe for PQDistanceTable<S, M, NBITS>
impl<S, const M: usize, const NBITS: usize> Send for PQDistanceTable<S, M, NBITS>
impl<S, const M: usize, const NBITS: usize> Sync for PQDistanceTable<S, M, NBITS>
impl<S, const M: usize, const NBITS: usize> Unpin for PQDistanceTable<S, M, NBITS>
impl<S, const M: usize, const NBITS: usize> UnsafeUnpin for PQDistanceTable<S, M, NBITS>
impl<S, const M: usize, const NBITS: usize> UnwindSafe for PQDistanceTable<S, M, NBITS>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more