pub struct ProductQuantizer {
pub m: usize,
pub dsub: usize,
pub dim: usize,
pub centroids: Vec<Vec<Vec<f32>>>,
pub trained: bool,
}Expand description
Product Quantizer with M subspaces, 256 centroids each (1 byte per subspace)
Fields§
§m: usizeNumber of subspaces
dsub: usizeDimensions per subspace
dim: usizeTotal dimensions
centroids: Vec<Vec<Vec<f32>>>Centroids: [m][256][dsub]
trained: boolWhether the PQ has been trained
Implementations§
Source§impl ProductQuantizer
impl ProductQuantizer
Sourcepub fn new(dim: usize, m: usize) -> Result<Self>
pub fn new(dim: usize, m: usize) -> Result<Self>
Create a new PQ with M subspaces for D-dimensional vectors
Sourcepub fn train(&mut self, vectors: &[Vec<f32>], iterations: usize) -> Result<()>
pub fn train(&mut self, vectors: &[Vec<f32>], iterations: usize) -> Result<()>
Train PQ centroids using k-means on training vectors
Sourcepub fn encode(&self, vector: &[f32]) -> Result<Vec<u8>>
pub fn encode(&self, vector: &[f32]) -> Result<Vec<u8>>
Encode a vector into PQ codes (M bytes)
Sourcepub fn build_distance_table(&self, query: &[f32]) -> Result<Vec<f32>>
pub fn build_distance_table(&self, query: &[f32]) -> Result<Vec<f32>>
Build flat asymmetric distance table for a query vector Returns flat table[subspace * 256 + centroid_id] = distance
Sourcepub fn distance_with_table(&self, codes: &[u8], table: &[f32]) -> f32
pub fn distance_with_table(&self, codes: &[u8], table: &[f32]) -> f32
Compute approximate distance using flat precomputed table
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for ProductQuantizer
impl<'__de, __Context> BorrowDecode<'__de, __Context> for ProductQuantizer
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Attempt to decode this type with the given BorrowDecode.
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<__Context> Decode<__Context> for ProductQuantizer
impl<__Context> Decode<__Context> 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 Encode for ProductQuantizer
impl Encode for ProductQuantizer
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> 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