pub struct IVFPQIndex {
pub config: IVFPQConfig,
pub centroids_version: u64,
pub codebook_version: u64,
pub clusters: ClusterStorage<PQVector>,
}Expand description
IVF-PQ index for a single segment
Fields§
§config: IVFPQConfigConfiguration
centroids_version: u64Version of coarse centroids used (for merge compatibility)
codebook_version: u64Version of PQ codebook used (for merge compatibility)
clusters: ClusterStorage<PQVector>Cluster storage with PQ codes
Implementations§
Source§impl IVFPQIndex
impl IVFPQIndex
Sourcepub fn new(
config: IVFPQConfig,
centroids_version: u64,
codebook_version: u64,
) -> Self
pub fn new( config: IVFPQConfig, centroids_version: u64, codebook_version: u64, ) -> Self
Create a new empty IVF-PQ index
Sourcepub fn build(
config: IVFPQConfig,
coarse_centroids: &CoarseCentroids,
codebook: &PQCodebook,
vectors: &[Vec<f32>],
doc_ids: Option<&[u32]>,
) -> Self
pub fn build( config: IVFPQConfig, coarse_centroids: &CoarseCentroids, codebook: &PQCodebook, vectors: &[Vec<f32>], doc_ids: Option<&[u32]>, ) -> Self
Build index from vectors using provided coarse centroids and PQ codebook
Sourcepub fn add_vector(
&mut self,
coarse_centroids: &CoarseCentroids,
codebook: &PQCodebook,
doc_id: u32,
vector: &[f32],
)
pub fn add_vector( &mut self, coarse_centroids: &CoarseCentroids, codebook: &PQCodebook, doc_id: u32, vector: &[f32], )
Add a single vector to the index
Sourcepub fn search(
&self,
coarse_centroids: &CoarseCentroids,
codebook: &PQCodebook,
query: &[f32],
k: usize,
nprobe: Option<usize>,
) -> Vec<(u32, f32)>
pub fn search( &self, coarse_centroids: &CoarseCentroids, codebook: &PQCodebook, query: &[f32], k: usize, nprobe: Option<usize>, ) -> Vec<(u32, f32)>
Search for k nearest neighbors
Sourcepub fn search_mips(
&self,
coarse_centroids: &CoarseCentroids,
codebook: &PQCodebook,
query: &[f32],
k: usize,
nprobe: Option<usize>,
) -> Vec<(u32, f32)>
pub fn search_mips( &self, coarse_centroids: &CoarseCentroids, codebook: &PQCodebook, query: &[f32], k: usize, nprobe: Option<usize>, ) -> Vec<(u32, f32)>
Search using inner product (MIPS - Maximum Inner Product Search)
Sourcepub fn merge_into(
&mut self,
other: &IVFPQIndex,
doc_id_offset: u32,
) -> Result<(), &'static str>
pub fn merge_into( &mut self, other: &IVFPQIndex, doc_id_offset: u32, ) -> Result<(), &'static str>
Merge another index into this one (instance method)
pub fn is_empty(&self) -> bool
Sourcepub fn num_clusters(&self) -> usize
pub fn num_clusters(&self) -> usize
Number of non-empty clusters
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Memory usage estimate
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self>
pub fn from_bytes(data: &[u8]) -> Result<Self>
Deserialize from bytes
Trait Implementations§
Source§impl Clone for IVFPQIndex
impl Clone for IVFPQIndex
Source§fn clone(&self) -> IVFPQIndex
fn clone(&self) -> IVFPQIndex
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 IVFPQIndex
impl Debug for IVFPQIndex
Source§impl<'de> Deserialize<'de> for IVFPQIndex
impl<'de> Deserialize<'de> for IVFPQIndex
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 IVFPQIndex
impl RefUnwindSafe for IVFPQIndex
impl Send for IVFPQIndex
impl Sync for IVFPQIndex
impl Unpin for IVFPQIndex
impl UnwindSafe for IVFPQIndex
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 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.