pub struct FlatIvfIndex {
pub dim: usize,
pub num_cells: usize,
pub cells: Vec<IvfCell>,
pub centroids: Vec<Centroid>,
}Expand description
Flat IVF index.
Fields§
§dim: usize§num_cells: usize§cells: Vec<IvfCell>§centroids: Vec<Centroid>Implementations§
Source§impl FlatIvfIndex
impl FlatIvfIndex
Sourcepub fn new(dim: usize, num_cells: usize) -> Self
pub fn new(dim: usize, num_cells: usize) -> Self
Create an untrained index with num_cells cells and vectors of dimension dim.
Sourcepub fn train(&mut self, vectors: &[Vec<f32>])
pub fn train(&mut self, vectors: &[Vec<f32>])
Train the index using Lloyd’s k-means (up to 20 iterations) on vectors.
Centroids are initialised by selecting evenly-spaced samples from the input.
Sourcepub fn insert(&mut self, id: u64, vector: Vec<f32>)
pub fn insert(&mut self, id: u64, vector: Vec<f32>)
Insert a vector with the given id into the nearest cell.
Sourcepub fn search(
&self,
query: &[f32],
k: usize,
n_probe: usize,
) -> Vec<SearchResult>
pub fn search( &self, query: &[f32], k: usize, n_probe: usize, ) -> Vec<SearchResult>
Search for the k nearest neighbours of query, probing n_probe cells.
Sourcepub fn remove(&mut self, id: u64) -> bool
pub fn remove(&mut self, id: u64) -> bool
Remove the vector with id from the index. Returns true if found.
Sourcepub fn nearest_centroid(&self, vec: &[f32]) -> usize
pub fn nearest_centroid(&self, vec: &[f32]) -> usize
Return the index of the nearest cell for vec.
Sourcepub fn l2_distance(a: &[f32], b: &[f32]) -> f32
pub fn l2_distance(a: &[f32], b: &[f32]) -> f32
Compute the squared L2 distance between two equal-length slices.
Auto Trait Implementations§
impl Freeze for FlatIvfIndex
impl RefUnwindSafe for FlatIvfIndex
impl Send for FlatIvfIndex
impl Sync for FlatIvfIndex
impl Unpin for FlatIvfIndex
impl UnsafeUnpin for FlatIvfIndex
impl UnwindSafe for FlatIvfIndex
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> 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 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>
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.