The Memory System in RAGFlow provides a persistent, searchable storage layer for agentic workflows. Unlike standard conversation history, which is often ephemeral or limited by context window sizes, the Memory System treats dialogue and extracted insights as structured data. It allows agents to maintain long-term state, recall past interactions across sessions, and organize information into different cognitive categories (e.g., raw dialogue vs. semantic facts).
The memory subsystem bridges the gap between the LLM's "Natural Language Space" and the "Code Entity Space" by mapping conversation turns into vector-searchable documents stored in specialized indices. The system is implemented in both Python and Go to support the dual-backend architecture.
Title: Memory System Architecture
Sources: memory/services/messages.py25-34 api/db/joint_services/memory_message_service.py39-67 internal/service/memory.go17-35 internal/handler/memory.go39-54
RAGFlow categorizes memory into four distinct types to optimize how agents retrieve information:
When a message is processed via save_to_memory, the system uses an LLM to extract content unless the memory type is strictly RAW api/db/joint_services/memory_message_service.py39-67 Messages are stored in the document store using per-user indices named via index_name(uid) which adds a memory_ prefix memory/services/messages.py29-31 The MessageService acts as the primary interface for CRUD operations on these messages, abstracting the underlying msgStoreConn memory/services/messages.py34-69
For a deep dive into the underlying storage schemas and the extraction pipeline, see Memory Types and Storage.
Sources: api/db/joint_services/memory_message_service.py39-102 memory/services/messages.py25-69 internal/service/memory.go101-157 internal/dao/memory.go30-44
The system provides a REST API and a React-based frontend for managing these persistent states. Users can configure memory parameters, such as forgetting policies and storage types, through the UI.
Title: Memory Configuration and Storage Flow
Key management features include:
memory_api.py api/apps/restful_apis/memory_api.py30-130 and handled by MemoryHandler in Go internal/handler/memory.go82-169forgetting_policy (e.g., FIFO) and memory_size internal/service/memory.go75-86 api/apps/services/memory_api_service.py181-188get_memory_messages, including filtering by agent_ids or keywords api/apps/restful_apis/memory_api.py157-175 internal/handler/memory.go264-280temperature for extraction and defining system_prompt or user_prompt via the PromptAssembler internal/service/memory.go102-120 api/db/services/memory_service.py130-135me, team, or all via TenantPermission internal/service/memory.go49-60 api/apps/services/memory_api_service.py53-59For details on the API endpoints and frontend configuration, see Memory Management UI and API.
Sources: api/apps/restful_apis/memory_api.py30-175 internal/handler/memory.go82-280 internal/service/memory.go38-86 api/apps/services/memory_api_service.py75-188 web/src/routes.tsx26-30
The Memory System is integrated into agent workflows to provide long-term context:
AssembleSystemPrompt function generates instructions that guide the LLM in identifying semantic, episodic, or procedural information from raw dialogues internal/service/memory.go160-188 api/db/joint_services/memory_message_service.py158-171ESConnection maps message fields like message_type to message_type_kwd and content to content_ltks for optimized search memory/utils/es_conn.py38-50mapping.json to ensure memory fields like *_ltks (text) and *_vec (vectors) are correctly indexed in the document store conf/mapping.json83-201Sources: api/db/joint_services/memory_message_service.py158-195 internal/service/memory.go160-188 memory/services/messages.py151-171 conf/mapping.json83-201 memory/utils/es_conn.py38-77
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.