pub struct ProductQuantizer {
pub config: PQConfig,
pub codebooks: Vec<Vec<Vec<f32>>>,
pub dimension: usize,
pub subvector_dim: usize,
}Expand description
A trained Product Quantizer
Fields§
§config: PQConfigConfiguration
codebooks: Vec<Vec<Vec<f32>>>Codebooks: [num_subquantizers][num_centroids][subvector_dim]
dimension: usizeDimension of full vector
subvector_dim: usizeDimension of each subvector
Implementations§
Source§impl ProductQuantizer
impl ProductQuantizer
Sourcepub fn new(config: PQConfig, dimension: usize) -> Result<Self, String>
pub fn new(config: PQConfig, dimension: usize) -> Result<Self, String>
Create a new untrained quantizer
Sourcepub fn train(&mut self, vectors: &[Vector]) -> Result<(), String>
pub fn train(&mut self, vectors: &[Vector]) -> Result<(), String>
Train the quantizer on a set of vectors
Sourcepub fn is_trained(&self) -> bool
pub fn is_trained(&self) -> bool
Check if the quantizer is trained
Sourcepub fn decode(&self, codes: &[u8]) -> Result<Vec<f32>, String>
pub fn decode(&self, codes: &[u8]) -> Result<Vec<f32>, String>
Decode PQ codes back to approximate vector
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
Source§impl Persistable for ProductQuantizer
impl Persistable for ProductQuantizer
Source§type Snapshot = PQSnapshot
type Snapshot = PQSnapshot
The snapshot type for this index
Source§fn to_snapshot(&self) -> PQSnapshot
fn to_snapshot(&self) -> PQSnapshot
Create a snapshot of the current state
Source§fn from_snapshot(snapshot: PQSnapshot) -> Result<Self, String>
fn from_snapshot(snapshot: PQSnapshot) -> Result<Self, String>
Restore from a snapshot
Auto Trait Implementations§
impl Freeze for ProductQuantizer
impl RefUnwindSafe for ProductQuantizer
impl Send for ProductQuantizer
impl Sync for ProductQuantizer
impl Unpin for ProductQuantizer
impl UnsafeUnpin for ProductQuantizer
impl UnwindSafe for ProductQuantizer
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> 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 more