pub struct MemoryManager { /* private fields */ }Expand description
High-level memory manager that coordinates database, embeddings, and chunking
Implementations§
Source§impl MemoryManager
impl MemoryManager
pub fn db(&self) -> &Arc<MemoryDatabase>
Sourcepub async fn new(db_path: &Path) -> MemoryResult<Self>
pub async fn new(db_path: &Path) -> MemoryResult<Self>
Initialize the memory manager
Sourcepub async fn new_with_embedding_service(
db_path: &Path,
embedding_service: EmbeddingService,
) -> MemoryResult<Self>
pub async fn new_with_embedding_service( db_path: &Path, embedding_service: EmbeddingService, ) -> MemoryResult<Self>
Initialize the memory manager with a caller-provided embedding service. Tests use this to avoid depending on local model assets.
Sourcepub async fn store_message(
&self,
request: StoreMessageRequest,
) -> MemoryResult<Vec<String>>
pub async fn store_message( &self, request: StoreMessageRequest, ) -> MemoryResult<Vec<String>>
Store a message in memory
This will:
- Chunk the message content
- Generate embeddings for each chunk
- Store chunks and embeddings in the database
Sourcepub async fn search(
&self,
query: &str,
tier: Option<MemoryTier>,
project_id: Option<&str>,
session_id: Option<&str>,
limit: Option<i64>,
) -> MemoryResult<Vec<MemorySearchResult>>
pub async fn search( &self, query: &str, tier: Option<MemoryTier>, project_id: Option<&str>, session_id: Option<&str>, limit: Option<i64>, ) -> MemoryResult<Vec<MemorySearchResult>>
Search memory for relevant chunks
pub async fn upsert_knowledge_space( &self, space: &KnowledgeSpaceRecord, ) -> MemoryResult<()>
pub async fn get_knowledge_space( &self, id: &str, ) -> MemoryResult<Option<KnowledgeSpaceRecord>>
pub async fn list_knowledge_spaces( &self, project_id: Option<&str>, ) -> MemoryResult<Vec<KnowledgeSpaceRecord>>
pub async fn upsert_knowledge_item( &self, item: &KnowledgeItemRecord, ) -> MemoryResult<()>
pub async fn get_knowledge_item( &self, id: &str, ) -> MemoryResult<Option<KnowledgeItemRecord>>
pub async fn list_knowledge_items( &self, space_id: &str, coverage_key: Option<&str>, ) -> MemoryResult<Vec<KnowledgeItemRecord>>
pub async fn upsert_knowledge_coverage( &self, coverage: &KnowledgeCoverageRecord, ) -> MemoryResult<()>
pub async fn get_knowledge_coverage( &self, coverage_key: &str, space_id: &str, ) -> MemoryResult<Option<KnowledgeCoverageRecord>>
pub async fn promote_knowledge_item( &self, request: &KnowledgePromotionRequest, ) -> MemoryResult<Option<KnowledgePromotionResult>>
pub async fn preflight_knowledge( &self, request: &KnowledgePreflightRequest, ) -> MemoryResult<KnowledgePreflightResult>
Sourcepub async fn retrieve_context(
&self,
query: &str,
project_id: Option<&str>,
session_id: Option<&str>,
token_budget: Option<i64>,
) -> MemoryResult<MemoryContext>
pub async fn retrieve_context( &self, query: &str, project_id: Option<&str>, session_id: Option<&str>, token_budget: Option<i64>, ) -> MemoryResult<MemoryContext>
Retrieve context for a message
This retrieves relevant chunks from all tiers and formats them for injection into the prompt
Sourcepub async fn retrieve_context_with_meta(
&self,
query: &str,
project_id: Option<&str>,
session_id: Option<&str>,
token_budget: Option<i64>,
) -> MemoryResult<(MemoryContext, MemoryRetrievalMeta)>
pub async fn retrieve_context_with_meta( &self, query: &str, project_id: Option<&str>, session_id: Option<&str>, token_budget: Option<i64>, ) -> MemoryResult<(MemoryContext, MemoryRetrievalMeta)>
Retrieve context plus retrieval metadata for observability.
Sourcepub async fn clear_session(&self, session_id: &str) -> MemoryResult<u64>
pub async fn clear_session(&self, session_id: &str) -> MemoryResult<u64>
Clear session memory
Sourcepub async fn clear_project(&self, project_id: &str) -> MemoryResult<u64>
pub async fn clear_project(&self, project_id: &str) -> MemoryResult<u64>
Clear project memory
Sourcepub async fn get_stats(&self) -> MemoryResult<MemoryStats>
pub async fn get_stats(&self) -> MemoryResult<MemoryStats>
Get memory statistics
Sourcepub async fn get_config(&self, project_id: &str) -> MemoryResult<MemoryConfig>
pub async fn get_config(&self, project_id: &str) -> MemoryResult<MemoryConfig>
Get memory configuration for a project
Sourcepub async fn set_config(
&self,
project_id: &str,
config: &MemoryConfig,
) -> MemoryResult<()>
pub async fn set_config( &self, project_id: &str, config: &MemoryConfig, ) -> MemoryResult<()>
Update memory configuration for a project
pub async fn resolve_uri(&self, uri: &str) -> MemoryResult<Option<MemoryNode>>
pub async fn list_directory(&self, uri: &str) -> MemoryResult<DirectoryListing>
pub async fn tree( &self, uri: &str, max_depth: usize, ) -> MemoryResult<Vec<TreeNode>>
pub async fn create_context_node( &self, uri: &str, node_type: NodeType, metadata: Option<Value>, ) -> MemoryResult<String>
pub async fn get_context_layer( &self, node_id: &str, layer_type: LayerType, ) -> MemoryResult<Option<MemoryLayer>>
pub async fn store_content_with_layers( &self, uri: &str, content: &str, metadata: Option<Value>, ) -> MemoryResult<String>
pub async fn generate_layers_for_node( &self, node_id: &str, providers: &ProviderRegistry, ) -> MemoryResult<()>
pub async fn get_layer_content( &self, node_id: &str, layer_type: LayerType, ) -> MemoryResult<Option<String>>
pub async fn store_content_with_layers_auto( &self, uri: &str, content: &str, metadata: Option<Value>, providers: Option<&ProviderRegistry>, ) -> MemoryResult<String>
Sourcepub async fn run_cleanup(&self, project_id: Option<&str>) -> MemoryResult<u64>
pub async fn run_cleanup(&self, project_id: Option<&str>) -> MemoryResult<u64>
Run cleanup based on retention policies
Sourcepub async fn get_cleanup_log(
&self,
_limit: i64,
) -> MemoryResult<Vec<CleanupLogEntry>>
pub async fn get_cleanup_log( &self, _limit: i64, ) -> MemoryResult<Vec<CleanupLogEntry>>
Get cleanup log entries
Sourcepub fn count_tokens(&self, text: &str) -> usize
pub fn count_tokens(&self, text: &str) -> usize
Count tokens in text
Sourcepub async fn embedding_health(&self) -> EmbeddingHealth
pub async fn embedding_health(&self) -> EmbeddingHealth
Report embedding backend health for UI/telemetry.
Sourcepub async fn consolidate_session(
&self,
session_id: &str,
project_id: Option<&str>,
providers: &ProviderRegistry,
config: &MemoryConsolidationConfig,
) -> MemoryResult<Option<String>>
pub async fn consolidate_session( &self, session_id: &str, project_id: Option<&str>, providers: &ProviderRegistry, config: &MemoryConsolidationConfig, ) -> MemoryResult<Option<String>>
Consolidate a session’s memory into a summary chunk using the cheapest available provider.