- User Profile: Key-value attributes describing the user (e.g., name, location, preferences).
- User Events: Significant occurrences and interactions from the user’s history.
context()
API to retrieve this information as a structured string, ready to be injected directly into your LLM prompts.
Basic Usage
The simplest way to get a user’s context is to call thecontext()
method on a user object.
Context-Aware Retrieval
To make the retrieved context more relevant to the ongoing conversation, you can provide recent chat messages. Memobase will perform a semantic search to prioritize the most relevant historical events, rather than simply returning the most recent ones.Controlling Context Size
You can manage the size and cost of your prompts by limiting the token count of the retrieved context using themax_tokens
parameter.
max_tokens
limit applies to the profile and event content, not the final formatted string. If you use a large custom prompt template, the final output may still exceed the limit.
Advanced Filtering
Thecontext()
API offers several parameters for fine-grained control:
prefer_topics
,only_topics
: Prioritize or exclusively include certain profile topics.max_subtopic_size
: Limit the number of sub-topics returned per topic.profile_event_ratio
: Adjust the balance between profile and event information.time_range_in_days
: Filter events to a specific time window.customize_context_prompt
: Provide a custom template for the final output string.
get_context
.