Configuring User Memory
You can define the structure of user profiles by configuring topics and sub-topics in yourconfig.yaml file. This tells Memobase what kind of information to track.
Integrating Memory into Prompts
There are two primary ways to retrieve and use a user’s memory.Method 1: Profile API (Manual Assembly)
The Profile API returns a structured JSON object containing the user’s profile data. You are responsible for formatting this JSON into a string and inserting it into your prompt. Key Considerations:- Context Length: Control the token count of the memory context to manage cost and performance. Use max_token_sizeto set a hard limit andmax_subtopic_sizeto limit the number of sub-topics per topic.
- Topic Filtering: Use only_topicsto retrieve specific profile sections orprefer_topicsto prioritize the most important information.
Method 2: Context API (Automated Assembly)
The Context API returns a pre-formatted string containing both the user’s profile and recent events, ready to be injected directly into your system prompt. It uses a template like this:Flushing the Memory Buffer
Memobase uses a buffer to collect user interactions. Aflush operation processes this buffer and updates the long-term memory. Flushing occurs automatically when:
- The buffer exceeds a certain size.
- The buffer has been idle for a set period.
flush API. It is best practice to call flush at the end of a user session or conversation.
User ID Management
A single user in your application can correspond to multiple Memobase users. This is useful for creating segmented memories.- Example: AI Role-Playing: If a user interacts with multiple AI agents (e.g., a history tutor and a creative writer), you can create a separate Memobase user for each agent. This keeps the memories for each role distinct.
Enriching Conversation Data
You can add metadata to the messages you insert to provide more context for memory extraction.- Speaker Alias: Use aliasto specify the name of the AI assistant in the conversation.
- Timestamps: Provide a created_attimestamp for each message so Memobase can build a timeline of events.