pub struct SemanticQueryCache { /* private fields */ }Expand description
Semantic query cache
Implementations§
Source§impl SemanticQueryCache
impl SemanticQueryCache
Sourcepub fn with_capacity(threshold: f32, max_entries: usize) -> Self
pub fn with_capacity(threshold: f32, max_entries: usize) -> Self
Create a new semantic query cache with specified capacity
Sourcepub fn with_config(
threshold: f32,
max_entries: usize,
index_config: SemanticIndexConfig,
) -> Self
pub fn with_config( threshold: f32, max_entries: usize, index_config: SemanticIndexConfig, ) -> Self
Create with custom index config
Sourcepub fn lookup(&self, embedding: &[f32]) -> Option<SimilarityResult>
pub fn lookup(&self, embedding: &[f32]) -> Option<SimilarityResult>
Lookup by semantic similarity
Sourcepub fn lookup_with_threshold(
&self,
embedding: &[f32],
threshold: f32,
) -> Option<SimilarityResult>
pub fn lookup_with_threshold( &self, embedding: &[f32], threshold: f32, ) -> Option<SimilarityResult>
Lookup with custom threshold
Sourcepub fn find_similar(&self, embedding: &[f32], k: usize) -> Vec<SimilarityResult>
pub fn find_similar(&self, embedding: &[f32], k: usize) -> Vec<SimilarityResult>
Find k most similar queries
Sourcepub fn lookup_with_branch(
&self,
embedding: &[f32],
branch: &BranchContext,
) -> Option<SimilarityResult>
pub fn lookup_with_branch( &self, embedding: &[f32], branch: &BranchContext, ) -> Option<SimilarityResult>
Lookup with branch context filtering
Returns cached entry only if it’s compatible with the given branch context. This enables branch-aware caching for time-travel queries.
Sourcepub fn lookup_with_session(
&self,
embedding: &[f32],
session: &String,
) -> Option<SimilarityResult>
pub fn lookup_with_session( &self, embedding: &[f32], session: &String, ) -> Option<SimilarityResult>
Lookup with session affinity for agent conversations
Prioritizes entries from the same session for better conversation context.
Sourcepub fn lookup_with_context(
&self,
embedding: &[f32],
branch: Option<&BranchContext>,
session: Option<&String>,
workload: AIWorkloadContext,
) -> Option<SimilarityResult>
pub fn lookup_with_context( &self, embedding: &[f32], branch: Option<&BranchContext>, session: Option<&String>, workload: AIWorkloadContext, ) -> Option<SimilarityResult>
Lookup with full AI context (branch + session + workload)
Most comprehensive lookup that considers:
- Branch context for time-travel
- Session affinity for agent conversations
- Workload type for TTL and priority
Sourcepub fn find_similar_in_branch(
&self,
embedding: &[f32],
branch: &BranchContext,
k: usize,
) -> Vec<SimilarityResult>
pub fn find_similar_in_branch( &self, embedding: &[f32], branch: &BranchContext, k: usize, ) -> Vec<SimilarityResult>
Find similar entries within a branch
Sourcepub fn invalidate_by_table(&self, table: &str) -> usize
pub fn invalidate_by_table(&self, table: &str) -> usize
Invalidate entries by table name
Used when WAL invalidation detects changes to a table.
Sourcepub fn invalidate_branch(&self, branch: &BranchId) -> usize
pub fn invalidate_branch(&self, branch: &BranchId) -> usize
Invalidate entries by branch
Sourcepub fn insert(
&self,
query: impl Into<String>,
embedding: Embedding,
result: Value,
) -> VectorId
pub fn insert( &self, query: impl Into<String>, embedding: Embedding, result: Value, ) -> VectorId
Insert a new entry
Sourcepub fn insert_with_ttl(
&self,
query: impl Into<String>,
embedding: Embedding,
result: Value,
ttl: Duration,
) -> VectorId
pub fn insert_with_ttl( &self, query: impl Into<String>, embedding: Embedding, result: Value, ttl: Duration, ) -> VectorId
Insert with TTL
Sourcepub fn insert_with_context(
&self,
query: impl Into<String>,
embedding: Embedding,
result: Value,
branch: Option<BranchContext>,
session: Option<String>,
workload: AIWorkloadContext,
tables: Vec<String>,
) -> VectorId
pub fn insert_with_context( &self, query: impl Into<String>, embedding: Embedding, result: Value, branch: Option<BranchContext>, session: Option<String>, workload: AIWorkloadContext, tables: Vec<String>, ) -> VectorId
Insert with full AI context (branch, session, workload, tables)
This is the recommended insertion method for AI/Agent workloads as it enables branch-aware caching, session affinity, and workload-specific TTL management.
Sourcepub fn insert_rag_retrieval(
&self,
query: impl Into<String>,
embedding: Embedding,
result: Value,
tables: Vec<String>,
) -> VectorId
pub fn insert_rag_retrieval( &self, query: impl Into<String>, embedding: Embedding, result: Value, tables: Vec<String>, ) -> VectorId
Insert for RAG retrieval workload
Optimized TTL for fast-refresh retrieval phase.
Sourcepub fn insert_agent_response(
&self,
query: impl Into<String>,
embedding: Embedding,
result: Value,
session: String,
branch: Option<BranchContext>,
) -> VectorId
pub fn insert_agent_response( &self, query: impl Into<String>, embedding: Embedding, result: Value, session: String, branch: Option<BranchContext>, ) -> VectorId
Insert for agent conversation
Session-aware with longer TTL for conversation context.
Sourcepub fn insert_tool_result(
&self,
query: impl Into<String>,
embedding: Embedding,
result: Value,
) -> VectorId
pub fn insert_tool_result( &self, query: impl Into<String>, embedding: Embedding, result: Value, ) -> VectorId
Insert deterministic tool result
Long TTL for deterministic tool calls (e.g., math, date formatting).
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Remove expired entries
Sourcepub fn stats(&self) -> SemanticCacheStatsSnapshot
pub fn stats(&self) -> SemanticCacheStatsSnapshot
Get statistics
Auto Trait Implementations§
impl !Freeze for SemanticQueryCache
impl !RefUnwindSafe for SemanticQueryCache
impl Send for SemanticQueryCache
impl Sync for SemanticQueryCache
impl Unpin for SemanticQueryCache
impl UnsafeUnpin for SemanticQueryCache
impl UnwindSafe for SemanticQueryCache
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
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>
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>
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 more