pub struct SemanticCache { /* private fields */ }Expand description
Semantic cache using embeddings for similarity matching
Implementations§
Source§impl SemanticCache
impl SemanticCache
Sourcepub fn new(
embedding_provider: Box<dyn EmbeddingProvider>,
threshold: SimilarityThreshold,
max_size: usize,
) -> Self
pub fn new( embedding_provider: Box<dyn EmbeddingProvider>, threshold: SimilarityThreshold, max_size: usize, ) -> Self
Create a new semantic cache
§Arguments
embedding_provider- Provider for generating embeddingsthreshold- Minimum similarity score for cache hit (0.0 to 1.0)max_size- Maximum number of entries to cache
Sourcepub async fn stats(&self) -> SemanticCacheStats
pub async fn stats(&self) -> SemanticCacheStats
Get cache statistics
Sourcepub async fn get(&self, prompt: &str) -> Option<LlmResponse>
pub async fn get(&self, prompt: &str) -> Option<LlmResponse>
Try to get a cached response for a prompt
Sourcepub async fn put(&self, prompt: String, response: LlmResponse)
pub async fn put(&self, prompt: String, response: LlmResponse)
Store a response in the cache
Auto Trait Implementations§
impl Freeze for SemanticCache
impl !RefUnwindSafe for SemanticCache
impl Send for SemanticCache
impl Sync for SemanticCache
impl Unpin for SemanticCache
impl !UnwindSafe for SemanticCache
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