Expand description
Memory system for MatrixCode.
This module implements automatic memory accumulation for AI agents. It captures user preferences, project decisions, key findings, and solutions across sessions, providing persistent context.
§Module Structure
- config: Constants and configuration
- types: Core types (MemoryCategory, MemoryEntry, AutoMemory)
- storage: File storage with locking
- retrieval: TF-IDF search, keyword extraction
- extractor: AI and rule-based memory detection
- learning: Feedback learning, behavior inference
- project: Project structure analysis
- keywords_config: Customizable keywords configuration
Structs§
- AiMemory
Extractor - AI-based memory extractor using a fast/cheap model.
- Auto
Memory - Manager for automatic memory accumulation.
- Behavior
Inference - Result of behavior inference.
- Behavior
Inference Config - Configuration for behavior inference.
- Feedback
Result - Result of feedback detection.
- Keywords
Config - Keywords configuration for memory detection.
- Memory
Config - Configuration for the memory system.
- Memory
Entry - A single memory entry.
- Memory
File Lock - File lock for preventing concurrent access to memory storage.
- Memory
Statistics - Statistics about memory collection.
- Memory
Storage - Storage for memory files (global and project-level) with file locking.
- Project
Structure Analyzer - Project
Type Config - Project type detection configuration.
- Stop
Words Config - Stop words configuration.
- TfIdf
Search - Semantic search using TF-IDF algorithm.
Enums§
- AiDetection
Mode - AI memory detection mode. Controls whether AI is used for memory category detection.
- AiKeyword
Mode - AI keyword extraction mode.
- Feedback
Action - Action to take when user feedback is detected.
- Memory
Category - Categories for memory entries.
Constants§
- CONFLICT_
OVERLAY_ THRESHOLD - Topic overlap threshold for conflict detection.
- CONFLICT_
OVERLAY_ THRESHOLD_ WITH_ SIGNAL - Lower topic overlap threshold when change signal is present.
- CONTEXT_
IMPORTANCE_ WEIGHT - Weight for importance in contextual summary (1.0 - CONTEXT_RELEVANCE_WEIGHT).
- CONTEXT_
RELEVANCE_ WEIGHT - Weight for relevance in contextual summary (relevance vs importance trade-off).
- DEFAULT_
FAST_ MODEL - Default fast model for AI memory extraction.
- DEFAULT_
IMPORTANCE_ DECISION - Default importance scores by category. Lower values allow for gradual importance growth through references.
- DEFAULT_
IMPORTANCE_ FINDING - DEFAULT_
IMPORTANCE_ PREF - DEFAULT_
IMPORTANCE_ SOLUTION - DEFAULT_
IMPORTANCE_ STRUCTURE - DEFAULT_
IMPORTANCE_ TECH - DEFAULT_
MEMORY_ EXTRACTOR_ MODEL - Default model for cost-effective memory extraction.
- IGNORE_
DIRS - IMPORTANCE_
STAR_ THRESHOLD - Importance threshold for displaying star marker (⭐).
- MAX_
DETECTED_ ENTRIES - Maximum entries to return from detection (to avoid overwhelming).
- MAX_
DISPLAY_ LENGTH - Maximum length for display (shorter for terminal readability).
- MAX_
IMPORTANCE_ CEILING - Maximum importance score ceiling (entries cannot exceed this).
- MAX_
MEMORY_ CONTENT_ LENGTH - Maximum length for memory content before truncation.
- MERGE_
SIMILARITY_ THRESHOLD - Similarity threshold for merging similar memories (0.0-1.0). Lower than duplicate threshold to allow semantic merging.
- MIN_
KEYWORDS_ FOR_ AI_ FALLBACK - Minimum keywords threshold for triggering AI fallback. If rule-based extraction produces fewer keywords than this, AI is used.
- MIN_
MEMORY_ CONTENT_ LENGTH - Minimum content length for memory detection (to avoid capturing too generic content). Increased to 20 to filter out short fragments.
- MIN_
SIMILARITY_ LENGTH - Minimum content length for similarity check (to avoid short words matching everything).
- PROJECT_
TYPE_ CONFIGS - SEMANTIC_
ALIASES_ DEFAULT - Default semantic aliases (embedded for fallback).
- SIMILARITY_
THRESHOLD - Similarity threshold for considering entries as duplicates (0.0-1.0). Higher value (0.85) reduces duplicate detection false negatives.
Traits§
- Memory
Extractor - Trait for memory extraction implementations.
Functions§
- apply_
behavior_ inferences_ to_ memory - Apply behavior inferences to memory.
- apply_
feedback_ to_ memory - Apply feedback to memory.
- apply_
tool_ learning_ to_ memory - Generic tool learning - let model decide what to remember. This is a placeholder for future AI-driven learning.
- calculate_
similarity - Calculate word-based similarity between two strings (Jaccard coefficient).
- compute_
relevance - Compute relevance score of a memory entry to context keywords. Returns 0.0-1.0 where 1.0 means highly relevant.
- detect_
feedback_ patterns - Detect user feedback patterns - generic detection, not exhaustive. The model should use its understanding to detect nuances.
- detect_
memories_ fallback - Detect memories from text using configurable patterns.
- detect_
memories_ from_ text - Detect memories from text (wrapper for fallback).
- detect_
memories_ smart - Smart detection: AI-first with rule-based fallback.
- expand_
semantic_ keywords - Expand keywords with semantic aliases from KeywordsConfig.
- extract_
context_ keywords - Extract meaningful keywords from conversation context. Uses KeywordsConfig for stop words and tech keywords.
- extract_
keywords_ hybrid - Extract keywords using hybrid approach (rule-based + AI fallback).
- generate_
project_ structure_ memories - Generate project structure memories and save.
- get_
default_ keywords - Get embedded default keywords configuration.
- get_
semantic_ aliases - Get semantic aliases from KeywordsConfig.
- has_
contradiction_ signal - Detect if two memory contents have contradiction signals. Uses KeywordsConfig for contradiction signals.
- infer_
category_ from_ content - Infer category from content.
- infer_
preferences_ from_ behavior - Infer patterns from behavior - generic word frequency analysis. Let the model decide what’s meaningful, not hardcoded tech patterns.
- inference_
to_ memory_ entry - Convert inference to memory entry.