pub struct VectorIndex { /* private fields */ }Expand description
Vector index using simple brute-force search
This implementation uses linear scan which is efficient for small collections (< 10,000 vectors). For larger collections, consider HNSW or IVF indexing.
Implementations§
Source§impl VectorIndex
impl VectorIndex
Sourcepub fn add(&mut self, chunk_id: String, embedding: Vec<f32>) -> Result<()>
pub fn add(&mut self, chunk_id: String, embedding: Vec<f32>) -> Result<()>
Add embedding to index.
The embedding is L2-normalized at insert time so that cosine similarity reduces to a simple dot product during search.
Sourcepub fn search(&self, query: &[f32], k: usize) -> Vec<(String, f32)>
pub fn search(&self, query: &[f32], k: usize) -> Vec<(String, f32)>
Search for similar embeddings
Uses a min-heap to efficiently track the top-k results without sorting the entire result set. Also applies early termination when all top-k results have similarity > 0.95.
Because all stored embeddings are L2-normalized at insert time, cosine similarity is just the dot product (no per-query sqrt needed).
Sourcepub fn cosine_similarity(a: &[f32], b: &[f32]) -> f32
pub fn cosine_similarity(a: &[f32], b: &[f32]) -> f32
Cosine similarity between two arbitrary vectors.
Normalizes both inputs before computing the dot product.
Kept for external callers and tests; the hot search path uses
dot_product on pre-normalized vectors instead.
Sourcepub fn verify_index_integrity(&self) -> Vec<String>
pub fn verify_index_integrity(&self) -> Vec<String>
Verify index integrity, returning a list of issues found.
Checks for:
- Mismatched embedding dimensions
- NaN or Inf values in vectors
- Duplicate chunk IDs
- Empty embedding vectors
Sourcepub fn check_health(&self) -> IndexHealth
pub fn check_health(&self) -> IndexHealth
Check overall health of the index.
Auto Trait Implementations§
impl Freeze for VectorIndex
impl RefUnwindSafe for VectorIndex
impl Send for VectorIndex
impl Sync for VectorIndex
impl Unpin for VectorIndex
impl UnsafeUnpin for VectorIndex
impl UnwindSafe for VectorIndex
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 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>
T in a tonic::Request