## AsyncMemoryClient

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
import os
from mem0 import AsyncMemoryClient

os.environ["MEM0_API_KEY"] = "your-api-key"

client = AsyncMemoryClient()
```

### JavaScript

```javascript
const { MemoryClient } = require('mem0ai');
const client = new MemoryClient({ apiKey: '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, { userId: "alice" });
```

### Search

Search for memories based on a query asynchronously.

#### Python

```python
await client.search("What is Alice's favorite sport?", filters={"user_id": "alice"})
```

#### JavaScript

```javascript
await client.search("What is Alice's favorite sport?", { filters: { userId: "alice" } });
```

### Get All

Retrieve all memories for a user asynchronously.

`get_all()` now requires filters to be specified.

#### Python

```python
await client.get_all(filters={"AND": [{"user_id": "alice"}]})
```

#### JavaScript

```javascript
await client.getAll({ filters: {"AND": [{"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({ userId: "alice" });
```

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 `"*"`.

### 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.
