5.2 KiB
5.2 KiB
Memory System Architecture
Overview
The memory system architecture is designed with a layered approach, separating concerns between:
- Storage layer
- Memory integration layer
- Assistant layer (LLM integration)
This modular design allows for flexibility, extensibility, and ease of maintenance.
System Layers
┌────────────────────────────────────────────────────┐
│ │
│ ┌────────────────────────────────────────────┐ │
│ │ OllamaMemoryAssistant │ │
│ │ │ │
│ │ - User interface for memory interaction │ │
│ │ - LLM integration via Ollama │ │
│ │ - Query processing with context │ │
│ └────────────────────┬───────────────────────┘ │
│ │ │
│ ┌────────────────────▼───────────────────────┐ │
│ │ IntegratedMemory │ │
│ │ │ │
│ │ - Combines memory types │ │
│ │ - Manages context generation │ │
│ │ - Coordinates memory operations │ │
│ └────────────────────┬───────────────────────┘ │
│ │ │
│ ┌────────────────────▼───────────────────────┐ │
│ │ SimpleMemoryStore │ │
│ │ │ │
│ │ - Basic storage implementation │ │
│ │ - Persistence with JSON files │ │
│ │ - Namespaced key-value storage │ │
│ └────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────┘
Key Components
1. SimpleMemoryStore
The foundation of the system, providing basic storage capabilities:
-
Responsibilities:
- Store and retrieve data by namespace and key
- Provide basic search functionality
- Handle persistence to disk (optional)
- Manage file I/O for memory files
-
Key Methods:
put(namespace, key, value): Store dataget(namespace, key): Retrieve datasearch(namespace, query): Find relevant informationsave()andload(): Handle persistence
2. IntegratedMemory
The integration layer that combines different memory types:
-
Responsibilities:
- Provide typed access to memory (semantic, episodic, procedural)
- Generate context for LLM queries
- Manage memory-specific operations
- Coordinate between memory types
-
Key Methods:
add_fact(concept, details): Add semantic memoryadd_procedure(name, steps): Add procedural memoryadd_interaction(query, response): Add episodic memorygenerate_context(query): Create LLM context from memories
3. OllamaMemoryAssistant
The application layer that interfaces with Ollama LLM:
-
Responsibilities:
- Process user queries with memory context
- Send requests to Ollama API
- Update memory with new interactions
- Present responses to the user
-
Key Methods:
process_query(query): Process a query with memory contextlearn_fact(concept, details): Add to semantic memorylearn_procedure(name, steps): Add to procedural memory
Data Flow
-
Query Processing:
User Query → OllamaMemoryAssistant → IntegratedMemory (context) → Ollama API → Response -
Memory Addition:
New Knowledge → OllamaMemoryAssistant → IntegratedMemory → SimpleMemoryStore -
Persistence:
Memory Update → SimpleMemoryStore → JSON File
Extensibility
The system architecture allows for several extension points:
- Storage Backends: Replace SimpleMemoryStore with other implementations (e.g., database, vector store)
- LLM Integration: Swap Ollama with other LLM providers
- Memory Types: Add new memory types beyond the current three
- Context Generation: Customize how context is generated for different query types
Configuration Options
- Persistence: Enable/disable memory persistence
- Memory Directory: Configure where memory files are stored
- Model Selection: Choose which LLM model to use via Ollama
- Base URL: Configure the Ollama API endpoint