Skip to main content

Module memory

Module memory 

Source
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§

AiMemoryExtractor
AI-based memory extractor using a fast/cheap model.
AutoMemory
Manager for automatic memory accumulation.
BehaviorInference
Result of behavior inference.
BehaviorInferenceConfig
Configuration for behavior inference.
FeedbackResult
Result of feedback detection.
KeywordsConfig
Keywords configuration for memory detection.
MemoryConfig
Configuration for the memory system.
MemoryEntry
A single memory entry.
MemoryFileLock
File lock for preventing concurrent access to memory storage.
MemoryStatistics
Statistics about memory collection.
MemoryStorage
Storage for memory files (global and project-level) with file locking.
ProjectStructureAnalyzer
ProjectTypeConfig
Project type detection configuration.
StopWordsConfig
Stop words configuration.
TfIdfSearch
Semantic search using TF-IDF algorithm.

Enums§

AiDetectionMode
AI memory detection mode. Controls whether AI is used for memory category detection.
AiKeywordMode
AI keyword extraction mode.
FeedbackAction
Action to take when user feedback is detected.
MemoryCategory
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§

MemoryExtractor
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. Improved: avoids meaningless character fragments.
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.