Memory System¶
Location: cogs/memory/
The Memory System is a sophisticated, persistent long-term memory feature for the bot. It automatically captures, processes, and indexes conversations, enabling the bot to recall past interactions with high relevance and context.
Core Components¶
The system is built upon several key, interconnected components:
- Memory Manager: The central orchestrator of the entire system.
- Database: The SQLite-based persistence layer for all textual data.
- Embedding Service: Converts text into numerical vector representations.
- Search Engine: Provides hybrid search capabilities (semantic, keyword, etc.).
- Segmentation Service: Groups messages into coherent conversational segments.
- Conversation Segment Enhancer: Enhances conversation segments with additional metadata or context.
- Reranker Service: Re-ranks retrieved memories based on relevance to the current query.
- Structured Context Builder: Formats retrieved memories into a human-readable context for the LLM.
- Configuration: Configuration settings for the memory system.
Data Flow: Storing a Message¶
- A new message is sent in a channel where the memory system is active.
- The Memory Manager receives the message.
- The message content and metadata are saved to the Database.
- The message is passed to the Segmentation Service, which determines if the message concludes a conversational segment.
- Once a segment is complete, its content is sent to the Embedding Service to be converted into a vector.
- The resulting vector is stored in a specialized index file by the Vector Manager.
Data Flow: Recalling a Memory¶
- The bot needs to recall a memory (e.g., to answer a question).
- A query is sent to the Memory Manager's
search_memorymethod. - The Search Engine uses the Embedding Service to convert the query into a vector.
- The Vector Manager finds the most similar conversation segment vectors.
- The Database retrieves the corresponding text messages for those segments.
- The Structured Context Builder formats the retrieved messages and user data into a clean block of text.
- This final context is provided to the LLM to inform its response.