pub struct AutoMemory {
pub entries: Vec<MemoryEntry>,
pub config: MemoryConfig,
pub max_entries: usize,
pub min_importance: f64,
pub enabled: bool,
/* private fields */
}Expand description
Manager for automatic memory accumulation.
Fields§
§entries: Vec<MemoryEntry>All memory entries.
config: MemoryConfigConfiguration for memory management.
max_entries: usizeLegacy fields for backward compatibility (deprecated).
min_importance: f64§enabled: boolImplementations§
Source§impl AutoMemory
impl AutoMemory
Sourcepub fn rebuild_index(&mut self)
pub fn rebuild_index(&mut self)
Rebuild search index.
Sourcepub fn with_config(config: MemoryConfig) -> Self
pub fn with_config(config: MemoryConfig) -> Self
Create with custom configuration.
Sourcepub fn add(&mut self, entry: MemoryEntry)
pub fn add(&mut self, entry: MemoryEntry)
Add a new memory entry.
Sourcepub fn add_memory(
&mut self,
category: MemoryCategory,
content: String,
source_session: Option<String>,
)
pub fn add_memory( &mut self, category: MemoryCategory, content: String, source_session: Option<String>, )
Add memory from detected content.
Sourcepub fn has_similar(&self, content: &str) -> bool
pub fn has_similar(&self, content: &str) -> bool
Check if similar content already exists. Uses minimum length threshold to prevent short words from matching everything.
Sourcepub fn prune(&mut self)
pub fn prune(&mut self)
Remove low-importance entries when exceeding max_entries. Strategy: preserve manual entries + high importance entries, sorted by importance.
Sourcepub fn by_category(&self, category: MemoryCategory) -> Vec<&MemoryEntry>
pub fn by_category(&self, category: MemoryCategory) -> Vec<&MemoryEntry>
Get entries by category.
Sourcepub fn by_category_fast(
&mut self,
category: MemoryCategory,
) -> Vec<&MemoryEntry>
pub fn by_category_fast( &mut self, category: MemoryCategory, ) -> Vec<&MemoryEntry>
Get entries by category using index (faster).
Sourcepub fn top_n(&self, n: usize) -> Vec<&MemoryEntry>
pub fn top_n(&self, n: usize) -> Vec<&MemoryEntry>
Get top N most important entries.
Sourcepub fn top_n_fast(&mut self, n: usize) -> Vec<&MemoryEntry>
pub fn top_n_fast(&mut self, n: usize) -> Vec<&MemoryEntry>
Get top N using index (faster).
Sourcepub fn search(&self, query: &str) -> Vec<&MemoryEntry>
pub fn search(&self, query: &str) -> Vec<&MemoryEntry>
Search entries by content or tags.
Sourcepub fn search_with_limit(
&self,
query: &str,
limit: Option<usize>,
) -> Vec<&MemoryEntry>
pub fn search_with_limit( &self, query: &str, limit: Option<usize>, ) -> Vec<&MemoryEntry>
Search entries with result limit.
Sourcepub fn search_fast(
&mut self,
query: &str,
limit: Option<usize>,
) -> Vec<&MemoryEntry>
pub fn search_fast( &mut self, query: &str, limit: Option<usize>, ) -> Vec<&MemoryEntry>
Search using index (faster).
Sourcepub fn search_multi(&self, keywords: &[&str]) -> Vec<&MemoryEntry>
pub fn search_multi(&self, keywords: &[&str]) -> Vec<&MemoryEntry>
Multi-keyword search (matches any keyword).
Sourcepub fn search_multi_fast(&mut self, keywords: &[&str]) -> Vec<&MemoryEntry>
pub fn search_multi_fast(&mut self, keywords: &[&str]) -> Vec<&MemoryEntry>
Multi-keyword search using index (faster).
Sourcepub fn add_batch(&mut self, entries: Vec<MemoryEntry>)
pub fn add_batch(&mut self, entries: Vec<MemoryEntry>)
Batch add multiple entries efficiently. Only prunes once at the end instead of after each entry.
Sourcepub fn update_references(&mut self, messages: &[Message])
pub fn update_references(&mut self, messages: &[Message])
Mark entries as referenced if they appear in the conversation. Optimized: pre-computes lowercase versions to avoid repeated conversions.
Sourcepub fn generate_prompt_summary(&self, max_entries: usize) -> String
pub fn generate_prompt_summary(&self, max_entries: usize) -> String
Generate summary for system prompt.
Sourcepub fn generate_contextual_summary(
&self,
context: &str,
max_entries: usize,
) -> String
pub fn generate_contextual_summary( &self, context: &str, max_entries: usize, ) -> String
Generate context-aware summary for system prompt.
Unlike generate_prompt_summary which always returns top N by importance,
this method selects memories that are relevant to the current conversation context.
Strategy:
- Always include manual entries (user explicitly added)
- Include entries whose content overlaps with recent conversation keywords
- Fill remaining slots with top importance entries
Sourcepub fn generate_contextual_summary_with_keywords(
&self,
context_keywords: &[String],
max_entries: usize,
) -> String
pub fn generate_contextual_summary_with_keywords( &self, context_keywords: &[String], max_entries: usize, ) -> String
Generate context-aware summary with pre-extracted keywords. More efficient when keywords are already extracted (e.g., by AI).
Sourcepub async fn generate_contextual_summary_async(
&self,
context: &str,
max_entries: usize,
fast_provider: Option<&dyn Provider>,
) -> String
pub async fn generate_contextual_summary_async( &self, context: &str, max_entries: usize, fast_provider: Option<&dyn Provider>, ) -> String
Generate context-aware summary with AI-enhanced keyword extraction.
This is the async version that uses AI to extract keywords when rule-based extraction produces insufficient results.
Sourcepub fn format_all(&self) -> String
pub fn format_all(&self) -> String
Format all entries for display.
Sourcepub fn generate_statistics(&self) -> MemoryStatistics
pub fn generate_statistics(&self) -> MemoryStatistics
Generate statistics summary for display.
Sourcepub fn apply_time_decay(&mut self)
pub fn apply_time_decay(&mut self)
Apply time decay to memory importance. Entries that haven’t been referenced recently will have their importance reduced.
Source§impl AutoMemory
Extended AutoMemory with AI-enhanced operations.
impl AutoMemory
Extended AutoMemory with AI-enhanced operations.
Sourcepub async fn add_memory_with_ai_conflict(
&mut self,
category: MemoryCategory,
content: String,
source_session: Option<String>,
processor: Option<&AiMemoryProcessor>,
) -> Result<()>
pub async fn add_memory_with_ai_conflict( &mut self, category: MemoryCategory, content: String, source_session: Option<String>, processor: Option<&AiMemoryProcessor>, ) -> Result<()>
Add memory with AI conflict detection.
Sourcepub async fn assess_quality_with_ai(
&mut self,
processor: &AiMemoryProcessor,
config: &AiMemoryConfig,
) -> Result<usize>
pub async fn assess_quality_with_ai( &mut self, processor: &AiMemoryProcessor, config: &AiMemoryConfig, ) -> Result<usize>
Assess and filter memories by quality using AI.
Sourcepub async fn merge_similar_with_ai(
&mut self,
processor: &AiMemoryProcessor,
config: &AiMemoryConfig,
) -> Result<usize>
pub async fn merge_similar_with_ai( &mut self, processor: &AiMemoryProcessor, config: &AiMemoryConfig, ) -> Result<usize>
Merge similar memories using AI.
Sourcepub async fn generate_ai_summary(
&self,
max_entries: usize,
processor: Option<&AiMemoryProcessor>,
config: Option<&AiMemoryConfig>,
) -> Result<String>
pub async fn generate_ai_summary( &self, max_entries: usize, processor: Option<&AiMemoryProcessor>, config: Option<&AiMemoryConfig>, ) -> Result<String>
Generate AI-enhanced summary for prompt.
Trait Implementations§
Source§impl Clone for AutoMemory
impl Clone for AutoMemory
Source§fn clone(&self) -> AutoMemory
fn clone(&self) -> AutoMemory
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more