pub struct ReasoningMemory { /* private fields */ }Expand description
SQLite-backed store for distilled reasoning strategies.
Attach to crate::semantic::SemanticMemory via with_reasoning.
All write operations are best-effort: SQLite errors are propagated as
MemoryError, Qdrant failures are logged and silently ignored.
Implementations§
Source§impl ReasoningMemory
impl ReasoningMemory
Sourcepub fn new(pool: DbPool, vector_store: Option<Arc<dyn VectorStore>>) -> Self
pub fn new(pool: DbPool, vector_store: Option<Arc<dyn VectorStore>>) -> Self
Create a new ReasoningMemory backed by the given SQLite pool.
Pass vector_store = Some(arc) to enable embedding-similarity retrieval via Qdrant.
When None, Self::retrieve_by_embedding always returns an empty vec.
§Examples
use zeph_memory::reasoning::ReasoningMemory;
async fn demo(pool: zeph_db::DbPool) {
let memory = ReasoningMemory::new(pool, None);
}Sourcepub async fn insert(
&self,
strategy: &ReasoningStrategy,
embedding: Vec<f32>,
) -> Result<(), MemoryError>
pub async fn insert( &self, strategy: &ReasoningStrategy, embedding: Vec<f32>, ) -> Result<(), MemoryError>
Insert a new strategy into SQLite.
When a vector_store is configured, the strategy is also upserted into
the Qdrant reasoning_strategies collection using the provided embedding.
Qdrant failures are logged at warn level and do not fail the insert.
§Errors
Returns an error if the SQLite insert fails.
Sourcepub async fn retrieve_by_embedding(
&self,
embedding: &[f32],
top_k: u64,
) -> Result<Vec<ReasoningStrategy>, MemoryError>
pub async fn retrieve_by_embedding( &self, embedding: &[f32], top_k: u64, ) -> Result<Vec<ReasoningStrategy>, MemoryError>
Retrieve up to top_k strategies by embedding similarity.
This method is pure — it does not update use_count or last_used_at.
Call Self::mark_used with the ids of strategies actually injected into the
prompt (after budget truncation) to maintain accurate retrieval bookkeeping.
Returns an empty vec when no vector store is configured.
§Errors
Returns an error if the Qdrant search or SQLite fetch fails.
Sourcepub async fn mark_used(&self, ids: &[String]) -> Result<(), MemoryError>
pub async fn mark_used(&self, ids: &[String]) -> Result<(), MemoryError>
Increment use_count and update last_used_at for each id in the list.
Safe to call with an empty slice — no SQL is issued.
The list is chunked into batches of [MAX_IDS_PER_QUERY] to respect SQLite’s
variable limit.
§Errors
Returns an error if the database update fails.
Sourcepub async fn evict_lru(&self, store_limit: usize) -> Result<usize, MemoryError>
pub async fn evict_lru(&self, store_limit: usize) -> Result<usize, MemoryError>
Evict strategies when the table exceeds store_limit.
Normal path: delete rows with use_count <= HOT_STRATEGY_USE_COUNT, oldest
first, until the table returns to store_limit.
Saturation path: when the normal path deletes nothing AND the table exceeds
2 × store_limit, bypass hot-row protection and delete oldest rows regardless of
use_count. Emits a warn! with the eviction count so operators can tune
store_limit upward or lower the hot threshold.
Returns the number of rows deleted.
§Errors
Returns an error if any database operation fails.
Auto Trait Implementations§
impl Freeze for ReasoningMemory
impl !RefUnwindSafe for ReasoningMemory
impl Send for ReasoningMemory
impl Sync for ReasoningMemory
impl Unpin for ReasoningMemory
impl UnsafeUnpin for ReasoningMemory
impl !UnwindSafe for ReasoningMemory
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