pub struct EmbeddingIndex<T: Clone> { /* private fields */ }Expand description
Combined NSW graph index with per-entry metadata storage.
T is any cloneable metadata type — e.g. a String payload, a struct, or
a raw identifier.
use oxibonsai_runtime::embedding_index::EmbeddingIndex;
let mut idx: EmbeddingIndex<String> = EmbeddingIndex::new(3);
idx.insert(vec![1.0, 0.0, 0.0], "vec-a".to_string());
idx.insert(vec![0.0, 1.0, 0.0], "vec-b".to_string());
let results = idx.search(&[1.0, 0.0, 0.0], 1);
assert_eq!(results[0].1, &"vec-a".to_string());Implementations§
Source§impl<T: Clone> EmbeddingIndex<T>
impl<T: Clone> EmbeddingIndex<T>
Sourcepub fn new(dim: usize) -> Self
pub fn new(dim: usize) -> Self
Create a new index for dim-dimensional vectors with default NSW config.
Sourcepub fn new_with_config(dim: usize, config: NswConfig) -> Self
pub fn new_with_config(dim: usize, config: NswConfig) -> Self
Create a new index with a custom NswConfig.
Sourcepub fn insert(&mut self, vector: Vec<f32>, meta: T) -> usize
pub fn insert(&mut self, vector: Vec<f32>, meta: T) -> usize
Insert a vector with associated metadata.
Returns the stable numeric ID assigned to this entry.
Auto Trait Implementations§
impl<T> Freeze for EmbeddingIndex<T>
impl<T> RefUnwindSafe for EmbeddingIndex<T>where
T: RefUnwindSafe,
impl<T> Send for EmbeddingIndex<T>where
T: Send,
impl<T> Sync for EmbeddingIndex<T>where
T: Sync,
impl<T> Unpin for EmbeddingIndex<T>where
T: Unpin,
impl<T> UnsafeUnpin for EmbeddingIndex<T>
impl<T> UnwindSafe for EmbeddingIndex<T>where
T: UnwindSafe,
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