Skip to main content

PQDistanceTable

Struct PQDistanceTable 

Source
pub struct PQDistanceTable<S: EmbeddingSpace, const M: usize, const NBITS: usize>
where [(); { _ }]:,
{ /* 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>
where [(); { _ }]:,

Source

pub const KSUB: usize

Number of centroids per subspace (2^NBITS)

Source

pub fn new(table: Vec<S::DistanceValue>, ksub: usize) -> Self

Source

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.

Source

pub fn m(&self) -> usize

Source

pub fn ksub(&self) -> usize

Trait Implementations§

Source§

impl<S: EmbeddingSpace, const M: usize, const NBITS: usize> Debug for PQDistanceTable<S, M, NBITS>
where [(); { _ }]:,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V