pub struct CachedEmbeddingProvider { /* private fields */ }Expand description
Wraps any EmbeddingProvider with a thread-safe in-memory LRU-ish cache.
Embeddings are cached by FNV-1a hash of the input text. When the cache
exceeds max_cache_size, the oldest entry (by insertion order) is evicted.
Implementations§
Source§impl CachedEmbeddingProvider
impl CachedEmbeddingProvider
Sourcepub fn new(inner: Arc<dyn EmbeddingProvider>, max_cache_size: usize) -> Self
pub fn new(inner: Arc<dyn EmbeddingProvider>, max_cache_size: usize) -> Self
Wrap an existing provider with caching.
Sourcepub async fn cache_stats(&self) -> CacheStats
pub async fn cache_stats(&self) -> CacheStats
Returns current cache statistics.
Trait Implementations§
Source§impl EmbeddingProvider for CachedEmbeddingProvider
impl EmbeddingProvider for CachedEmbeddingProvider
Source§fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = ArgentorResult<Vec<f32>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = ArgentorResult<Vec<f32>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Compute embedding vector for a single text.
Source§fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = ArgentorResult<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = ArgentorResult<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Compute embeddings for a batch of texts.
Auto Trait Implementations§
impl Freeze for CachedEmbeddingProvider
impl !RefUnwindSafe for CachedEmbeddingProvider
impl Send for CachedEmbeddingProvider
impl Sync for CachedEmbeddingProvider
impl Unpin for CachedEmbeddingProvider
impl UnsafeUnpin for CachedEmbeddingProvider
impl !UnwindSafe for CachedEmbeddingProvider
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