title | description |
---|---|
Async Client |
Asynchronous client for Mem0 |
The AsyncMemoryClient
is an asynchronous client for interacting with the Mem0 API. It provides similar functionality to the synchronous MemoryClient
but allows for non-blocking operations, which can be beneficial in applications that require high concurrency.
To use the async client, you first need to initialize it:
from mem0 import AsyncMemoryClient
client = AsyncMemoryClient(api_key="your-api-key")
const { MemoryClient } = require('mem0ai');
const client = new MemoryClient('your-api-key');
The AsyncMemoryClient
provides the following methods:
Add a new memory asynchronously.
messages = [
{"role": "user", "content": "Alice loves playing badminton"},
{"role": "assistant", "content": "That's great! Alice is a fitness freak"},
]
await client.add(messages, user_id="alice")
const messages = [
{"role": "user", "content": "Alice loves playing badminton"},
{"role": "assistant", "content": "That's great! Alice is a fitness freak"},
];
await client.add(messages, { user_id: "alice" });
Search for memories based on a query asynchronously.
await client.search(query="What is Alice's favorite sport?", user_id="alice")
await client.search("What is Alice's favorite sport?", { user_id: "alice" });
Retrieve all memories for a user asynchronously.
await client.get_all(user_id="alice")
await client.getAll({ user_id: "alice" });
Delete a specific memory asynchronously.
await client.delete(memory_id="memory-id-here")
await client.delete("memory-id-here");
Delete all memories for a user asynchronously.
await client.delete_all(user_id="alice")
await client.deleteAll({ user_id: "alice" });
Get the history of a specific memory asynchronously.
await client.history(memory_id="memory-id-here")
await client.history("memory-id-here");
Get all users, agents, and runs which have memories associated with them asynchronously.
await client.users()
await client.users();
Reset the client, deleting all users and memories asynchronously.
await client.reset()
await client.reset();
The AsyncMemoryClient
provides a powerful way to interact with the Mem0 API asynchronously, allowing for more efficient and responsive applications. By using this client, you can perform memory operations without blocking your application's execution.
If you have any questions or need further assistance, please don't hesitate to reach out: