Skip to main content

MemoryStore

Struct MemoryStore 

Source
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

Source

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.

Source

pub fn open_memory() -> Result<Self, MemoryStoreError>

Open an in-memory store for testing.

Source

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.

Source

pub fn insert_evidence( &self, link: EvidenceLink, ) -> Result<(), MemoryStoreError>

Insert an evidence link for a memory item.

Source

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 days
  • evidence_score = confidence × ln(1 + evidence_count) — logarithmic evidence strength
  • final_score = fts_score × 1.0 + recency × 0.3 + evidence_score × 0.5

Results are sorted by final_score descending and truncated to limit.

Source

pub fn get(&self, id: &str) -> Result<Option<MemoryItem>, MemoryStoreError>

Get a memory item by ID.

Source

pub fn count(&self) -> Result<usize, MemoryStoreError>

Count total memory items.

Source

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.

Source

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.

Source

pub fn memory_status(&self) -> Result<MemoryStatus, MemoryStoreError>

Report memory store status without exposing any content.

Source

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.

Source

pub fn graph_upsert_node( &self, node: &GraphNode, ) -> Result<(), MemoryStoreError>

Source

pub fn graph_upsert_edge( &self, edge: &GraphEdge, ) -> Result<(), MemoryStoreError>

Source

pub fn graph_get_node( &self, id: &str, ) -> Result<Option<GraphNode>, MemoryStoreError>

Source

pub fn graph_recall( &self, seed_ids: &[&str], max_hops: usize, min_edge_weight: f64, fanout: usize, ) -> Result<Vec<AssociationResult>, MemoryStoreError>

Trait Implementations§

Source§

impl MemoryPersistence for MemoryStore

Source§

fn insert(&mut self, item: MemoryItem) -> Result<bool, MemoryStoreError>

Preserve add-only semantics: false means an exact duplicate was ignored.
Source§

fn insert_evidence(&self, link: EvidenceLink) -> Result<(), MemoryStoreError>

Attach source provenance to an existing memory item.
Source§

fn retrieve( &self, query: &str, limit: usize, ) -> Result<Vec<RetrievalResult>, MemoryStoreError>

Return existing bounded, scored lexical retrieval results.
Source§

fn get(&self, id: &str) -> Result<Option<MemoryItem>, MemoryStoreError>

Look up one memory by its stable domain identifier.
Source§

fn count(&self) -> Result<usize, MemoryStoreError>

Count authoritative memory records.
Source§

fn graph_upsert_node(&self, node: &GraphNode) -> Result<(), MemoryStoreError>

Upsert a domain graph node without treating it as a vector index.
Source§

fn graph_upsert_edge(&self, edge: &GraphEdge) -> Result<(), MemoryStoreError>

Upsert a domain graph edge preserving its evidence semantics.
Source§

fn graph_recall( &self, seed_ids: &[&str], max_hops: usize, min_edge_weight: f64, fanout: usize, ) -> Result<Vec<AssociationResult>, MemoryStoreError>

Recall associated records within existing graph traversal bounds.
Source§

fn retention_candidates( &self, policy: &RetentionPolicy, ) -> Result<Vec<RetentionCandidate>, MemoryStoreError>

Select records eligible under the existing retention policy.

Auto Trait Implementations§

§

impl !Freeze for MemoryStore

§

impl !RefUnwindSafe for MemoryStore

§

impl !Sync for MemoryStore

§

impl !UnwindSafe for MemoryStore

§

impl Forget for MemoryStore

§

impl Move for MemoryStore

§

impl Send for MemoryStore

§

impl Unpin for MemoryStore
where *mut sqlite3: Unpin, Arc<Mutex<*mut sqlite3>>: Unpin, *const u8 is !null: Unpin, *const Node<Arc<str>, RawStatement> is !null: Unpin,

§

impl UnsafeUnpin for MemoryStore
where *mut sqlite3: UnsafeUnpin, *const ArcInner<Mutex<*mut sqlite3>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<*mut sqlite3>>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<NonNull<Node<Arc<str>, RawStatement>>>: UnsafeUnpin, *const Node<Arc<str>, RawStatement> is !null: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.