pub struct OptimizedProductQuantizer { /* private fields */ }Expand description
Optimized Product Quantization (OPQ)
OPQ extends PQ by learning a rotation matrix that minimizes quantization error. It achieves better accuracy than standard PQ at the same compression ratio.
Implementations§
Source§impl OptimizedProductQuantizer
impl OptimizedProductQuantizer
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 OPQ quantizer
§Arguments
dimension- Vector dimension (must be divisible by num_subquantizers)num_subquantizers- Number of sub-quantizersbits- Bits per code (typically 8)
Sourcepub fn standard(dimension: usize) -> Result<Self>
pub fn standard(dimension: usize) -> Result<Self>
Create standard OPQ with 8 sub-quantizers and 8 bits
Sourcepub fn train(
&mut self,
vectors: &[Vec<f32>],
max_iterations: usize,
rotation_iterations: usize,
) -> Result<()>
pub fn train( &mut self, vectors: &[Vec<f32>], max_iterations: usize, rotation_iterations: usize, ) -> Result<()>
Train OPQ with rotation learning
Uses iterative optimization: alternate between learning rotation and PQ codebooks
§Arguments
vectors- Training vectorsmax_iterations- Max iterations for PQ k-meansrotation_iterations- Iterations for rotation learning (typically 5-10)
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)
Sourcepub fn compute_distance_table(&self, query: &[f32]) -> Result<Vec<Vec<f32>>>
pub fn compute_distance_table(&self, query: &[f32]) -> Result<Vec<Vec<f32>>>
Compute distance table for fast batch queries
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 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
Sourcepub fn inner_pq(&self) -> &ProductQuantizer
pub fn inner_pq(&self) -> &ProductQuantizer
Get the underlying PQ (for testing)
Trait Implementations§
Source§impl Clone for OptimizedProductQuantizer
impl Clone for OptimizedProductQuantizer
Source§fn clone(&self) -> OptimizedProductQuantizer
fn clone(&self) -> OptimizedProductQuantizer
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 OptimizedProductQuantizer
impl Debug for OptimizedProductQuantizer
Source§impl<'de> Deserialize<'de> for OptimizedProductQuantizer
impl<'de> Deserialize<'de> for OptimizedProductQuantizer
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 OptimizedProductQuantizer
impl RefUnwindSafe for OptimizedProductQuantizer
impl Send for OptimizedProductQuantizer
impl Sync for OptimizedProductQuantizer
impl Unpin for OptimizedProductQuantizer
impl UnwindSafe for OptimizedProductQuantizer
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.