From aace88d2e7e284e027d2e06363941f550ce705ca Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Thu, 24 Oct 2024 16:48:57 +0530 Subject: [PATCH] Update docs for AsyncClient (#1984) --- docs/features/async-client.mdx | 172 +++++++++++++++++++++++++++++++++ docs/mint.json | 2 +- 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 docs/features/async-client.mdx diff --git a/docs/features/async-client.mdx b/docs/features/async-client.mdx new file mode 100644 index 0000000000..ceba802fd6 --- /dev/null +++ b/docs/features/async-client.mdx @@ -0,0 +1,172 @@ +--- +title: Async Client +description: '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. + +## Initialization + +To use the async client, you first need to initialize it: + + + +```python Python +from mem0 import AsyncMemoryClient +client = AsyncMemoryClient(api_key="your-api-key") +``` + +```javascript JavaScript +const { MemoryClient } = require('mem0ai'); +const client = new MemoryClient('your-api-key'); +``` + + + +## Methods + +The `AsyncMemoryClient` provides the following methods: + +### Add + +Add a new memory asynchronously. + + + +```python Python +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") +``` + +```javascript JavaScript +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 + +Search for memories based on a query asynchronously. + + + +```python Python +await client.search(query="What is Alice's favorite sport?", user_id="alice") +``` + +```javascript JavaScript +await client.search("What is Alice's favorite sport?", { user_id: "alice" }); +``` + + + +### Get All + +Retrieve all memories for a user asynchronously. + + + +```python Python +await client.get_all(user_id="alice") +``` + +```javascript JavaScript +await client.getAll({ user_id: "alice" }); +``` + + + +### Delete + +Delete a specific memory asynchronously. + + + +```python Python +await client.delete(memory_id="memory-id-here") +``` + +```javascript JavaScript +await client.delete("memory-id-here"); +``` + + + +### Delete All + +Delete all memories for a user asynchronously. + + + +```python Python +await client.delete_all(user_id="alice") +``` + +```javascript JavaScript +await client.deleteAll({ user_id: "alice" }); +``` + + + +### History + +Get the history of a specific memory asynchronously. + + + +```python Python +await client.history(memory_id="memory-id-here") +``` + +```javascript JavaScript +await client.history("memory-id-here"); +``` + + + +### Users + +Get all users, agents, and runs which have memories associated with them asynchronously. + + + +```python Python +await client.users() +``` + +```javascript JavaScript +await client.users(); +``` + + + +### Reset + +Reset the client, deleting all users and memories asynchronously. + + + +```python Python +await client.reset() +``` + +```javascript JavaScript +await client.reset(); +``` + + + +## Conclusion + +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: + + diff --git a/docs/mint.json b/docs/mint.json index 7e5e8f57ce..efb11f5b86 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -64,7 +64,7 @@ "platform/quickstart", { "group": "Features", - "pages": ["features/selective-memory", "features/custom-categories", "features/direct-import"] + "pages": ["features/selective-memory", "features/custom-categories", "features/direct-import", "features/async-client"] } ] },