pub struct SqliteMemoryStore { /* private fields */ }Expand description
SQLite-backed memory store.
Wraps MemoryDatabase and provides high-level CRUD + search operations
that the existing MemoryManager API expects.
Implementations§
Source§impl SqliteMemoryStore
impl SqliteMemoryStore
Sourcepub fn new(
db: Arc<MemoryDatabase>,
embedding: Arc<dyn EmbeddingProvider>,
) -> SqliteMemoryStore
pub fn new( db: Arc<MemoryDatabase>, embedding: Arc<dyn EmbeddingProvider>, ) -> SqliteMemoryStore
Create a new SQLite memory store.
Sourcepub fn db(&self) -> &Arc<MemoryDatabase> ⓘ
pub fn db(&self) -> &Arc<MemoryDatabase> ⓘ
Returns a reference to the underlying database.
Sourcepub async fn remember(&self, entry: &MemoryEntry) -> Result<String, Error>
pub async fn remember(&self, entry: &MemoryEntry) -> Result<String, Error>
Store a memory entry. Returns the entry ID.
Inserts into memories table, FTS5 (via trigger), and sqlite-vec.
Sourcepub fn get(
&self,
id: &str,
_memory_type: MemoryType,
) -> Result<Option<MemoryEntry>, Error>
pub fn get( &self, id: &str, _memory_type: MemoryType, ) -> Result<Option<MemoryEntry>, Error>
Retrieve a single memory by ID and type.
Sourcepub fn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>, Error>
pub fn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>, Error>
Retrieve a memory by ID (searches all types).
Sourcepub fn forget(&self, id: &str, _memory_type: MemoryType) -> Result<bool, Error>
pub fn forget(&self, id: &str, _memory_type: MemoryType) -> Result<bool, Error>
Delete a memory entry.
Sourcepub fn list(
&self,
memory_type: MemoryType,
limit: usize,
) -> Result<Vec<MemoryEntry>, Error>
pub fn list( &self, memory_type: MemoryType, limit: usize, ) -> Result<Vec<MemoryEntry>, Error>
List memories of a given type, most recent first.
Sourcepub async fn search(
&self,
query: &str,
memory_type: Option<MemoryType>,
limit: usize,
) -> Result<Vec<MemoryEntry>, Error>
pub async fn search( &self, query: &str, memory_type: Option<MemoryType>, limit: usize, ) -> Result<Vec<MemoryEntry>, Error>
Search memories using BM25 + optional vector KNN with RRF fusion.
Sourcepub async fn semantic_search(
&self,
query: &str,
memory_type: Option<MemoryType>,
limit: usize,
) -> Result<Vec<RankedMemory>, Error>
pub async fn semantic_search( &self, query: &str, memory_type: Option<MemoryType>, limit: usize, ) -> Result<Vec<RankedMemory>, Error>
Semantic search returning scored results.
Sourcepub async fn recall(
&self,
query: &str,
max_recall: usize,
) -> Result<Vec<MemoryEntry>, Error>
pub async fn recall( &self, query: &str, max_recall: usize, ) -> Result<Vec<MemoryEntry>, Error>
Recall relevant memories for a new session.
Sourcepub async fn recall_with_rerank(
&self,
query: &str,
max_recall: usize,
) -> Result<Vec<MemoryEntry>, Error>
pub async fn recall_with_rerank( &self, query: &str, max_recall: usize, ) -> Result<Vec<MemoryEntry>, Error>
Recall with Flash Attention re-ranking (Phase 6).
First does standard recall, then re-ranks results using Flash Attention to compute context-aware relevance scores.
The query and memory embeddings form the Q/K/V of the attention mechanism. The output attention weights determine final ranking.
Sourcepub fn total_entries(&self) -> usize
pub fn total_entries(&self) -> usize
Count total entries in the database.
Sourcepub fn count_by_type(&self, memory_type: MemoryType) -> usize
pub fn count_by_type(&self, memory_type: MemoryType) -> usize
Count entries by type.
Sourcepub fn blend_into_prompt(
&self,
memories: &[MemoryEntry],
system_prompt: &str,
) -> String
pub fn blend_into_prompt( &self, memories: &[MemoryEntry], system_prompt: &str, ) -> String
Blend recalled memories into the system prompt.
Sourcepub async fn is_duplicate(&self, content: &str) -> bool
pub async fn is_duplicate(&self, content: &str) -> bool
Check if a memory entry with identical content already exists.
Sourcepub async fn remember_unique(
&self,
entry: &MemoryEntry,
) -> Result<Option<String>, Error>
pub async fn remember_unique( &self, entry: &MemoryEntry, ) -> Result<Option<String>, Error>
Store a memory entry only if no duplicate content exists.
Sourcepub fn migrate_if_needed(&self, workspace_dir: &Path) -> Result<(), Error>
pub fn migrate_if_needed(&self, workspace_dir: &Path) -> Result<(), Error>
Run JSON → SQLite migration if needed.
Sourcepub fn build_co_access_graph(&self) -> MemoryGraph
pub fn build_co_access_graph(&self) -> MemoryGraph
Build a co-access graph from memory session history.
Groups memories by session_id and links all co-accessed pairs.
Returns a MemoryGraph ready for PageRank computation.
Sourcepub fn compute_pagerank(
&self,
damping: f64,
iterations: usize,
initial_scores: Option<&HashMap<u64, f64>>,
) -> HashMap<u64, f64>
pub fn compute_pagerank( &self, damping: f64, iterations: usize, initial_scores: Option<&HashMap<u64, f64>>, ) -> HashMap<u64, f64>
Compute PageRank-based importance scores for all memories.
Returns a map of memory rowid -> PageRank score. Higher scores indicate memories that are more “central” in the co-access graph — they bridge topics and appear in many sessions.
Sourcepub fn apply_pagerank_boost(
&self,
pagerank_scores: &HashMap<u64, f64>,
boost_factor: f32,
) -> usize
pub fn apply_pagerank_boost( &self, pagerank_scores: &HashMap<u64, f64>, boost_factor: f32, ) -> usize
Apply PageRank scores as importance boosts.
For each memory, the importance is updated as:
new_importance = old_importance * (1 + pagerank_boost * pagerank_score)
Returns the number of entries updated.
Sourcepub fn list_by_tier(
&self,
tier: MemoryTier,
limit: usize,
) -> Result<Vec<MemoryEntry>, Error>
pub fn list_by_tier( &self, tier: MemoryTier, limit: usize, ) -> Result<Vec<MemoryEntry>, Error>
List memories by tier.
Sourcepub fn update_entry(&self, entry: &MemoryEntry) -> Result<(), Error>
pub fn update_entry(&self, entry: &MemoryEntry) -> Result<(), Error>
Update a memory entry in-place.
Sourcepub fn save_pattern(
&self,
id: &str,
strategy: &str,
domain: Option<&str>,
quality: f32,
data: &str,
) -> Result<(), Error>
pub fn save_pattern( &self, id: &str, strategy: &str, domain: Option<&str>, quality: f32, data: &str, ) -> Result<(), Error>
Store a learning pattern.
Sourcepub fn load_patterns(&self) -> Result<Vec<PatternRow>, Error>
pub fn load_patterns(&self) -> Result<Vec<PatternRow>, Error>
Load all learning patterns.
Sourcepub fn record_pattern_usage(&self, id: &str, success: bool) -> Result<(), Error>
pub fn record_pattern_usage(&self, id: &str, success: bool) -> Result<(), Error>
Record a pattern usage.
Sourcepub fn auto_promote_patterns(&self, min_quality: f32, min_usage: u32) -> usize
pub fn auto_promote_patterns(&self, min_quality: f32, min_usage: u32) -> usize
Auto-promote high-quality patterns to long-term storage.
Patterns with quality >= min_quality and use_count >= min_usage
are marked as long-term.