pub struct IvfFlatIndex { /* private fields */ }Expand description
An IVF-Flat index. All methods take &self; internal mutable state is guarded
by a single RwLock, so the index is Send + Sync and safe to share behind
an Arc like the usearch backend.
Implementations§
Source§impl IvfFlatIndex
impl IvfFlatIndex
pub fn new(dims: usize, metric: Metric, nlist: usize, nprobe: usize) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn is_trained(&self) -> bool
pub const fn metric(&self) -> Metric
pub const fn nlist(&self) -> usize
pub const fn nprobe(&self) -> usize
Sourcepub fn centroid_count(&self) -> usize
pub fn centroid_count(&self) -> usize
The number of trained centroids (0 until IvfFlatIndex::train runs).
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Approximate resident bytes: stored vectors + norms + centroids + bookkeeping.
Sourcepub fn upsert(&self, id: u64, v: &[f32]) -> Result<bool, String>
pub fn upsert(&self, id: u64, v: &[f32]) -> Result<bool, String>
Insert or replace the vector for id. Returns true if it replaced an
existing entry.
Sourcepub fn search(
&self,
query: &[f32],
top_k: usize,
nprobe_override: Option<usize>,
) -> Result<Vec<(u64, f32)>, String>
pub fn search( &self, query: &[f32], top_k: usize, nprobe_override: Option<usize>, ) -> Result<Vec<(u64, f32)>, String>
Return the top_k nearest ids with their distances (ascending). Uses
nprobe_override cells when given, else the configured default; falls back
to an exact scan when untrained.
Sourcepub fn train(&self) -> Result<(), String>
pub fn train(&self) -> Result<(), String>
(Re)train centroids over the currently stored vectors via k-means, then
rebuild the inverted lists. Cheap no-op when empty. The centroid count is
min(nlist, n).
Sourcepub fn bulk_load(
&self,
items: impl IntoIterator<Item = (u64, Vec<f32>)>,
) -> Result<(), String>
pub fn bulk_load( &self, items: impl IntoIterator<Item = (u64, Vec<f32>)>, ) -> Result<(), String>
Replace the entire contents in one shot (used for the initial bulk load).
Does not train; call IvfFlatIndex::train afterwards.
Auto Trait Implementations§
impl !Freeze for IvfFlatIndex
impl !RefUnwindSafe for IvfFlatIndex
impl Send for IvfFlatIndex
impl Sync for IvfFlatIndex
impl Unpin for IvfFlatIndex
impl UnsafeUnpin for IvfFlatIndex
impl UnwindSafe for IvfFlatIndex
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more