pub struct FlatIndex {
pub dimensions: usize,
pub distance: DistanceMetric,
/* private fields */
}Expand description
Brute-force flat index backed by a RwLock<Vec<(id, vector)>>.
Fields§
§dimensions: usizeExpected vector dimensionality.
distance: DistanceMetricDistance metric for similarity comparisons.
Implementations§
Source§impl FlatIndex
impl FlatIndex
Sourcepub fn new(dimensions: usize, distance: DistanceMetric) -> Self
pub fn new(dimensions: usize, distance: DistanceMetric) -> Self
Create a new, empty flat index.
Sourcepub fn insert(&self, id: usize, vector: Vec<f32>) -> VectorResult<()>
pub fn insert(&self, id: usize, vector: Vec<f32>) -> VectorResult<()>
Insert a single vector, validating its dimensionality.
Sourcepub fn insert_batch(&self, items: Vec<(usize, Vec<f32>)>) -> VectorResult<()>
pub fn insert_batch(&self, items: Vec<(usize, Vec<f32>)>) -> VectorResult<()>
Insert multiple vectors.
Sourcepub fn search(
&self,
query: &[f32],
top_k: usize,
) -> VectorResult<Vec<(usize, f32)>>
pub fn search( &self, query: &[f32], top_k: usize, ) -> VectorResult<Vec<(usize, f32)>>
Score all stored vectors in parallel and return the top_k closest.
Sourcepub fn delete(&self, id: usize) -> VectorResult<bool>
pub fn delete(&self, id: usize) -> VectorResult<bool>
Remove a vector by id. Returns true if the id was present.
Sourcepub fn all_vectors(&self) -> VectorResult<Vec<(usize, Vec<f32>)>>
pub fn all_vectors(&self) -> VectorResult<Vec<(usize, Vec<f32>)>>
Return all stored (id, vector) pairs (used for persistence and migration).
Sourcepub fn to_hnsw(&self, config: &VectorConfig) -> VectorResult<HnswIndex>
pub fn to_hnsw(&self, config: &VectorConfig) -> VectorResult<HnswIndex>
Migrate all vectors into a fresh HnswIndex.
Auto Trait Implementations§
impl !Freeze for FlatIndex
impl RefUnwindSafe for FlatIndex
impl Send for FlatIndex
impl Sync for FlatIndex
impl Unpin for FlatIndex
impl UnsafeUnpin for FlatIndex
impl UnwindSafe for FlatIndex
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