pub struct EmbeddingRetriever<P: EmbeddingProvider> { /* private fields */ }Expand description
In-memory vector retriever using cosine similarity search.
Stores document embeddings and retrieves the top-k most similar documents for a query, optionally filtered by a minimum similarity threshold.
Implementations§
Source§impl<P: EmbeddingProvider> EmbeddingRetriever<P>
impl<P: EmbeddingProvider> EmbeddingRetriever<P>
Sourcepub fn new(provider: P) -> Self
pub fn new(provider: P) -> Self
Create a new retriever backed by the given EmbeddingProvider.
Sourcepub fn with_similarity_threshold(self, threshold: f64) -> Self
pub fn with_similarity_threshold(self, threshold: f64) -> Self
Set the minimum cosine similarity required to include a result.
Results with similarity below this threshold are excluded.
§Example
let retriever = EmbeddingRetriever::new(Dummy).with_similarity_threshold(0.7);Trait Implementations§
Source§impl<P: EmbeddingProvider> Retriever for EmbeddingRetriever<P>
impl<P: EmbeddingProvider> Retriever for EmbeddingRetriever<P>
Source§fn retrieve<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Document>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn retrieve<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Document>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Embed query, compute cosine similarity with all stored docs, return top-k.
Auto Trait Implementations§
impl<P> Freeze for EmbeddingRetriever<P>where
P: Freeze,
impl<P> RefUnwindSafe for EmbeddingRetriever<P>where
P: RefUnwindSafe,
impl<P> Send for EmbeddingRetriever<P>
impl<P> Sync for EmbeddingRetriever<P>
impl<P> Unpin for EmbeddingRetriever<P>where
P: Unpin,
impl<P> UnsafeUnpin for EmbeddingRetriever<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for EmbeddingRetriever<P>where
P: 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