pub struct EmbeddingCache { /* private fields */ }Expand description
An embedding cache that avoids re-computing embeddings for unchanged content.
Keys are (id, content_hash) pairs. When the content hash changes, the
old embedding is invalidated and a new one is computed.
Implementations§
Source§impl EmbeddingCache
impl EmbeddingCache
Sourcepub fn get(&mut self, id: &str, content_hash: &str) -> Option<&Vec<f32>>
pub fn get(&mut self, id: &str, content_hash: &str) -> Option<&Vec<f32>>
Look up an embedding by ID and content hash.
Returns Some(vector) if the cache has a valid entry (matching hash).
Returns None if the entry is missing or the hash has changed.
Sourcepub fn insert(&mut self, id: String, content_hash: String, vector: Vec<f32>)
pub fn insert(&mut self, id: String, content_hash: String, vector: Vec<f32>)
Insert or update a cache entry.
Sourcepub fn embed_cached(
&mut self,
items: &[(String, String, String)],
provider: &dyn EmbeddingProvider,
) -> Result<Vec<EmbeddedItem>>
pub fn embed_cached( &mut self, items: &[(String, String, String)], provider: &dyn EmbeddingProvider, ) -> Result<Vec<EmbeddedItem>>
Embed items using the cache, only computing embeddings for cache misses.
items is a list of (id, content_hash, text) tuples. Items with
unchanged content hashes use cached vectors. Changed items are embedded
in batch and cached.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EmbeddingCache
impl RefUnwindSafe for EmbeddingCache
impl Send for EmbeddingCache
impl Sync for EmbeddingCache
impl Unpin for EmbeddingCache
impl UnsafeUnpin for EmbeddingCache
impl UnwindSafe for EmbeddingCache
Blanket Implementations§
impl<T> Allocation for T
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