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) -> Self
pub fn new(config: SemanticCacheConfig) -> Self
Build an in-process cache with no durable backend.
Sourcepub fn with_backend(
config: SemanticCacheConfig,
backend: Arc<dyn MlPersistence>,
) -> Self
pub fn with_backend( config: SemanticCacheConfig, backend: Arc<dyn MlPersistence>, ) -> Self
Build a cache that persists every mutation to backend under
cache:{namespace}. Entries rehydrate on construction.
Sourcepub fn load_from_backend(&self) -> MlPersistenceResult<usize>
pub fn load_from_backend(&self) -> MlPersistenceResult<usize>
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
Auto Trait Implementations§
impl !RefUnwindSafe for SemanticCache
impl !UnwindSafe for SemanticCache
impl Forget for SemanticCache
impl Freeze for SemanticCachewhere
*const ArcInner<Mutex<Inner>> is !null: Freeze,
PhantomData<ArcInner<Mutex<Inner>>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<dyn MlPersistence> is !null: Freeze,
PhantomData<ArcInner<dyn MlPersistence>>: Freeze,
impl Move for SemanticCache
impl Send for SemanticCache
impl Sync for SemanticCache
impl Unpin for SemanticCache
impl UnsafeUnpin for SemanticCachewhere
*const ArcInner<Mutex<Inner>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Inner>>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<dyn MlPersistence> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn MlPersistence>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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