pub struct MemoryStore { /* private fields */ }Expand description
SQLite-backed store for semantic and procedural memory.
Provides ADD-only writes, FTS5-based retrieval with multi-signal scoring, and evidence provenance tracking.
Implementations§
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, MemoryStoreError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, MemoryStoreError>
Open or create a memory store at the given file path.
Creates parent directories if they do not exist. Runs schema migration automatically.
Sourcepub fn open_memory() -> Result<Self, MemoryStoreError>
pub fn open_memory() -> Result<Self, MemoryStoreError>
Open an in-memory store for testing.
Sourcepub fn insert(&mut self, item: MemoryItem) -> Result<bool, MemoryStoreError>
pub fn insert(&mut self, item: MemoryItem) -> Result<bool, MemoryStoreError>
Insert a memory item.
ADD-only: exact duplicates (same key + content hash) are silently ignored.
Conflicting entries with the same key but different content are preserved
as separate rows (ADD-only semantics per ADR-016).
Returns true if the item was inserted, false if it was an exact duplicate.
Sourcepub fn insert_evidence(
&self,
link: EvidenceLink,
) -> Result<(), MemoryStoreError>
pub fn insert_evidence( &self, link: EvidenceLink, ) -> Result<(), MemoryStoreError>
Insert an evidence link for a memory item.
Sourcepub fn retrieve(
&self,
query: &str,
limit: usize,
) -> Result<Vec<RetrievalResult>, MemoryStoreError>
pub fn retrieve( &self, query: &str, limit: usize, ) -> Result<Vec<RetrievalResult>, MemoryStoreError>
Retrieve memory items matching the query, scored by FTS5 relevance, recency, and evidence.
§Scoring Formula
fts_score = |bm25| / (1 + |bm25|)— normalized FTS5 relevance (higher = more relevant)recency = exp(-days_since_last_reinforced / 30.0)— exponential decay over 30 daysevidence_score = confidence × ln(1 + evidence_count)— logarithmic evidence strengthfinal_score = fts_score × 1.0 + recency × 0.3 + evidence_score × 0.5
Results are sorted by final_score descending and truncated to limit.
Sourcepub fn get(&self, id: &str) -> Result<Option<MemoryItem>, MemoryStoreError>
pub fn get(&self, id: &str) -> Result<Option<MemoryItem>, MemoryStoreError>
Get a memory item by ID.
Sourcepub fn count(&self) -> Result<usize, MemoryStoreError>
pub fn count(&self) -> Result<usize, MemoryStoreError>
Count total memory items.
Sourcepub fn checkpoint_truncate(&self) -> Result<(), MemoryStoreError>
pub fn checkpoint_truncate(&self) -> Result<(), MemoryStoreError>
Checkpoint the SQLite write-ahead log, truncating it when possible.
This is an explicit maintenance operation for storage lifecycle workflows; normal memory reads and writes do not invoke it.
Sourcepub fn vacuum(&self) -> Result<(), MemoryStoreError>
pub fn vacuum(&self) -> Result<(), MemoryStoreError>
Rebuild the SQLite database file to reclaim free pages.
This should only be called by explicit maintenance commands, never inside the agent turn loop.
Sourcepub fn memory_status(&self) -> Result<MemoryStatus, MemoryStoreError>
pub fn memory_status(&self) -> Result<MemoryStatus, MemoryStoreError>
Report memory store status without exposing any content.
Sourcepub fn retention_candidates(
&self,
policy: &RetentionPolicy,
) -> Result<Vec<RetentionCandidate>, MemoryStoreError>
pub fn retention_candidates( &self, policy: &RetentionPolicy, ) -> Result<Vec<RetentionCandidate>, MemoryStoreError>
Report memory items that match retention criteria. This is DRY-RUN ONLY — no items are deleted. ADD-only semantics are preserved.