Memory class is the synchronous OMP client. You instantiate it once with a provider string and any provider-specific configuration, then call its methods — add, search, get, update, delete, list, context, audit, and capabilities — the same way regardless of which backend is underneath. Swapping providers requires only changing the constructor arguments; all method calls remain identical.
Constructor
provider argument is a string that selects the backend adapter. The remaining keyword arguments are forwarded directly to that adapter.
string
default:"postgres"
required
Selects the memory backend. Accepted values:
"postgres", "mem0", "supermemory", "letta". Pass base_url= pointing to any OMP-native HTTP server and the SDK will auto-detect it as a passthrough provider regardless of this string.**config keyword arguments depend on which provider you choose:
postgres
postgres
string
required
PostgreSQL connection string, e.g.
"postgresql://localhost/omp". Also accepted as dsn=.object
An embedder instance. Defaults to a lightweight offline embedder that uses zero vectors — suitable for testing without an OpenAI key. Pass
use_openai=True to use OpenAI embeddings instead, or supply a custom embedder object.boolean
default:"false"
When
True and no embedder= is supplied, initializes an OpenAIEmbedder automatically.mem0
mem0
supermemory
supermemory
Methods
add()
Store a new memory for a user.string
required
The text content of the memory. Must be a non-empty string.
string
required
Identifies the user this memory belongs to. All subsequent reads and searches are scoped to this user.
string
Slash-delimited hierarchy that organizes the memory, e.g.
"coding/preferences" or "health/symptoms". Scopes enable fine-grained consent and filtering.string[]
Free-form labels for filtering, e.g.
["tooling", "nodejs"]. Supported by all providers; used as a fallback for scopes on providers where features.scopes == "tags".MemorySource | dict
Origin information for the memory. Accepts a
MemorySource instance or a plain dict with app, type, and/or ref keys. See MemorySource.number
A float between
0 and 1 indicating confidence in this memory. Higher values indicate higher certainty.datetime
ISO 8601 datetime at which this memory becomes valid.
None means immediately.datetime
ISO 8601 datetime at which this memory expires.
None means no expiry.string[]
A list of memory IDs that this new memory replaces. The referenced memories are retained but semantically superseded.
MemoryRecord containing the provider-assigned id and all stored fields.
search()
Find memories semantically relevant to a query string.string
required
The natural-language query to search against stored memories.
string
required
Restricts results to memories belonging to this user.
string
Restrict results to memories under this scope prefix, e.g.
"coding/*".number
default:"10"
Maximum number of results to return. Subject to the provider’s
limits.max_search_results cap.number
Minimum similarity score (0..1) for a result to be included. Omit to return the top
limit results regardless of score.SearchResult objects, each containing a memory and a score.
get()
Fetch a single memory by its provider-assigned ID.string
required
The provider-assigned memory ID, e.g.
"mem_abc123".MemoryRecord. Raises NotFoundError if the ID does not exist.
update()
Partially update a memory’s fields. Only the fields you provide are changed.string
required
The ID of the memory to update.
string
Replacement text content.
string
New scope path to move the memory to.
string[]
Replacement tag list. Replaces all existing tags.
number
Updated confidence score (0..1).
datetime
New expiry datetime.
string[]
Additional IDs of memories superseded by this one.
MemoryRecord.
delete()
Permanently delete a memory.string
required
The ID of the memory to delete.
None on success. Raises NotFoundError if the ID does not exist.
list()
List memories for a user, optionally filtered by scope, tag, or time range. Results are paginated.string
required
The user whose memories to list.
string
Filter to memories under this scope prefix.
string
Filter to memories with this exact tag.
datetime
Return only memories created at or after this datetime.
datetime
Return only memories created before this datetime.
number
default:"50"
Maximum number of records per page.
string
Opaque pagination cursor from a previous
MemoryPage.next_cursor. Pass None to start from the beginning.MemoryPage. When next_cursor on the result is non-None, pass it back as cursor= to fetch the next page.
context()
Retrieve a pre-ranked, prompt-ready text block for injecting into an LLM prompt.string
required
The user’s current query or intent used to rank memories for relevance.
string
required
The user whose memories to draw from.
string
Restrict context retrieval to memories under this scope.
number
default:"500"
Approximate maximum number of tokens for the returned
text. The provider fits as many high-scoring memories as possible within this budget.ContextBlock with a text field ready for prompt injection, citations linking back to source memories, and an optional token_count.
audit()
Retrieve the audit log of operations performed on a user’s memories.Audit log support depends on the provider. Check
caps.features.supports_audit before calling this method.string
required
The user whose audit log to retrieve.
string
Filter to entries originating from this app name.
datetime
Return only entries at or after this datetime.
number
default:"100"
Maximum number of entries to return.
AuditEntry objects, each describing a single operation.
capabilities()
Retrieve the provider’s declared capabilities.Capabilities object describing which verbs and features the provider supports. The result is cached for the lifetime of the Memory instance — the network call is made at most once per session.
Use this to conditionally enable features at runtime:
Full example
AsyncMemory has identical method signatures to Memory, but every method is a coroutine and must be awaited. See AsyncMemory.