pub struct PqEncoder { /* private fields */ }Expand description
A product quantizer with pre-trained codebooks.
The codebook codebooks[m][k] is the k-th centroid vector for sub-space
m, with length config.subspace_dim().
Implementations§
Source§impl PqEncoder
impl PqEncoder
Sourcepub fn new_random(config: PqConfig) -> Self
pub fn new_random(config: PqConfig) -> Self
Create a PqEncoder with randomly initialised codebooks using a
deterministic LCG so tests are reproducible.
Sourcepub fn encode(&self, vector: &[f32]) -> Result<Vec<usize>, String>
pub fn encode(&self, vector: &[f32]) -> Result<Vec<usize>, String>
Encode a vector into M centroid indices (one per sub-space).
Returns an error if vector.len() != config.dimension.
Sourcepub fn decode(&self, codes: &[usize]) -> Result<Vec<f32>, String>
pub fn decode(&self, codes: &[usize]) -> Result<Vec<f32>, String>
Decode M centroid indices back to an approximate reconstructed vector.
Returns an error if codes.len() != config.num_subspaces or any code
index is out of bounds.
Sourcepub fn asymmetric_distance(
&self,
query: &[f32],
codes: &[usize],
) -> Result<f32, String>
pub fn asymmetric_distance( &self, query: &[f32], codes: &[usize], ) -> Result<f32, String>
Compute the asymmetric distance between a query vector and encoded codes.
The asymmetric distance is the sum of squared Euclidean distances between each query sub-vector and its assigned centroid.
Returns an error if query.len() != config.dimension or codes are invalid.
Auto Trait Implementations§
impl Freeze for PqEncoder
impl RefUnwindSafe for PqEncoder
impl Send for PqEncoder
impl Sync for PqEncoder
impl Unpin for PqEncoder
impl UnsafeUnpin for PqEncoder
impl UnwindSafe for PqEncoder
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
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>
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>
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.