The memory store lets agents retain user preferences and history across sessions.
Overview
LLMs are limited by context windows and cannot retain information across sessions. The memory store automatically extracts key information from conversations and persists it. In subsequent conversations, relevant memories are retrieved via semantic search and injected into the context, enabling agents to continuously understand user preferences and historical information. The memory store provides open API interfaces that can be integrated into any application and supports multiple applications sharing the same memory store.
Two types of memory content are supported:
- Memory segments: Key events and information automatically extracted from conversations, such as "user needs a water reminder at 9 AM every morning." Suitable for most long-term memory scenarios.
- User profiles: Structured attributes extracted from conversations based on custom templates, such as age, occupation, and preferences. Suitable for scenarios requiring fixed attributes.
- Obtain an API Key, then create or use the default memory store.
- After each conversation turn, call AddMemory to write the memory.
- View and search memories in the console, or call SearchMemory to search within your application.
- Inject the retrieved results into the prompt to enable personalized responses.
Quick Start
The following example uses the default memory store and demonstrates writing, viewing, and searching memories in 3 steps. To customize memory rules, see Configure Memory Rules.
Step 1: Write Memory
Call the AddMemory API to store the conversation into the memory store. Before calling, configure DASHSCOPE_API_KEY; see the API Key page for how to obtain one. Replace {workspaceId} in the request URL with your actual workspace ID, and use an API key that belongs to the same workspace.
cURL
Step 2: View Memory in the Console
Go to the Memory Store Management page. Click the target memory store name to enter the details page, then click the Memory tab to view and search all memory segments for the current user.
Step 3: Search Memory via API
Call SearchMemory to semantically search relevant historical memories. It is recommended to set top_k between 3 and 10.
Configure Memory Rules
Creating a Memory Store
Click Create Memory Store on the Memory Store Management page. Each memory store can contain multiple memory segments; one memory store can be shared by multiple applications.
Memory Segments and User Profiles
Memory segments are automatically extracted key information, stored as structured memory entries. Write via AddMemory; search via SearchMemory.
User profiles extract structured attributes (age, occupation, interests, etc.) based on profile templates. Configure on the memory store details page under the Memory Rules tab.
Memory segments apply to most long-term memory scenarios. When fixed attribute extraction is needed, use user profiles in combination with memory segments.