pub struct SemanticCache { /* private fields */ }Expand description
The cache itself. Cloning shares state via the inner Arc.
Implementations§
Source§impl SemanticCache
impl SemanticCache
Sourcepub fn new(config: SemanticCacheConfig) -> SemanticCache
pub fn new(config: SemanticCacheConfig) -> SemanticCache
Build an in-process cache with no durable backend.
Sourcepub fn with_backend(
config: SemanticCacheConfig,
backend: Arc<dyn MlPersistence>,
) -> SemanticCache
pub fn with_backend( config: SemanticCacheConfig, backend: Arc<dyn MlPersistence>, ) -> SemanticCache
Build a cache that persists every mutation to backend under
cache:{namespace}. Entries rehydrate on construction.
Sourcepub fn load_from_backend(&self) -> Result<usize, MlPersistenceError>
pub fn load_from_backend(&self) -> Result<usize, MlPersistenceError>
Re-read persisted entries into memory. Malformed rows are skipped rather than crashing startup.
Sourcepub fn lookup(&self, embedding: &[f32]) -> Option<String>
pub fn lookup(&self, embedding: &[f32]) -> Option<String>
Look up by embedding. Returns the cached response on hit;
updates last_hit_ms and hit counter as a side-effect.
Sourcepub fn insert(
&self,
prompt: impl Into<String>,
response: impl Into<String>,
embedding: Vec<f32>,
ttl_ms_override: Option<u64>,
)
pub fn insert( &self, prompt: impl Into<String>, response: impl Into<String>, embedding: Vec<f32>, ttl_ms_override: Option<u64>, )
Insert (prompt, response) keyed by embedding.
If ttl_ms_override is None the config default applies.
Sourcepub fn evict_expired(&self) -> usize
pub fn evict_expired(&self) -> usize
Manually force a sweep. Returns number of entries dropped.
Sourcepub fn stats(&self) -> SemanticCacheStats
pub fn stats(&self) -> SemanticCacheStats
Snapshot of counters.
pub fn config(&self) -> &SemanticCacheConfig
Trait Implementations§
Source§impl Clone for SemanticCache
impl Clone for SemanticCache
Source§fn clone(&self) -> SemanticCache
fn clone(&self) -> SemanticCache
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request