TheDocumentation Index
Fetch the complete documentation index at: https://docs.openmem.blog/llms.txt
Use this file to discover all available pages before exploring further.
context() method bridges your stored memories and your LLM calls. Instead of retrieving a raw list of search results and assembling them yourself, you call mem.context() with a query and a token budget, and receive back a single text blob that is already ranked by relevance, trimmed to fit your budget, and annotated with citation metadata. Prepend it to your system prompt and your model has access to the most relevant facts about the user without any extra formatting work on your end.
What context() returns
mem.context() returns a ContextBlock with three fields:
text— ranked text ready for prompt injectioncitations— list of{memory_id, score}objects for attributiontoken_count— actual tokens used (always ≤token_budget)
OpenAI integration
Passctx.text directly into the system message. Include ctx.citations if you want to surface sources to the user or log attribution data.
Storing memories from conversations
Callmem.add() after each turn to build up the memory store over time. Extract discrete facts from the conversation rather than storing full message transcripts.
Storing one fact per
add() call produces better search results than storing full conversation turns. Smaller, focused records score higher on semantic similarity and fit into tight token budgets more efficiently.Choosing a token budget
Checking provider capabilities
Not all providers support rich context ranking. Before relying on scored output, verify that the provider’sfeatures indicate support.
mem.capabilities() result is cached for the lifetime of the Memory instance, so calling it on every turn adds no latency after the first call.