pub struct EmbeddingStore { /* private fields */ }Expand description
In-memory store for labelled embedding vectors.
Implementations§
Source§impl EmbeddingStore
impl EmbeddingStore
Sourcepub fn insert(
&mut self,
label: impl Into<String>,
vector: Vec<f64>,
) -> Result<usize, StoreError>
pub fn insert( &mut self, label: impl Into<String>, vector: Vec<f64>, ) -> Result<usize, StoreError>
Insert a new embedding.
All vectors in the store must have the same dimension. The first insertion fixes the dimension for all subsequent insertions.
Returns the assigned id on success.
Sourcepub fn insert_with_meta(
&mut self,
label: impl Into<String>,
vector: Vec<f64>,
meta: HashMap<String, String>,
) -> Result<usize, StoreError>
pub fn insert_with_meta( &mut self, label: impl Into<String>, vector: Vec<f64>, meta: HashMap<String, String>, ) -> Result<usize, StoreError>
Insert a new embedding with accompanying metadata.
Sourcepub fn get_by_label(&self, label: &str) -> Option<&EmbeddingEntry>
pub fn get_by_label(&self, label: &str) -> Option<&EmbeddingEntry>
Look up an entry by its label.
Sourcepub fn get_by_id(&self, id: usize) -> Option<&EmbeddingEntry>
pub fn get_by_id(&self, id: usize) -> Option<&EmbeddingEntry>
Look up an entry by its sequential id.
Sourcepub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
pub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
Compute the cosine similarity between two slices of equal length.
Returns 0.0 when either vector has zero norm.
Sourcepub fn nearest(
&self,
query: &[f64],
k: usize,
) -> Result<Vec<(&EmbeddingEntry, f64)>, StoreError>
pub fn nearest( &self, query: &[f64], k: usize, ) -> Result<Vec<(&EmbeddingEntry, f64)>, StoreError>
Return the k nearest entries to query by cosine similarity, in
descending order of similarity.
Returns StoreError::EmptyStore when the store is empty and
StoreError::DimensionMismatch when query has the wrong length.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EmbeddingStore
impl RefUnwindSafe for EmbeddingStore
impl Send for EmbeddingStore
impl Sync for EmbeddingStore
impl Unpin for EmbeddingStore
impl UnsafeUnpin for EmbeddingStore
impl UnwindSafe for EmbeddingStore
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> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.