pub struct IVFIndex {
pub centroids: Vec<f32>,
pub num_clusters: usize,
pub dim: usize,
pub inverted_lists: Vec<Vec<usize>>,
}Expand description
An inverted file index that partitions vectors into clusters.
Fields§
§centroids: Vec<f32>Cluster centroids: [num_clusters][dim] stored flat.
num_clusters: usizeNumber of clusters.
dim: usizeVector dimension.
inverted_lists: Vec<Vec<usize>>Inverted lists: for each cluster, the indices of vectors assigned to it.
Implementations§
Source§impl IVFIndex
impl IVFIndex
Sourcepub fn train(vectors: &[Vec<f32>], dim: usize, num_clusters: usize) -> Self
pub fn train(vectors: &[Vec<f32>], dim: usize, num_clusters: usize) -> Self
Train an IVF index using k-means clustering.
Sourcepub fn search(
&self,
query: &[f32],
vectors: &[Vec<f32>],
norms: &[f32],
tombstones: &[u8],
nprobe: usize,
k: usize,
) -> Vec<(usize, f32)>
pub fn search( &self, query: &[f32], vectors: &[Vec<f32>], norms: &[f32], tombstones: &[u8], nprobe: usize, k: usize, ) -> Vec<(usize, f32)>
Search using IVF: probe the nprobe nearest clusters and return
top-k results by cosine similarity.
Sourcepub fn is_balanced(&self) -> bool
pub fn is_balanced(&self) -> bool
Check if clusters are reasonably balanced (no cluster has more than 3x the average size).
Auto Trait Implementations§
impl Freeze for IVFIndex
impl RefUnwindSafe for IVFIndex
impl Send for IVFIndex
impl Sync for IVFIndex
impl Unpin for IVFIndex
impl UnsafeUnpin for IVFIndex
impl UnwindSafe for IVFIndex
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> 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