pub struct MemorySystem { /* private fields */ }Expand description
Main memory system
Implementations§
Source§impl MemorySystem
impl MemorySystem
Sourcepub fn new(config: MemoryConfig, shared_cache: Option<&Cache>) -> Result<Self>
pub fn new(config: MemoryConfig, shared_cache: Option<&Cache>) -> Result<Self>
Create a new memory system.
If shared_cache is provided, all per-user RocksDB instances share the
same LRU block cache (multi-tenant server mode). Pass None for
standalone / test use — each DB gets a small local cache.
Sourcepub fn set_graph_memory(&mut self, graph: Arc<RwLock<GraphMemory>>)
pub fn set_graph_memory(&mut self, graph: Arc<RwLock<GraphMemory>>)
Wire up GraphMemory for entity relationships and spreading activation
When GraphMemory is set, the remember() method will:
- Extract entities from memory content
- Add them to the knowledge graph
- Create edges between co-occurring entities
This enables spreading activation retrieval and Hebbian learning
Sourcepub fn graph_memory(&self) -> Option<&Arc<RwLock<GraphMemory>>>
pub fn graph_memory(&self) -> Option<&Arc<RwLock<GraphMemory>>>
Get reference to the optional graph memory
Sourcepub fn set_feedback_store(&mut self, feedback: Arc<RwLock<FeedbackStore>>)
pub fn set_feedback_store(&mut self, feedback: Arc<RwLock<FeedbackStore>>)
Set the feedback store for momentum-based scoring (PIPE-9)
When set, retrieval automatically applies feedback momentum:
- Positive momentum (frequently helpful) → boost score
- Negative momentum (frequently ignored) → suppress score (up to 20%)
This provides consistent feedback integration across all retrieval paths.
Sourcepub fn feedback_store(&self) -> Option<&Arc<RwLock<FeedbackStore>>>
pub fn feedback_store(&self) -> Option<&Arc<RwLock<FeedbackStore>>>
Get reference to the optional feedback store
Sourcepub fn remember_with_id(
&self,
memory_id: MemoryId,
experience: Experience,
created_at: Option<DateTime<Utc>>,
) -> Result<MemoryId>
pub fn remember_with_id( &self, memory_id: MemoryId, experience: Experience, created_at: Option<DateTime<Utc>>, ) -> Result<MemoryId>
Store a new memory with an explicit ID.
Used by MIF import to preserve original UUIDs. Stores the memory with embedding generation and vector indexing, but skips graph entity extraction (imported memories already have their entity relationships established).
Sourcepub fn remember(
&self,
experience: Experience,
created_at: Option<DateTime<Utc>>,
) -> Result<MemoryId>
pub fn remember( &self, experience: Experience, created_at: Option<DateTime<Utc>>, ) -> Result<MemoryId>
Store a new memory (takes ownership to avoid clones)
Thread-safe: uses interior mutability for all internal state
If created_at is None, uses current time (Utc::now())
Sourcepub fn remember_with_agent(
&self,
experience: Experience,
created_at: Option<DateTime<Utc>>,
agent_id: Option<String>,
run_id: Option<String>,
) -> Result<MemoryId>
pub fn remember_with_agent( &self, experience: Experience, created_at: Option<DateTime<Utc>>, agent_id: Option<String>, run_id: Option<String>, ) -> Result<MemoryId>
Remember with agent context for multi-agent systems
Same as remember but tracks which agent created the memory,
enabling agent-specific retrieval and hierarchical memory tracking.
Sourcepub fn recall(&self, query: &Query) -> Result<Vec<SharedMemory>>
pub fn recall(&self, query: &Query) -> Result<Vec<SharedMemory>>
Search and retrieve relevant memories (zero-copy with Arc
PRODUCTION IMPLEMENTATION:
- Semantic search: Uses embeddings + vector similarity across ALL tiers
- Non-semantic search: Uses importance * temporal decay
- Zero shortcuts, no TODOs, enterprise-grade
Sourcepub fn paginated_recall(
&self,
query: &Query,
) -> Result<PaginatedResults<SharedMemory>>
pub fn paginated_recall( &self, query: &Query, ) -> Result<PaginatedResults<SharedMemory>>
Paginated memory recall with “has_more” indicator (SHO-69)
Returns a PaginatedResults struct containing:
- The page of results
- Whether there are more results beyond this page
- The total count (if computed)
- Pagination metadata (offset, limit)
Uses the limit+1 trick: requests one extra result to detect if there are more.
Recall memories by tags (fast, no embedding required)
Returns memories that have ANY of the specified tags.
Sourcepub fn recall_by_date(
&self,
start: DateTime<Utc>,
end: DateTime<Utc>,
limit: usize,
) -> Result<Vec<Memory>>
pub fn recall_by_date( &self, start: DateTime<Utc>, end: DateTime<Utc>, limit: usize, ) -> Result<Vec<Memory>>
Recall memories within a date range
Returns memories created between start and end (inclusive).
Sourcepub fn apply_learning_boost(
&self,
user_id: &str,
memories: Vec<SharedMemory>,
) -> Vec<SharedMemory> ⓘ
pub fn apply_learning_boost( &self, user_id: &str, memories: Vec<SharedMemory>, ) -> Vec<SharedMemory> ⓘ
Apply learning velocity boost to retrieved memories
This method should be called after recall() when user_id is known.
It boosts memories that have been recently learned/reinforced, implementing
the principle that “learning should improve retrieval over time”.
Boost factors:
- Base boost for any learning activity (5%)
- Velocity boost for rapid learning (up to 15%)
- Potentiation bonus for LTP’d edges (10%)
- Total max boost: 30%
The memories are re-sorted by adjusted score after boosting.
Sourcepub fn recall_for_user(
&self,
user_id: &str,
query: &Query,
) -> Result<Vec<SharedMemory>>
pub fn recall_for_user( &self, user_id: &str, query: &Query, ) -> Result<Vec<SharedMemory>>
Recall with learning boost applied
Convenience method that combines recall() with apply_learning_boost().
Use this when you have the user_id available at recall time.
Sourcepub fn get_learning_velocity(
&self,
user_id: &str,
memory_id: &str,
hours: i64,
) -> Result<LearningVelocity>
pub fn get_learning_velocity( &self, user_id: &str, memory_id: &str, hours: i64, ) -> Result<LearningVelocity>
Get learning velocity statistics for a memory
Returns information about recent learning activity for this memory, useful for debugging/introspection.
Sourcepub fn get_learning_stats(&self, user_id: &str) -> Result<LearningStats>
pub fn get_learning_stats(&self, user_id: &str) -> Result<LearningStats>
Get learning history statistics for a user
Sourcepub fn get_learning_events(
&self,
user_id: &str,
since: DateTime<Utc>,
limit: usize,
) -> Result<Vec<StoredLearningEvent>>
pub fn get_learning_events( &self, user_id: &str, since: DateTime<Utc>, limit: usize, ) -> Result<Vec<StoredLearningEvent>>
Get recent learning events for a user
Sourcepub fn store_temporal_facts_for_memory(
&self,
user_id: &str,
memory_id: &MemoryId,
content: &str,
entities: &[String],
created_at: DateTime<Utc>,
) -> Result<usize>
pub fn store_temporal_facts_for_memory( &self, user_id: &str, memory_id: &MemoryId, content: &str, entities: &[String], created_at: DateTime<Utc>, ) -> Result<usize>
Extract and store temporal facts from a memory
Call this after remember() when you have access to user_id. Extracts facts like “Melanie is planning camping next month” and stores them with resolved absolute dates for accurate multi-hop retrieval.
Sourcepub fn find_temporal_facts(
&self,
user_id: &str,
entity: &str,
event_keywords: &[&str],
event_type: Option<EventType>,
) -> Result<Vec<TemporalFact>>
pub fn find_temporal_facts( &self, user_id: &str, entity: &str, event_keywords: &[&str], event_type: Option<EventType>, ) -> Result<Vec<TemporalFact>>
Find temporal facts by entity and event keywords
Used for multi-hop queries like “When did Melanie paint a sunrise?” Returns facts sorted by conversation date (earliest first for planning queries).
Sourcepub fn list_temporal_facts(
&self,
user_id: &str,
limit: usize,
) -> Result<Vec<TemporalFact>>
pub fn list_temporal_facts( &self, user_id: &str, limit: usize, ) -> Result<Vec<TemporalFact>>
List all temporal facts for a user
Sourcepub fn forget(&self, criteria: ForgetCriteria) -> Result<usize>
pub fn forget(&self, criteria: ForgetCriteria) -> Result<usize>
Forget memories based on criteria Thread-safe: uses interior mutability for all internal state
Sourcepub fn stats(&self) -> MemoryStats
pub fn stats(&self) -> MemoryStats
Get memory statistics
Returns current stats with fresh average_importance calculated from storage. Most counters are cached in-memory for performance, but importance is recalculated to ensure accuracy after memory modifications.
Sourcepub fn export_visualization_dot(&self) -> String
pub fn export_visualization_dot(&self) -> String
Export visualization graph as DOT format for Graphviz
Sourcepub fn build_visualization_graph(&self) -> Result<GraphStats>
pub fn build_visualization_graph(&self) -> Result<GraphStats>
Build visualization graph from current memory state Call this to populate the visualization graph with all current memories
Sourcepub fn get_embedder(&self) -> &dyn Embedder
pub fn get_embedder(&self) -> &dyn Embedder
Get reference to embedder for graph-aware retrieval
Sourcepub fn compute_embedding(&self, text: &str) -> Result<Vec<f32>>
pub fn compute_embedding(&self, text: &str) -> Result<Vec<f32>>
Compute embedding for arbitrary text (for external use like prospective memory)
Sourcepub fn get_all_memories(&self) -> Result<Vec<SharedMemory>>
pub fn get_all_memories(&self) -> Result<Vec<SharedMemory>>
Get all memories across all tiers for graph-aware retrieval Deduplicates by memory ID, preferring working > session > long-term
Sourcepub fn find_memory_by_prefix(
&self,
id_prefix: &str,
) -> Result<Option<SharedMemory>>
pub fn find_memory_by_prefix( &self, id_prefix: &str, ) -> Result<Option<SharedMemory>>
Find a memory by UUID prefix across all tiers.
Accepts both full UUIDs and 8+ char hex prefixes (as displayed by MCP tools).
Searches working → session → long-term memory with deduplication.
Returns Err for ambiguous prefixes (multiple matches).
Sourcepub fn get_working_memories(&self) -> Vec<SharedMemory> ⓘ
pub fn get_working_memories(&self) -> Vec<SharedMemory> ⓘ
Get memories from working memory tier (highest activation, most recent)
Sourcepub fn get_session_memories(&self) -> Vec<SharedMemory> ⓘ
pub fn get_session_memories(&self) -> Vec<SharedMemory> ⓘ
Get memories from session memory tier (medium-term, consolidated)
Sourcepub fn get_longterm_memories(&self, limit: usize) -> Result<Vec<Memory>>
pub fn get_longterm_memories(&self, limit: usize) -> Result<Vec<Memory>>
Get memories from long-term memory tier (persistent, lower activation)
Returns up to limit memories to avoid overwhelming responses
Sourcepub fn apply_edge_promotion_boosts(
&self,
boosts: &[EdgePromotionBoost],
) -> Result<usize>
pub fn apply_edge_promotion_boosts( &self, boosts: &[EdgePromotionBoost], ) -> Result<usize>
Apply importance boosts to memories whose edges were promoted (Direction 1).
When an edge promotes from L1→L2 or L2→L3, the memories involved get
a small importance boost, reflecting that they participate in a consolidating
relationship. Uses interior mutability — set_importance works through Arc.
Sourcepub fn compensate_orphaned_memories(
&self,
orphaned_entity_ids: &[String],
) -> Result<usize>
pub fn compensate_orphaned_memories( &self, orphaned_entity_ids: &[String], ) -> Result<usize>
Apply compensatory boost to memories that lost all graph edges (Direction 2).
When graph decay prunes edges and leaves entities orphaned, the memories referencing those entities get a small importance boost to prevent immediate decay death. This gives them one more maintenance cycle to prove value.
Sourcepub fn show_visualization(&self)
pub fn show_visualization(&self)
Show memory visualization (ASCII art of memory graph)
Sourcepub fn export_graph(&self, path: &Path) -> Result<()>
pub fn export_graph(&self, path: &Path) -> Result<()>
Export memory graph as DOT file for Graphviz
Sourcepub fn get_visualization_stats(&self) -> GraphStats
pub fn get_visualization_stats(&self) -> GraphStats
Get visualization statistics
Sourcepub fn flush_storage(&self) -> Result<()>
pub fn flush_storage(&self) -> Result<()>
Flush long-term storage to ensure data persistence (critical for graceful shutdown)
Sourcepub fn get_db(&self) -> Arc<DB> ⓘ
pub fn get_db(&self) -> Arc<DB> ⓘ
Get the underlying RocksDB database handle for backup operations
§Warning
This provides direct access to the database. Use with caution. Primarily intended for backup/restore operations.
Sourcepub fn advanced_search(&self, criteria: SearchCriteria) -> Result<Vec<Memory>>
pub fn advanced_search(&self, criteria: SearchCriteria) -> Result<Vec<Memory>>
Advanced search using storage criteria
Sourcepub fn get_memory(&self, id: &MemoryId) -> Result<Memory>
pub fn get_memory(&self, id: &MemoryId) -> Result<Memory>
Get memory by ID from long-term storage
Sourcepub fn update_memory(&self, memory: &Memory) -> Result<()>
pub fn update_memory(&self, memory: &Memory) -> Result<()>
Update a memory in storage with full re-indexing
This properly updates the memory by:
- Removing stale secondary indices and re-storing in RocksDB
- Re-indexing in vector DB (semantic search) if embeddings changed
- Re-indexing in BM25 (keyword/hybrid search)
- Updating working/session memory caches if the memory is cached
Sourcepub fn set_memory_parent(
&self,
memory_id: &MemoryId,
parent_id: Option<MemoryId>,
) -> Result<()>
pub fn set_memory_parent( &self, memory_id: &MemoryId, parent_id: Option<MemoryId>, ) -> Result<()>
Set or update the parent of a memory for hierarchical organization
This enables memory trees where memories can have parent-child relationships. Example: “71-research” -> “algebraic” -> “21×27≡-1”
Pass None as parent_id to remove the parent (make it a root memory).
Sourcepub fn get_memory_children(&self, parent_id: &MemoryId) -> Result<Vec<Memory>>
pub fn get_memory_children(&self, parent_id: &MemoryId) -> Result<Vec<Memory>>
Get children of a memory
Sourcepub fn get_memory_ancestors(&self, memory_id: &MemoryId) -> Result<Vec<Memory>>
pub fn get_memory_ancestors(&self, memory_id: &MemoryId) -> Result<Vec<Memory>>
Get ancestors (parent chain) of a memory
Sourcepub fn get_memory_hierarchy(
&self,
memory_id: &MemoryId,
) -> Result<(Vec<Memory>, Memory, Vec<Memory>)>
pub fn get_memory_hierarchy( &self, memory_id: &MemoryId, ) -> Result<(Vec<Memory>, Memory, Vec<Memory>)>
Get full hierarchy context (ancestors, memory, children)
Sourcepub fn decompress_memory(&self, memory: &Memory) -> Result<Memory>
pub fn decompress_memory(&self, memory: &Memory) -> Result<Memory>
Decompress a memory
Sourcepub fn get_storage_stats(&self) -> Result<StorageStats>
pub fn get_storage_stats(&self) -> Result<StorageStats>
Get storage statistics
Sourcepub fn get_uncompressed_older_than(
&self,
cutoff: DateTime<Utc>,
) -> Result<Vec<Memory>>
pub fn get_uncompressed_older_than( &self, cutoff: DateTime<Utc>, ) -> Result<Vec<Memory>>
Get uncompressed old memories
Sourcepub fn rebuild_vector_index(&self) -> Result<()>
pub fn rebuild_vector_index(&self) -> Result<()>
Rebuild vector index from all existing long-term memories (startup initialization)
Sourcepub fn repair_vector_index(&self) -> Result<(usize, usize, usize, usize)>
pub fn repair_vector_index(&self) -> Result<(usize, usize, usize, usize)>
Repair vector index by finding and re-indexing orphaned memories
Orphaned memories are those stored in RocksDB but missing from the vector index. This can happen if embedding generation fails during record().
Returns: (total_storage, indexed, repaired, failed)
Sourcepub fn verify_index_integrity(&self) -> Result<IndexIntegrityReport>
pub fn verify_index_integrity(&self) -> Result<IndexIntegrityReport>
Verify index integrity and return diagnostic information
Returns a struct with:
- total_storage: memories in RocksDB
- total_indexed: memories in vector index
- orphaned_count: memories missing from index
- orphaned_ids: list of orphaned memory IDs (first 100)
Sourcepub fn cleanup_corrupted(&self) -> Result<usize>
pub fn cleanup_corrupted(&self) -> Result<usize>
Cleanup corrupted memories that fail to deserialize Returns the number of entries deleted
Sourcepub fn migrate_legacy(&self) -> Result<(usize, usize, usize)>
pub fn migrate_legacy(&self) -> Result<(usize, usize, usize)>
Migrate legacy memories to current format for improved performance Returns (migrated_count, already_current_count, failed_count)
Sourcepub fn rebuild_index(&self) -> Result<(usize, usize)>
pub fn rebuild_index(&self) -> Result<(usize, usize)>
Rebuild vector index from scratch using only valid memories in storage This removes orphaned index entries and rebuilds with proper ID mappings Returns (total_memories, total_indexed)
Sourcepub fn save_vector_index(&self, _path: &Path) -> Result<()>
pub fn save_vector_index(&self, _path: &Path) -> Result<()>
Save vector index to disk (shutdown persistence) Uses Vamana persistence format for instant startup on restart
Sourcepub fn index_health(&self) -> IndexHealth
pub fn index_health(&self) -> IndexHealth
Get vector index health information
Returns metrics about the Vamana index including total vectors, incremental inserts since last build, and whether rebuild is recommended.
Sourcepub fn auto_rebuild_index_if_needed(&self) -> Result<bool>
pub fn auto_rebuild_index_if_needed(&self) -> Result<bool>
Auto-rebuild vector index if degradation threshold is exceeded
Returns Ok(true) if rebuild was performed, Ok(false) if not needed.
Thread-safe: concurrent calls are no-ops while rebuild is in progress.
Sourcepub fn recall_tracked(&self, query: &Query) -> Result<TrackedRetrieval>
pub fn recall_tracked(&self, query: &Query) -> Result<TrackedRetrieval>
Retrieve memories with tracking for later feedback
Use this when you want to provide feedback on retrieval quality.
Returns a TrackedRetrieval that can be used with reinforce_recall.
§Example
let tracked = memory_system.recall_tracked(&query)?;
// Use memories...
// Later, after task completion:
memory_system.reinforce_recall(&tracked.memory_ids(), RetrievalOutcome::Helpful)?;Sourcepub fn reinforce_recall(
&self,
memory_ids: &[MemoryId],
outcome: RetrievalOutcome,
) -> Result<ReinforcementStats>
pub fn reinforce_recall( &self, memory_ids: &[MemoryId], outcome: RetrievalOutcome, ) -> Result<ReinforcementStats>
Reinforce memories based on task outcome (core feedback loop)
This is THE key method that closes the Hebbian loop:
- If outcome is Helpful: strengthen associations, boost importance
- If outcome is Misleading: weaken associations, reduce importance
- If outcome is Neutral: just record access (mild reinforcement)
CACHE COHERENCY: This method updates BOTH the in-memory caches AND persistent storage to ensure importance changes are visible immediately through cached references (via Arc interior mutability) AND survive restarts.
§Arguments
memory_ids- IDs of memories that were used in the taskoutcome- Whether the memories were helpful, misleading, or neutral
§Returns
Statistics about what was reinforced
Sourcepub fn reinforce_recall_tracked(
&self,
tracked: &TrackedRetrieval,
outcome: RetrievalOutcome,
) -> Result<ReinforcementStats>
pub fn reinforce_recall_tracked( &self, tracked: &TrackedRetrieval, outcome: RetrievalOutcome, ) -> Result<ReinforcementStats>
Reinforce using a tracked recall (convenience wrapper)
Sourcepub fn graph_maintenance(&self)
pub fn graph_maintenance(&self)
Perform graph maintenance (decay old edges, prune weak ones)
Call this periodically (e.g., every hour or on user logout) to let unused associations naturally fade.
Sourcepub fn graph_stats(&self) -> MemoryGraphStats
pub fn graph_stats(&self) -> MemoryGraphStats
Get memory graph statistics
Sourcepub fn upsert(
&self,
external_id: String,
experience: Experience,
change_type: ChangeType,
changed_by: Option<String>,
change_reason: Option<String>,
) -> Result<(MemoryId, bool)>
pub fn upsert( &self, external_id: String, experience: Experience, change_type: ChangeType, changed_by: Option<String>, change_reason: Option<String>, ) -> Result<(MemoryId, bool)>
Upsert a memory: create if new, update with history tracking if exists
When a memory with the same external_id exists:
- Old content is pushed to history (audit trail)
- Content is updated with new content
- Version is incremented
- Embeddings are regenerated for new content
- Vector index is updated
§Arguments
external_id- External system identifier (e.g., “linear:SHO-39”, “github:pr-123”)experience- The experience data to storechange_type- Type of change (ContentUpdated, StatusChanged, etc.)changed_by- Optional: who/what triggered the changechange_reason- Optional: description of why this changed
§Returns
(MemoryId, bool)- Memory ID and whether it was an update (true) or create (false)
Sourcepub fn get_memory_history(
&self,
memory_id: &MemoryId,
) -> Result<Vec<MemoryRevision>>
pub fn get_memory_history( &self, memory_id: &MemoryId, ) -> Result<Vec<MemoryRevision>>
Get the history of a memory (audit trail of changes)
Returns the full revision history for memories with external linking. Returns empty vec for regular (non-mutable) memories.
Sourcepub fn find_by_external_id(&self, external_id: &str) -> Result<Option<Memory>>
pub fn find_by_external_id(&self, external_id: &str) -> Result<Option<Memory>>
Find a memory by external ID
Used to check if a memory already exists for an external entity
Sourcepub fn run_maintenance(
&self,
decay_factor: f32,
user_id: &str,
is_heavy: bool,
) -> Result<MaintenanceResult>
pub fn run_maintenance( &self, decay_factor: f32, user_id: &str, is_heavy: bool, ) -> Result<MaintenanceResult>
Run periodic maintenance (consolidation, activation decay, graph maintenance)
Call this periodically (e.g., every 5 minutes) to:
- Promote memories between tiers based on thresholds
- Decay activation levels on all memories
- Run graph maintenance (prune weak edges)
is_heavy: when true, runs expensive operations (fact extraction, auto-repair)
that require full RocksDB scans. Light cycles only touch in-memory data.
Returns the number of memories processed for activation decay. Also records consolidation events for introspection.
Sourcepub fn get_consolidation_report(
&self,
since: DateTime<Utc>,
until: Option<DateTime<Utc>>,
) -> ConsolidationReport
pub fn get_consolidation_report( &self, since: DateTime<Utc>, until: Option<DateTime<Utc>>, ) -> ConsolidationReport
Get a consolidation report for a time period
Shows what the memory system has been learning:
- Which memories strengthened or decayed
- What associations formed or were pruned
- What facts were extracted or reinforced
§Arguments
since- Start of the time perioduntil- End of the time period (default: now)
Sourcepub fn get_consolidation_report_for_user(
&self,
user_id: &str,
since: DateTime<Utc>,
until: Option<DateTime<Utc>>,
) -> Result<ConsolidationReport>
pub fn get_consolidation_report_for_user( &self, user_id: &str, since: DateTime<Utc>, until: Option<DateTime<Utc>>, ) -> Result<ConsolidationReport>
Get a consolidation report for a user using persisted history
Unlike get_consolidation_report, this method uses persisted learning history
and can generate reports spanning across restarts. It combines:
- Persisted significant events from learning_history (survives restarts)
- Ephemeral events from the event buffer (current session)
Use this when you need historical reports beyond the current session.
Sourcepub fn get_consolidation_events_since(
&self,
since: DateTime<Utc>,
) -> Vec<ConsolidationEvent>
pub fn get_consolidation_events_since( &self, since: DateTime<Utc>, ) -> Vec<ConsolidationEvent>
Get all consolidation events since a timestamp
Returns raw events for detailed analysis
Sourcepub fn get_all_consolidation_events(&self) -> Vec<ConsolidationEvent>
pub fn get_all_consolidation_events(&self) -> Vec<ConsolidationEvent>
Get all consolidation events in the buffer
Sourcepub fn record_consolidation_event(&self, event: ConsolidationEvent)
pub fn record_consolidation_event(&self, event: ConsolidationEvent)
Record a consolidation event
Used internally by the memory system to log learning events. Also available for external callers that want to track custom events.
Sourcepub fn record_consolidation_event_for_user(
&self,
user_id: &str,
event: ConsolidationEvent,
)
pub fn record_consolidation_event_for_user( &self, user_id: &str, event: ConsolidationEvent, )
Record a consolidation event for a specific user
This method both:
- Pushes to the ephemeral event buffer (for real-time introspection)
- Persists significant events to learning_history (for retrieval boosting)
Use this instead of record_consolidation_event when you have a user_id.
Sourcepub fn clear_consolidation_events(&self)
pub fn clear_consolidation_events(&self)
Clear all consolidation events
Sourcepub fn consolidation_event_count(&self) -> usize
pub fn consolidation_event_count(&self) -> usize
Get the number of consolidation events in the buffer
Sourcepub fn distill_facts(
&self,
user_id: &str,
min_support: usize,
min_age_days: i64,
) -> Result<ConsolidationResult>
pub fn distill_facts( &self, user_id: &str, min_support: usize, min_age_days: i64, ) -> Result<ConsolidationResult>
Distill semantic facts from episodic memories
Runs the consolidation process to extract durable knowledge:
- Find patterns appearing in multiple memories
- Create or reinforce semantic facts
- Store facts in the fact store
§Arguments
user_id- User whose memories to consolidatemin_support- Minimum memories needed to form a fact (default: 3)min_age_days- Minimum age of memories to consider (default: 7)
§Returns
ConsolidationResult with stats and newly extracted facts
Sourcepub fn get_facts(
&self,
user_id: &str,
limit: usize,
) -> Result<Vec<SemanticFact>>
pub fn get_facts( &self, user_id: &str, limit: usize, ) -> Result<Vec<SemanticFact>>
Get semantic facts for a user
§Arguments
user_id- User whose facts to retrievelimit- Maximum number of facts to return
Sourcepub fn get_facts_by_entity(
&self,
user_id: &str,
entity: &str,
limit: usize,
) -> Result<Vec<SemanticFact>>
pub fn get_facts_by_entity( &self, user_id: &str, entity: &str, limit: usize, ) -> Result<Vec<SemanticFact>>
Get facts related to a specific entity
§Arguments
user_id- User whose facts to searchentity- Entity to search for (e.g., “authentication”, “JWT”)limit- Maximum number of facts to return
Sourcepub fn get_facts_by_type(
&self,
user_id: &str,
fact_type: FactType,
limit: usize,
) -> Result<Vec<SemanticFact>>
pub fn get_facts_by_type( &self, user_id: &str, fact_type: FactType, limit: usize, ) -> Result<Vec<SemanticFact>>
Get facts of a specific type
§Arguments
user_id- User whose facts to searchfact_type- Type of fact (Preference, Procedure, Definition, etc.)limit- Maximum number of facts to return
Sourcepub fn search_facts(
&self,
user_id: &str,
query: &str,
limit: usize,
) -> Result<Vec<SemanticFact>>
pub fn search_facts( &self, user_id: &str, query: &str, limit: usize, ) -> Result<Vec<SemanticFact>>
Search facts by keyword
§Arguments
user_id- User whose facts to searchquery- Search querylimit- Maximum number of facts to return
Sourcepub fn get_fact_stats(&self, user_id: &str) -> Result<FactStats>
pub fn get_fact_stats(&self, user_id: &str) -> Result<FactStats>
Get statistics about stored facts
Sourcepub fn get_facts_for_graph_entities(
&self,
user_id: &str,
entity_names: &[String],
limit_per_entity: usize,
) -> Result<Vec<SemanticFact>>
pub fn get_facts_for_graph_entities( &self, user_id: &str, entity_names: &[String], limit_per_entity: usize, ) -> Result<Vec<SemanticFact>>
Get facts associated with graph entity names.
Bridges graph traversal → fact retrieval: when spreading activation discovers entity nodes, this method returns the semantic facts linked to those entities. Results are deduplicated and sorted by confidence (highest first).
Sourcepub fn reinforce_fact(
&self,
user_id: &str,
fact_id: &str,
memory_id: &MemoryId,
) -> Result<bool>
pub fn reinforce_fact( &self, user_id: &str, fact_id: &str, memory_id: &MemoryId, ) -> Result<bool>
Reinforce a fact with new supporting evidence
Called when a new memory supports an existing fact. Increments support_count and boosts confidence.
Sourcepub fn delete_fact(&self, user_id: &str, fact_id: &str) -> Result<bool>
pub fn delete_fact(&self, user_id: &str, fact_id: &str) -> Result<bool>
Delete a fact (soft delete or hard delete)
Sourcepub fn fact_store(&self) -> &Arc<SemanticFactStore>
pub fn fact_store(&self) -> &Arc<SemanticFactStore>
Get the fact store for direct access
Sourcepub fn lineage_graph(&self) -> &Arc<LineageGraph>
pub fn lineage_graph(&self) -> &Arc<LineageGraph>
Get the lineage graph for direct access
Sourcepub fn infer_lineage_for_memory(
&self,
user_id: &str,
new_memory: &Memory,
candidate_memories: &[Memory],
) -> Result<Vec<LineageEdge>>
pub fn infer_lineage_for_memory( &self, user_id: &str, new_memory: &Memory, candidate_memories: &[Memory], ) -> Result<Vec<LineageEdge>>
Infer and store lineage between a new memory and existing memories
Called after storing a new memory to automatically detect causal relationships. Uses entity overlap, temporal proximity, and memory type patterns.
Sourcepub fn trace_lineage(
&self,
user_id: &str,
memory_id: &MemoryId,
direction: TraceDirection,
max_depth: usize,
) -> Result<LineageTrace>
pub fn trace_lineage( &self, user_id: &str, memory_id: &MemoryId, direction: TraceDirection, max_depth: usize, ) -> Result<LineageTrace>
Trace lineage from a memory
Sourcepub fn find_root_cause(
&self,
user_id: &str,
memory_id: &MemoryId,
) -> Result<Option<MemoryId>>
pub fn find_root_cause( &self, user_id: &str, memory_id: &MemoryId, ) -> Result<Option<MemoryId>>
Find the root cause of a memory
Sourcepub fn lineage_stats(&self, user_id: &str) -> Result<LineageStats>
pub fn lineage_stats(&self, user_id: &str) -> Result<LineageStats>
Get lineage statistics
Trait Implementations§
Source§impl Drop for MemorySystem
Automatic persistence on drop - ensures vector index and ID mappings survive restarts
impl Drop for MemorySystem
Automatic persistence on drop - ensures vector index and ID mappings survive restarts
This is CRITICAL for local memory: when the system shuts down (gracefully or via drop), all in-memory state (vector index, ID mappings) must be persisted to disk.
Auto Trait Implementations§
impl !Freeze for MemorySystem
impl !RefUnwindSafe for MemorySystem
impl Send for MemorySystem
impl Sync for MemorySystem
impl Unpin for MemorySystem
impl UnsafeUnpin for MemorySystem
impl !UnwindSafe for MemorySystem
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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