repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: Async Client |
| #3 | description: 'Asynchronous client for Mem0' |
| #4 | --- |
| #5 | |
| #6 | 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. |
| #7 | |
| #8 | ## Initialization |
| #9 | |
| #10 | To use the async client, you first need to initialize it: |
| #11 | |
| #12 | <CodeGroup> |
| #13 | |
| #14 | ```python Python |
| #15 | import os |
| #16 | from mem0 import AsyncMemoryClient |
| #17 | |
| #18 | os.environ["MEM0_API_KEY"] = "your-api-key" |
| #19 | |
| #20 | client = AsyncMemoryClient() |
| #21 | ``` |
| #22 | |
| #23 | ```javascript JavaScript |
| #24 | const { MemoryClient } = require('mem0ai'); |
| #25 | const client = new MemoryClient({ apiKey: 'your-api-key'}); |
| #26 | ``` |
| #27 | |
| #28 | </CodeGroup> |
| #29 | |
| #30 | ## Methods |
| #31 | |
| #32 | The `AsyncMemoryClient` provides the following methods: |
| #33 | |
| #34 | ### Add |
| #35 | |
| #36 | Add a new memory asynchronously. |
| #37 | |
| #38 | <CodeGroup> |
| #39 | |
| #40 | ```python Python |
| #41 | messages = [ |
| #42 | {"role": "user", "content": "Alice loves playing badminton"}, |
| #43 | {"role": "assistant", "content": "That's great! Alice is a fitness freak"}, |
| #44 | ] |
| #45 | await client.add(messages, user_id="alice") |
| #46 | ``` |
| #47 | |
| #48 | ```javascript JavaScript |
| #49 | const messages = [ |
| #50 | {"role": "user", "content": "Alice loves playing badminton"}, |
| #51 | {"role": "assistant", "content": "That's great! Alice is a fitness freak"}, |
| #52 | ]; |
| #53 | await client.add(messages, { user_id: "alice" }); |
| #54 | ``` |
| #55 | |
| #56 | </CodeGroup> |
| #57 | |
| #58 | ### Search |
| #59 | |
| #60 | Search for memories based on a query asynchronously. |
| #61 | |
| #62 | <CodeGroup> |
| #63 | |
| #64 | ```python Python |
| #65 | await client.search("What is Alice's favorite sport?", user_id="alice") |
| #66 | ``` |
| #67 | |
| #68 | ```javascript JavaScript |
| #69 | await client.search("What is Alice's favorite sport?", { user_id: "alice" }); |
| #70 | ``` |
| #71 | |
| #72 | </CodeGroup> |
| #73 | |
| #74 | ### Get All |
| #75 | |
| #76 | Retrieve all memories for a user asynchronously. |
| #77 | |
| #78 | <Callout type="warning" title="Filters Required"> |
| #79 | `get_all()` now requires filters to be specified. |
| #80 | </Callout> |
| #81 | |
| #82 | <CodeGroup> |
| #83 | |
| #84 | ```python Python |
| #85 | await client.get_all(filters={"AND": [{"user_id": "alice"}]}) |
| #86 | ``` |
| #87 | |
| #88 | ```javascript JavaScript |
| #89 | await client.getAll({ filters: {"AND": [{"user_id": "alice"}]} }); |
| #90 | ``` |
| #91 | |
| #92 | </CodeGroup> |
| #93 | |
| #94 | ### Delete |
| #95 | |
| #96 | Delete a specific memory asynchronously. |
| #97 | |
| #98 | <CodeGroup> |
| #99 | |
| #100 | ```python Python |
| #101 | await client.delete(memory_id="memory-id-here") |
| #102 | ``` |
| #103 | |
| #104 | ```javascript JavaScript |
| #105 | await client.delete("memory-id-here"); |
| #106 | ``` |
| #107 | |
| #108 | </CodeGroup> |
| #109 | |
| #110 | ### Delete All |
| #111 | |
| #112 | Delete all memories for a user asynchronously. |
| #113 | |
| #114 | <CodeGroup> |
| #115 | |
| #116 | ```python Python |
| #117 | await client.delete_all(user_id="alice") |
| #118 | ``` |
| #119 | |
| #120 | ```javascript JavaScript |
| #121 | await client.deleteAll({ user_id: "alice" }); |
| #122 | ``` |
| #123 | |
| #124 | </CodeGroup> |
| #125 | |
| #126 | <Note> |
| #127 | At least one filter (`user_id`, `agent_id`, `app_id`, or `run_id`) is required — calling `delete_all` with no filters raises an error to prevent accidental data loss. You can pass `"*"` as a value to delete all memories for a given entity type (e.g., `user_id="*"` removes memories for every user). A full project wipe requires all four filters set to `"*"`. |
| #128 | </Note> |
| #129 | |
| #130 | ### History |
| #131 | |
| #132 | Get the history of a specific memory asynchronously. |
| #133 | |
| #134 | <CodeGroup> |
| #135 | |
| #136 | ```python Python |
| #137 | await client.history(memory_id="memory-id-here") |
| #138 | ``` |
| #139 | |
| #140 | ```javascript JavaScript |
| #141 | await client.history("memory-id-here"); |
| #142 | ``` |
| #143 | |
| #144 | </CodeGroup> |
| #145 | |
| #146 | ### Users |
| #147 | |
| #148 | Get all users, agents, and runs which have memories associated with them asynchronously. |
| #149 | |
| #150 | <CodeGroup> |
| #151 | |
| #152 | ```python Python |
| #153 | await client.users() |
| #154 | ``` |
| #155 | |
| #156 | ```javascript JavaScript |
| #157 | await client.users(); |
| #158 | ``` |
| #159 | |
| #160 | </CodeGroup> |
| #161 | |
| #162 | ### Reset |
| #163 | |
| #164 | Reset the client, deleting all users and memories asynchronously. |
| #165 | |
| #166 | <CodeGroup> |
| #167 | |
| #168 | ```python Python |
| #169 | await client.reset() |
| #170 | ``` |
| #171 | |
| #172 | ```javascript JavaScript |
| #173 | await client.reset(); |
| #174 | ``` |
| #175 | |
| #176 | </CodeGroup> |
| #177 | |
| #178 | ## Conclusion |
| #179 | |
| #180 | 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. |
| #181 | |
| #182 | If you have any questions or need further assistance, please don't hesitate to reach out: |
| #183 | |
| #184 | <Snippet file="get-help.mdx" /> |
| #185 |