> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Mem0

> Set up the Mem0 Memory resource in Python.

## Dependencies

The Mem0 resource needs the `mem0` extra, which installs the `mem0ai` SDK:

```bash theme={null}
uv add "mirage-ai[mem0]"
```

For credential setup, see the [Mem0 Setup](/home/setup/mem0) guide.

## Configuration

```python theme={null}
import os

from mirage import MountMode, Workspace
from mirage.resource.mem0 import Mem0Config, Mem0Resource

config = Mem0Config(
    api_key=os.environ["MEM0_API_KEY"],
    user_id=os.environ.get("MEM0_USER_ID"),
)
resource = Mem0Resource(config=config)
ws = Workspace({"/memory/": resource}, mode=MountMode.READ)
```

Set exactly one of `user_id`, `agent_id`, or `run_id`. Providing zero or more
than one raises a validation error.

## Config Reference

| Field                  | Required | Default               | Description                                 |
| ---------------------- | -------- | --------------------- | ------------------------------------------- |
| `api_key`              | Yes      |                       | Mem0 API key (`m0-...`)                     |
| `host`                 | No       | `https://api.mem0.ai` | Mem0 API base URL                           |
| `user_id`              | One of   |                       | Scope the mount to a user's memories        |
| `agent_id`             | One of   |                       | Scope the mount to an agent's memories      |
| `run_id`               | One of   |                       | Scope the mount to a run/session's memories |
| `default_page_size`    | No       | `100`                 | Page size used when listing memories        |
| `default_search_limit` | No       | `10`                  | Default `top-k` for `search`                |
