# Long-Term Memory System Stores persistent facts about the user, their preferences, routines, and important information. ## Features - **Persistent Storage**: SQLite database for long-term storage - **Categories**: Personal, family, preferences, routines, facts - **Confidence Scoring**: Track certainty of each fact - **Source Tracking**: Know where facts came from (explicit, inferred, confirmed) - **Fast Retrieval**: Indexed lookups and search - **Prompt Integration**: Format memory for LLM prompts ## Usage ```python from memory.manager import get_memory_manager from memory.schema import MemoryCategory, MemorySource manager = get_memory_manager() # Store explicit fact manager.store_fact( category=MemoryCategory.PREFERENCES, key="favorite_color", value="blue", confidence=1.0, source=MemorySource.EXPLICIT ) # Store inferred fact manager.store_fact( category=MemoryCategory.ROUTINES, key="morning_routine", value="coffee at 7am", confidence=0.8, source=MemorySource.INFERRED, context="Mentioned in conversation on 2024-01-06" ) # Get fact fact = manager.get_fact(MemoryCategory.PREFERENCES, "favorite_color") if fact: print(f"Favorite color: {fact.value}") # Search facts facts = manager.search_facts("coffee", category=MemoryCategory.ROUTINES) # Format for LLM prompt memory_text = manager.format_for_prompt() # Use in system prompt: "## User Memory\n{memory_text}" ``` ## Categories - **PERSONAL**: Personal facts (name, age, location) - **FAMILY**: Family member information - **PREFERENCES**: User preferences (favorite foods, colors) - **ROUTINES**: Daily/weekly routines - **FACTS**: General facts about the user ## Memory Write Policy ### Explicit Facts (confidence: 1.0) - User explicitly states: "My favorite color is blue" - Source: `MemorySource.EXPLICIT` ### Inferred Facts (confidence: 0.7-0.9) - Inferred from conversation: "I always have coffee at 7am" - Source: `MemorySource.INFERRED` ### Confirmed Facts (confidence: 0.9-1.0) - User confirms inferred fact - Source: `MemorySource.CONFIRMED` ## Integration with LLM Memory is formatted and injected into system prompts: ```python memory_text = manager.format_for_prompt(limit=20) system_prompt = f""" You are a helpful assistant. ## User Memory {memory_text} Use this information to provide personalized responses. """ ``` ## Storage - **Database**: `data/memory.db` (SQLite) - **Schema**: See `memory/schema.py` - **Indexes**: Category, key, last_accessed for fast queries ## Future Enhancements - Semantic search using embeddings - Memory summarization - Confidence decay over time - Conflict resolution for conflicting facts - Memory validation and cleanup