pub struct SemanticCache { /* private fields */ }Expand description
A cache that matches queries by embedding similarity rather than exact string match.
Implementations§
Source§impl SemanticCache
impl SemanticCache
Sourcepub fn new(config: SemanticCacheConfig) -> Self
pub fn new(config: SemanticCacheConfig) -> Self
Create a new cache with the supplied configuration.
Sourcepub fn get(&self, query_embedding: &[f32]) -> Option<Value>
pub fn get(&self, query_embedding: &[f32]) -> Option<Value>
Try to find a cached result for query_embedding.
Performs a linear scan over all entries comparing cosine similarity. Returns the result of the best-matching non-expired entry whose similarity is at or above the configured threshold.
Sourcepub fn put(&self, query_embedding: Vec<f32>, query_text: String, results: Value)
pub fn put(&self, query_embedding: Vec<f32>, query_text: String, results: Value)
Store results under query_embedding.
If the cache is at capacity, the oldest entry (by created_at) is
evicted first.
Sourcepub fn invalidate_memory(&self, memory_id: i64)
pub fn invalidate_memory(&self, memory_id: i64)
Remove all entries whose result JSON contains memory_id.
The JSON is checked for any occurrence of the integer value at any position in the document.
Sourcepub fn stats(&self) -> SemanticCacheStats
pub fn stats(&self) -> SemanticCacheStats
Return a snapshot of cache statistics.
Auto Trait Implementations§
impl !Freeze for SemanticCache
impl !RefUnwindSafe for SemanticCache
impl Send for SemanticCache
impl Sync for SemanticCache
impl Unpin for SemanticCache
impl UnsafeUnpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.