pub struct ProductQuantizer { /* private fields */ }Expand description
Product Quantizer for high compression
Achieves 8-32x compression by dividing vectors into sub-vectors and quantizing each with a codebook.
Implementations§
Source§impl ProductQuantizer
impl ProductQuantizer
Sourcepub fn new(dimension: usize, num_subquantizers: usize, bits: u8) -> Result<Self>
pub fn new(dimension: usize, num_subquantizers: usize, bits: u8) -> Result<Self>
Create a new product quantizer
§Arguments
dimension- Vector dimension (must be divisible by num_subquantizers)num_subquantizers- Number of sub-quantizers (typically 8, 16, or 32)bits- Bits per code (typically 8, giving 256 centroids)
Sourcepub fn standard(dimension: usize) -> Result<Self>
pub fn standard(dimension: usize) -> Result<Self>
Create a standard PQ with 8 sub-quantizers and 8 bits
Sourcepub fn train(
&mut self,
vectors: &[Vec<f32>],
max_iterations: usize,
) -> Result<()>
pub fn train( &mut self, vectors: &[Vec<f32>], max_iterations: usize, ) -> Result<()>
Train the product quantizer using k-means clustering
§Arguments
vectors- Training vectorsmax_iterations- Maximum k-means iterations
Sourcepub fn dequantize(&self, code: &PQCode) -> Result<Vec<f32>>
pub fn dequantize(&self, code: &PQCode) -> Result<Vec<f32>>
Dequantize PQ codes back to approximate vector
Sourcepub fn asymmetric_distance(&self, query: &[f32], code: &PQCode) -> Result<f32>
pub fn asymmetric_distance(&self, query: &[f32], code: &PQCode) -> Result<f32>
Compute asymmetric distance (query is not quantized)
This is the preferred method for search as it’s more accurate
Sourcepub fn compute_distance_table(&self, query: &[f32]) -> Result<Vec<Vec<f32>>>
pub fn compute_distance_table(&self, query: &[f32]) -> Result<Vec<Vec<f32>>>
Precompute distance tables for fast ADC (Asymmetric Distance Computation)
Returns a table[sq][centroid] = distance from query subvector to centroid
Sourcepub fn distance_from_table(&self, table: &[Vec<f32>], code: &PQCode) -> f32
pub fn distance_from_table(&self, table: &[Vec<f32>], code: &PQCode) -> f32
Fast distance computation using precomputed table
Sourcepub fn compression_ratio(&self) -> f32
pub fn compression_ratio(&self) -> f32
Get compression ratio
Sourcepub fn is_trained(&self) -> bool
pub fn is_trained(&self) -> bool
Check if trained
Trait Implementations§
Source§impl Clone for ProductQuantizer
impl Clone for ProductQuantizer
Source§fn clone(&self) -> ProductQuantizer
fn clone(&self) -> ProductQuantizer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ProductQuantizer
impl Debug for ProductQuantizer
Source§impl<'de> Deserialize<'de> for ProductQuantizer
impl<'de> Deserialize<'de> for ProductQuantizer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ProductQuantizer
impl RefUnwindSafe for ProductQuantizer
impl Send for ProductQuantizer
impl Sync for ProductQuantizer
impl Unpin for ProductQuantizer
impl UnwindSafe for ProductQuantizer
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.