pub struct FlatIndex {
pub dim: usize,
pub data: Vec<Vector>,
}Expand description
Flat index implementation for exact vector search
This index stores vectors in a simple array and performs linear search to find the most similar vectors. While slower than approximate methods, it guarantees exact results.
§Examples
use vectorlite::{FlatIndex, Vector, SimilarityMetric, VectorIndex};
let mut index = FlatIndex::new(3, Vec::new());
let vector = Vector { id: 1, values: vec![1.0, 2.0, 3.0] };
index.add(vector)?;
let results = index.search(&[1.1, 2.1, 3.1], 5, SimilarityMetric::Cosine);Fields§
§dim: usizeDimension of vectors stored in this index
data: Vec<Vector>Storage for all vectors
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for FlatIndex
impl<'de> Deserialize<'de> for FlatIndex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl VectorIndex for FlatIndex
impl VectorIndex for FlatIndex
Source§fn search(
&self,
query: &[f64],
k: usize,
similarity_metric: SimilarityMetric,
) -> Vec<SearchResult>
fn search( &self, query: &[f64], k: usize, similarity_metric: SimilarityMetric, ) -> Vec<SearchResult>
Search for the k most similar vectors
Auto Trait Implementations§
impl Freeze for FlatIndex
impl RefUnwindSafe for FlatIndex
impl Send for FlatIndex
impl Sync for FlatIndex
impl Unpin 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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