Skip to main content
AsyncMemory gives you the full OMP verb set — add, search, context, list, update, delete, audit, and capabilities — as coroutines. It is a drop-in async counterpart to Memory: method names, parameters, and error semantics are identical; the only difference is that every call is awaitable. Use AsyncMemory in any application that runs an event loop, including FastAPI, aiohttp, and scripts driven by asyncio.run.

Install

AsyncMemory is not included in the default openmem install. Add the [async] extra:

Basic usage

Use async with to open a connection, run your operations, and release resources automatically when the block exits.

Context manager vs. manual lifecycle

The async with form is preferred. It guarantees close() is called even when an exception occurs, and it binds the instance to the current event loop at entry time, which makes cross-loop misuse detectable early.

Provider async implementation

Different providers use different async strategies under the hood. The behavior visible to your application is the same, but cancellation semantics vary.

Cancellation behavior

For Postgres and passthrough, cancellation propagates within 50 ms and the connection pool is reclaimed. For mem0, Supermemory, and Letta, the event loop returns to the awaiter immediately, but the underlying thread continues running until the HTTP request completes. The backend may have observable side-effects.

FastAPI integration

AsyncMemory is a natural fit for FastAPI dependency injection. Create a new instance per request using a dependency so each request gets a properly scoped connection.
For higher throughput, consider constructing a single AsyncMemory instance in a lifespan context and sharing it across requests — Postgres and passthrough manage an internal connection pool, so concurrent requests are safe.

Event loop binding

AsyncMemory is bound to the event loop it was first used on. Do not share a single instance across multiple threads or across multiple asyncio.run() calls. If you do, the SDK raises RuntimeError: AsyncMemory is bound to a different event loop before any backend call is made. Construct a new AsyncMemory instance for each loop.