pub struct Quantizer { /* private fields */ }Expand description
Product Quantizer that compresses high-dimensional vectors.
Implementations§
Source§impl Quantizer
impl Quantizer
Sourcepub fn new(config: QuantizerConfig) -> Self
pub fn new(config: QuantizerConfig) -> Self
Create a new, un-trained quantizer with the given configuration.
Sourcepub fn train(&mut self, data: &[Vec<f32>]) -> Result<(), QuantizerError>
pub fn train(&mut self, data: &[Vec<f32>]) -> Result<(), QuantizerError>
Train the quantizer using k-means on the provided data vectors.
All vectors must have the same dimensionality, which must be divisible by n_subspaces.
Sourcepub fn encode(&self, vector: &[f32]) -> Result<QuantizedVector, QuantizerError>
pub fn encode(&self, vector: &[f32]) -> Result<QuantizedVector, QuantizerError>
Encode a single vector into a QuantizedVector.
Sourcepub fn decode(
&self,
qv: &QuantizedVector,
) -> Result<ReconstructedVector, QuantizerError>
pub fn decode( &self, qv: &QuantizedVector, ) -> Result<ReconstructedVector, QuantizerError>
Decode a QuantizedVector back to an approximate vector.
Sourcepub fn encode_batch(
&self,
vectors: &[Vec<f32>],
) -> Result<Vec<QuantizedVector>, QuantizerError>
pub fn encode_batch( &self, vectors: &[Vec<f32>], ) -> Result<Vec<QuantizedVector>, QuantizerError>
Encode a batch of vectors.
Sourcepub fn is_trained(&self) -> bool
pub fn is_trained(&self) -> bool
Return true if the quantizer has been trained.
Sourcepub fn compression_ratio(&self, original_dim: usize) -> f32
pub fn compression_ratio(&self, original_dim: usize) -> f32
Compute the compression ratio: bytes of original / bytes of compressed.
Original: original_dim * 4 bytes (f32).
Compressed: n_subspaces bytes (one u8 code per sub-space).
Sourcepub fn codebook_count(&self) -> usize
pub fn codebook_count(&self) -> usize
Return the number of codebooks (equals n_subspaces after training).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Quantizer
impl RefUnwindSafe for Quantizer
impl Send for Quantizer
impl Sync for Quantizer
impl Unpin for Quantizer
impl UnsafeUnpin for Quantizer
impl UnwindSafe for Quantizer
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
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<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
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.