pub struct MemoryStore { /* private fields */ }Expand description
Core memory store combining embedding generation and persistence.
Wraps a SQLite database and ONNX embedding engine to provide semantic search capabilities for stored text memories.
§Mutability Requirements
Methods that generate embeddings (add, search, update) require
&mut self because EmbeddingEngine::embed internally mutates state
for ONNX tensor allocations.
Implementations§
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn add_with_conflict(
&mut self,
project_id: &str,
content: &str,
metadata: Option<&str>,
force: bool,
) -> Result<AddResult, Error>
pub fn add_with_conflict( &mut self, project_id: &str, content: &str, metadata: Option<&str>, force: bool, ) -> Result<AddResult, Error>
Add a memory with conflict detection.
Checks for similar existing memories before adding. If conflicts are found (similarity >= threshold), returns conflicts details without storing.
§Arguments
project_id- Project identifier (e.g., git repo URL or user-defined)content- Text content to store (1 to 100,000 characters)metadata- Optional JSON metadata stringforce- If true, bypass conflict detection and add regardless
§Returns
Ok(AddResult::Added { id })if no conflicts or force=trueOk(AddResult::Conflicts { proposed, conflicts })if conflicts found
§Errors
Returns error if:
- Input is empty
- Input exceeds 100,000 characters
- Embedding generation fails
- Database operations fail
Sourcepub fn get(&self, id: &str) -> Result<Option<Memory>, Error>
pub fn get(&self, id: &str) -> Result<Option<Memory>, Error>
Get a specific memory by ID.
Returns None if the memory doesn’t exist.
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn search(
&mut self,
project_id: &str,
query: &str,
limit: usize,
recency_weight: f64,
) -> Result<Vec<Memory>, Error>
pub fn search( &mut self, project_id: &str, query: &str, limit: usize, recency_weight: f64, ) -> Result<Vec<Memory>, Error>
Search memories by semantic similarity.
Generates an embedding for the query and finds memories with highest cosine similarity scores. Optionally applies recency weighting to boost recent memories.
§Arguments
project_id- Project identifier to search withinquery- Search query text (1 to 100,000 characters)limit- Maximum number of results to returnrecency_weight- Weight for temporal decay (0.0 = pure semantic, 1.0 = max recency)
§Returns
Vector of memories sorted by similarity or recency-adjusted score (highest first).
Each memory includes a similarity score field (recency-adjusted if weight > 0).
§Errors
Returns error if:
- Query is empty
- Query exceeds 100,000 characters
- Recency weight is invalid
- Embedding generation fails
- Database operations fail
Sourcepub fn search_hybrid(
&mut self,
project_id: &str,
query: &str,
limit: usize,
recency_weight: f64,
) -> Result<Vec<Memory>, Error>
pub fn search_hybrid( &mut self, project_id: &str, query: &str, limit: usize, recency_weight: f64, ) -> Result<Vec<Memory>, Error>
Search memories using hybrid search (semantic + BM25 fused with RRF).
Combines semantic embedding search and BM25 full-text search using Reciprocal Rank Fusion (RRF), then optionally applies recency weighting.
§Arguments
project_id- Project identifier to search withinquery- Search query text (1 to 100,000 characters)limit- Maximum number of results to returnrecency_weight- Weight for temporal decay (0.0 = pure score, 1.0 = max recency)
§Returns
Vector of memories sorted by fused or recency-adjusted score (highest first).
The similarity field contains the final RRF score (or recency-adjusted if weight > 0).
§Errors
Returns error if:
- Query is empty
- Query exceeds 100,000 characters
- Recency weight is invalid
- Embedding generation fails
- Database operations fail
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn new(
db_path: &Path,
model_id: &str,
config: Config,
) -> Result<Self, Error>
pub fn new( db_path: &Path, model_id: &str, config: Config, ) -> Result<Self, Error>
Initialize a new memory store with database path, model ID, and config.
§Arguments
db_path- Path to the SQLite database file (created if it doesn’t exist)model_id- HuggingFace model ID (e.g., “BAAI/bge-small-en-v1.5”)config- Configuration including similarity threshold for conflict detection
§Errors
Returns error if:
- Database path contains path traversal sequences (e.g., “../”)
- Parent directory cannot be canonicalized
- Database cannot be opened
Auto Trait Implementations§
impl !Freeze for MemoryStore
impl !RefUnwindSafe for MemoryStore
impl Send for MemoryStore
impl !Sync for MemoryStore
impl Unpin for MemoryStore
impl UnsafeUnpin for MemoryStore
impl !UnwindSafe for MemoryStore
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 more