pub trait SemanticCache: Cache {
// Required methods
fn find_similar_by_embedding<'life0, 'life1, 'async_trait>(
&'life0 self,
query_embedding: &'life1 [f32],
threshold: f32,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheEntry, f32)>, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn store_with_embedding<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
query: &'life1 str,
context: &'life2 str,
response: &'life3 str,
function_calls: Vec<String>,
embedding: Vec<f32>,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
}Expand description
Trait for semantic cache with similarity matching
Unlike regular caching, semantic caching finds similar queries based on embedding vectors rather than exact string matches.
Required Methods§
Sourcefn find_similar_by_embedding<'life0, 'life1, 'async_trait>(
&'life0 self,
query_embedding: &'life1 [f32],
threshold: f32,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheEntry, f32)>, CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn find_similar_by_embedding<'life0, 'life1, 'async_trait>(
&'life0 self,
query_embedding: &'life1 [f32],
threshold: f32,
) -> Pin<Box<dyn Future<Output = Result<Option<(CacheEntry, f32)>, CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Find similar entries based on embedding similarity
Takes a pre-computed embedding vector and finds cached entries with embeddings above the similarity threshold.
Returns the best matching entry and its similarity score (0.0 to 1.0).
Sourcefn store_with_embedding<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
query: &'life1 str,
context: &'life2 str,
response: &'life3 str,
function_calls: Vec<String>,
embedding: Vec<f32>,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn store_with_embedding<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
query: &'life1 str,
context: &'life2 str,
response: &'life3 str,
function_calls: Vec<String>,
embedding: Vec<f32>,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Store with embedding for semantic matching
Stores the response along with its embedding vector for future similarity searches.