pub struct PlanCache { /* private fields */ }Expand description
Plan template cache backed by SQLite with in-process cosine similarity search.
Stores embeddings as BLOB columns and computes cosine similarity in-process
(same pattern as ResponseCache). Graceful degradation: all failures are
logged as WARN and never block the planning critical path.
Implementations§
Source§impl PlanCache
impl PlanCache
Sourcepub async fn new(
pool: DbPool,
config: PlanCacheConfig,
current_embedding_model: &str,
) -> Result<Self, PlanCacheError>
pub async fn new( pool: DbPool, config: PlanCacheConfig, current_embedding_model: &str, ) -> Result<Self, PlanCacheError>
Create a new PlanCache and invalidate stale embeddings for the given model.
§Errors
Returns PlanCacheError if the stale embedding invalidation query fails.
Sourcepub async fn find_similar(
&self,
goal_embedding: &[f32],
embedding_model: &str,
) -> Result<Option<(PlanTemplate, f32)>, PlanCacheError>
pub async fn find_similar( &self, goal_embedding: &[f32], embedding_model: &str, ) -> Result<Option<(PlanTemplate, f32)>, PlanCacheError>
Find the most similar cached plan template for the given goal embedding.
Fetches all rows with matching embedding_model, computes cosine similarity
in-process, and returns the best match if it meets similarity_threshold.
Also updates last_accessed_at on a hit.
§Errors
Returns PlanCacheError::Database on query failure or
PlanCacheError::Serialization on template JSON deserialization failure.
Sourcepub async fn cache_plan(
&self,
graph: &TaskGraph,
goal_embedding: &[f32],
embedding_model: &str,
) -> Result<(), PlanCacheError>
pub async fn cache_plan( &self, graph: &TaskGraph, goal_embedding: &[f32], embedding_model: &str, ) -> Result<(), PlanCacheError>
Store a completed plan as a reusable template.
Extracts a PlanTemplate from the TaskGraph, serializes it to JSON,
and upserts into SQLite using INSERT OR REPLACE ON CONFLICT(goal_hash).
Deduplication is enforced by the UNIQUE constraint on goal_hash.
§Errors
Returns PlanCacheError on extraction, serialization, or database failure.
Sourcepub async fn evict(&self) -> Result<u32, PlanCacheError>
pub async fn evict(&self) -> Result<u32, PlanCacheError>
Run TTL + size-cap LRU eviction.
Phase 1: Delete rows where last_accessed_at < now - ttl_days * 86400.
Phase 2: If count exceeds max_templates, delete the least-recently-accessed rows.
Returns the total number of rows deleted.
§Errors
Returns PlanCacheError::Database on query failure.
Auto Trait Implementations§
impl Freeze for PlanCache
impl !RefUnwindSafe for PlanCache
impl Send for PlanCache
impl Sync for PlanCache
impl Unpin for PlanCache
impl UnsafeUnpin for PlanCache
impl !UnwindSafe for PlanCache
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 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>
T in a tonic::Request