aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/migration/from-mem0.mdx
blob: e218c592621a36ae210ef4f705c25ae169b575bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
---
title: "Migrating from Mem0.ai to Supermemory"
description: "Complete guide to migrate your data and applications from Mem0.ai to Supermemory"
sidebarTitle: "From Mem0"
---

Migrating from Mem0.ai to Supermemory is straightforward. This guide walks you through exporting your memories from Mem0 and importing them into Supermemory.

## Why Migrate to Supermemory?

Supermemory offers enhanced capabilities over Mem0.ai:
- **Memory Router** for zero-code LLM integration
- **Knowledge graph** architecture for better context relationships
- **Multiple content types** (URLs, PDFs, images, videos)
- **Generous free tier** (100k tokens) with affordable pricing
- **Multiple integration options** (API, Router, MCP, SDKs)

## Quick Migration (All-in-One)

Complete migration in one script:

```python
from mem0 import MemoryClient
from supermemory import Supermemory
import json, time

# Export from Mem0
mem0 = MemoryClient(api_key="your_mem0_api_key")
export = mem0.create_memory_export(
    schema={"type": "object", "properties": {"memories": {"type": "array", "items": {"type": "object"}}}},
    filters={}
)
time.sleep(5)
data = mem0.get_memory_export(memory_export_id=export["id"])

# Import to Supermemory
supermemory = Supermemory(api_key="your_supermemory_api_key")
for memory in data["memories"]:
    if memory.get("content"):
        supermemory.memories.add(
            content=memory["content"],
            container_tags=["imported_from_mem0"]
        )
        print(f"✅ {memory['content'][:50]}...")

print("Migration complete!")
```

## Step-by-Step Migration

<Steps>
  <Step title="Export from Mem0.ai">
    Mem0 provides two ways to export your memories:

    ### Option 1: Export via Dashboard (Recommended)
    1. Log into your [Mem0 dashboard](https://app.mem0.ai)
    2. Navigate to the export section
    3. Download your memories as JSON

    ### Option 2: Export via API

    Simple script to export all your memories from Mem0:

    ```python
    from mem0 import MemoryClient
    import json
    import time

    # Connect to Mem0
    client = MemoryClient(api_key="your_mem0_api_key")

    # Create export job
    schema = {
        "type": "object",
        "properties": {
            "memories": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "id": {"type": "string"},
                        "content": {"type": "string"},
                        "metadata": {"type": "object"},
                        "created_at": {"type": "string"}
                    }
                }
            }
        }
    }

    response = client.create_memory_export(schema=schema, filters={})
    export_id = response["id"]

    # Wait and retrieve
    print("Exporting memories...")
    time.sleep(5)
    export_data = client.get_memory_export(memory_export_id=export_id)

    # Save to file
    with open("mem0_export.json", "w") as f:
        json.dump(export_data, f, indent=2)

    print(f"Exported {len(export_data['memories'])} memories")
    ```
  </Step>

  <Step title="Set Up Supermemory">
    Create your Supermemory account and get your API key:

    1. Sign up at [console.supermemory.ai](https://console.supermemory.ai)
    2. Create a new project
    3. Generate an API key from the dashboard

    ```bash
    # Set your environment variable
    export SUPERMEMORY_API_KEY="your_supermemory_api_key"
    ```
  </Step>

  <Step title="Import to Supermemory">
    Simple script to import your Mem0 memories into Supermemory:

    ```python
    import json
    from supermemory import Supermemory

    # Load your Mem0 export
    with open("mem0_export.json", "r") as f:
        mem0_data = json.load(f)

    # Connect to Supermemory
    client = Supermemory(api_key="your_supermemory_api_key")

    # Import memories
    for memory in mem0_data["memories"]:
        content = memory.get("content", "")

        # Skip empty memories
        if not content:
            continue

        # Import to Supermemory
        try:
            result = client.memories.add(
                content=content,
                container_tags=["imported_from_mem0"],
                metadata={
                    "source": "mem0",
                    "created_at": memory.get("created_at"),
                    **(memory.get("metadata") or {})
                }
            )
            print(f"Imported: {content[:50]}...")
        except Exception as e:
            print(f"Failed: {e}")

    print("Migration complete!")
    ```
  </Step>
</Steps>

## API Migration Reference

Here's how common Mem0.ai operations map to Supermemory:

### Adding Memories

<CodeGroup>

```python Mem0.ai
from mem0 import MemoryClient

client = MemoryClient(api_key="...")
client.add(
    messages="User prefers dark mode",
    user_id="alice"
)
```

```python Supermemory
from supermemory import Supermemory

client = Supermemory(api_key="...")
client.memories.add(
    content="User prefers dark mode",
    container_tags=["user_alice"]
)
```

</CodeGroup>

### Searching Memories

<CodeGroup>

```python Mem0.ai
results = client.search(
    query="user preferences",
    user_id="alice"
)
```

```python Supermemory
results = client.memories.search(
    query="user preferences",
    container_tags=["user_alice"]
)
```

</CodeGroup>

### Getting All Memories

<CodeGroup>

```python Mem0.ai
memories = client.get_all(
    user_id="alice"
)
```

```python Supermemory
memories = client.memories.list(
    container_tags=["user_alice"],
    limit=100
)
```

</CodeGroup>

### Deleting Memories

<CodeGroup>

```python Mem0.ai
client.delete(memory_id="mem_123")
```

```python Supermemory
client.memories.delete("mem_123")
```

</CodeGroup>

## Using Memory Router (Easiest Migration)

For the simplest migration path, use Supermemory's Memory Router which requires minimal code changes:

<CodeGroup>

```python Before (Mem0 + OpenAI)
from openai import OpenAI
from mem0 import MemoryClient

# Two separate clients needed
openai = OpenAI(api_key="sk-...")
memory = MemoryClient(api_key="mem0_key")

# Manual memory management
context = memory.search("user preferences", user_id="alice")
messages = [
    {"role": "system", "content": f"Context: {context}"},
    {"role": "user", "content": "What are my preferences?"}
]

response = openai.chat.completions.create(
    model="gpt-5",
    messages=messages
)
```

```python After (Supermemory Router)
from openai import OpenAI

# Single client with automatic memory management
client = OpenAI(
    api_key="sk-...",
    base_url="https://api.supermemory.ai/v3/https://api.openai.com/v1",
    default_headers={
        "x-supermemory-api-key": "your_supermemory_key",
        "x-supermemory-user-id": "alice"
    }
)

# Memories handled automatically!
response = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "What are my preferences?"}]
)
```

</CodeGroup>

<Note>
For enterprise migrations, [contact us](mailto:[email protected]) for assistance.
</Note>

## Next Steps

1. [Explore](/how-it-works) how Supermemory works
2. Read the [quickstart](/quickstart) and add and retrieve your first memories
3. [Connect](/connectors/overview) to Google Drive, Notion, and OneDrive with automatic syncing