pub enum IndexSelector {
Flat(FlatIndex),
Hnsw(Box<HnswIndex>),
}Variants§
Flat(FlatIndex)
Brute-force index for small collections.
Hnsw(Box<HnswIndex>)
Approximate NN index for larger collections.
Implementations§
Source§impl IndexSelector
impl IndexSelector
Sourcepub fn new(
dimensions: usize,
distance: DistanceMetric,
_config: &VectorConfig,
) -> Self
pub fn new( dimensions: usize, distance: DistanceMetric, _config: &VectorConfig, ) -> Self
Create a new selector (always starts as Flat).
Sourcepub fn insert(
&mut self,
id: usize,
vector: Vec<f32>,
config: &VectorConfig,
) -> VectorResult<()>
pub fn insert( &mut self, id: usize, vector: Vec<f32>, config: &VectorConfig, ) -> VectorResult<()>
Insert a single vector, migrating to HNSW if the threshold is crossed.
Sourcepub fn insert_batch(
&mut self,
items: Vec<(usize, Vec<f32>)>,
config: &VectorConfig,
) -> VectorResult<()>
pub fn insert_batch( &mut self, items: Vec<(usize, Vec<f32>)>, config: &VectorConfig, ) -> VectorResult<()>
Insert a batch of vectors, migrating to HNSW if the threshold is crossed.
Sourcepub fn search(
&self,
query: &[f32],
top_k: usize,
ef_search: usize,
) -> VectorResult<Vec<(usize, f32)>>
pub fn search( &self, query: &[f32], top_k: usize, ef_search: usize, ) -> VectorResult<Vec<(usize, f32)>>
Search for top_k nearest neighbours of query.
Sourcepub fn delete(&mut self, id: usize) -> VectorResult<bool>
pub fn delete(&mut self, id: usize) -> VectorResult<bool>
Delete a vector by id. Returns true if the id was present.
Sourcepub fn migrate_to_hnsw(&mut self, config: &VectorConfig) -> VectorResult<()>
pub fn migrate_to_hnsw(&mut self, config: &VectorConfig) -> VectorResult<()>
Migrate from FlatIndex to HnswIndex, replacing self.
Sourcepub fn save(
&self,
dir: &Path,
workspace_id: &str,
collection: &str,
) -> VectorResult<()>
pub fn save( &self, dir: &Path, workspace_id: &str, collection: &str, ) -> VectorResult<()>
Persist the index under <dir>/<collection>/.
Sourcepub fn load(
dir: &Path,
workspace_id: &str,
collection: &str,
config: &VectorConfig,
distance: DistanceMetric,
dimensions: usize,
) -> VectorResult<Self>
pub fn load( dir: &Path, workspace_id: &str, collection: &str, config: &VectorConfig, distance: DistanceMetric, dimensions: usize, ) -> VectorResult<Self>
Reload a previously saved index from <dir>/<collection>/.
Auto Trait Implementations§
impl !Freeze for IndexSelector
impl !RefUnwindSafe for IndexSelector
impl Send for IndexSelector
impl Sync for IndexSelector
impl Unpin for IndexSelector
impl UnsafeUnpin for IndexSelector
impl !UnwindSafe for IndexSelector
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request