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.
Trait Implementations§
Source§impl Debug for SqliteMemoryStore
impl Debug for SqliteMemoryStore
Source§impl MemoryBackend for SqliteMemoryStore
impl MemoryBackend for SqliteMemoryStore
Source§fn remember<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
fn remember<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
Source§fn get(
&self,
id: &str,
memory_type: MemoryType,
) -> Result<Option<MemoryEntry>, Error>
fn get( &self, id: &str, memory_type: MemoryType, ) -> Result<Option<MemoryEntry>, Error>
Source§fn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>, Error>
fn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>, Error>
Source§fn forget(&self, id: &str, memory_type: MemoryType) -> Result<bool, Error>
fn forget(&self, id: &str, memory_type: MemoryType) -> Result<bool, Error>
Source§fn list(
&self,
memory_type: MemoryType,
limit: usize,
) -> Result<Vec<MemoryEntry>, Error>
fn list( &self, memory_type: MemoryType, limit: usize, ) -> Result<Vec<MemoryEntry>, Error>
Source§fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
memory_type: Option<MemoryType>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
memory_type: Option<MemoryType>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
Source§fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
Source§fn recall_with_rerank<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
fn recall_with_rerank<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
Source§fn blend_into_prompt(
&self,
memories: &[MemoryEntry],
system_prompt: &str,
) -> String
fn blend_into_prompt( &self, memories: &[MemoryEntry], system_prompt: &str, ) -> String
Source§fn is_duplicate<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
fn is_duplicate<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
Source§fn remember_unique<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
fn remember_unique<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
SqliteMemoryStore: 'async_trait,
Source§fn list_by_tier(
&self,
tier: MemoryTier,
limit: usize,
) -> Result<Vec<MemoryEntry>, Error>
fn list_by_tier( &self, tier: MemoryTier, limit: usize, ) -> Result<Vec<MemoryEntry>, Error>
Auto Trait Implementations§
impl !RefUnwindSafe for SqliteMemoryStore
impl !UnwindSafe for SqliteMemoryStore
impl Freeze for SqliteMemoryStore
impl Send for SqliteMemoryStore
impl Sync for SqliteMemoryStore
impl Unpin for SqliteMemoryStore
impl UnsafeUnpin for SqliteMemoryStore
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreimpl<T> MaybeSendSync for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.