pub struct IvfIndex { /* private fields */ }Expand description
IVF Index for approximate nearest neighbor search
Implementations§
Source§impl IvfIndex
impl IvfIndex
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration
Sourcepub fn train(&mut self, vectors: &[Vec<f32>]) -> Result<(), String>
pub fn train(&mut self, vectors: &[Vec<f32>]) -> Result<(), String>
Train the index using k-means clustering
Sourcepub fn add(&self, id: String, vector: Vec<f32>) -> Result<(), String>
pub fn add(&self, id: String, vector: Vec<f32>) -> Result<(), String>
Add a vector to the index (must be trained first)
Sourcepub fn add_batch(
&self,
vectors: Vec<(String, Vec<f32>)>,
) -> Result<usize, String>
pub fn add_batch( &self, vectors: Vec<(String, Vec<f32>)>, ) -> Result<usize, String>
Add multiple vectors to the index
Sourcepub fn search(
&self,
query: &[f32],
k: usize,
) -> Result<Vec<SearchResult>, String>
pub fn search( &self, query: &[f32], k: usize, ) -> Result<Vec<SearchResult>, String>
Search for the k nearest neighbors
Sourcepub fn is_trained(&self) -> bool
pub fn is_trained(&self) -> bool
Check if index is trained
Sourcepub fn n_clusters(&self) -> usize
pub fn n_clusters(&self) -> usize
Get number of clusters
Sourcepub fn from_snapshot(snapshot: IvfFullSnapshot) -> Result<Self, String>
pub fn from_snapshot(snapshot: IvfFullSnapshot) -> Result<Self, String>
Restore IVF index from a full snapshot
Trait Implementations§
Source§impl Persistable for IvfIndex
impl Persistable for IvfIndex
Source§type Snapshot = IvfFullSnapshot
type Snapshot = IvfFullSnapshot
The snapshot type for this index
Source§fn to_snapshot(&self) -> IvfFullSnapshot
fn to_snapshot(&self) -> IvfFullSnapshot
Create a snapshot of the current state
Source§fn from_snapshot(snapshot: IvfFullSnapshot) -> Result<Self, String>
fn from_snapshot(snapshot: IvfFullSnapshot) -> Result<Self, String>
Restore from a snapshot
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> 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 more