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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
---
title: API Reference Changes
description: "Comprehensive reference of all API changes between Mem0 v0.x and v1.0.0 Beta, organized by component and method."
icon: "code"
iconType: "solid"
---

## Overview

This page documents all API changes between Mem0 v0.x and v1.0.0 Beta, organized by component and method.

## Memory Class Changes

### Constructor

#### v0.x
```python
from mem0 import Memory

# Basic initialization
m = Memory()

# With configuration
config = {
    "version": "v1.0",  # Supported in v0.x
    "vector_store": {...}
}
m = Memory.from_config(config)
```

#### v1.0.0 
```python
from mem0 import Memory

# Basic initialization (same)
m = Memory()

# With configuration
config = {
    "version": "v1.1",  # v1.1+ only
    "vector_store": {...},
    # New optional features
    "reranker": {
        "provider": "cohere",
        "config": {...}
    }
}
m = Memory.from_config(config)
```

### add() Method

#### v0.x Signature
```python
def add(
    self,
    messages,
    user_id: str = None,
    agent_id: str = None,
    run_id: str = None,
    metadata: dict = None,
    filters: dict = None,
    output_format: str = None,  # ❌ REMOVED
    version: str = None         # ❌ REMOVED
) -> Union[List[dict], dict]
```

#### v1.0.0  Signature
```python
def add(
    self,
    messages,
    user_id: str = None,
    agent_id: str = None,
    run_id: str = None,
    metadata: dict = None,
    filters: dict = None,
    infer: bool = True          # βœ… NEW: Control memory inference
) -> dict  # Always returns dict with "results" key
```

#### Changes Summary

| Parameter | v0.x | v1.0.0  | Change |
|-----------|------|-----------|---------|
| `messages` | βœ… | βœ… | Unchanged |
| `user_id` | βœ… | βœ… | Unchanged |
| `agent_id` | βœ… | βœ… | Unchanged |
| `run_id` | βœ… | βœ… | Unchanged |
| `metadata` | βœ… | βœ… | Unchanged |
| `filters` | βœ… | βœ… | Unchanged |
| `output_format` | βœ… | ❌ | **REMOVED** |
| `version` | βœ… | ❌ | **REMOVED** |
| `infer` | ❌ | βœ… | **NEW** |

#### Response Format Changes

**v0.x Response (variable format):**
```python
# With output_format="v1.0"
[
    {
        "id": "mem_123",
        "memory": "User loves pizza",
        "event": "ADD"
    }
]

# With output_format="v1.1"
{
    "results": [
        {
            "id": "mem_123",
            "memory": "User loves pizza",
            "event": "ADD"
        }
    ]
}
```

**v1.0.0  Response (standardized):**
```python
# Always returns this format
{
    "results": [
        {
            "id": "mem_123",
            "memory": "User loves pizza",
            "metadata": {...},
            "event": "ADD"
        }
    ]
}
```

### search() Method

#### v0.x Signature
```python
def search(
    self,
    query: str,
    user_id: str = None,
    agent_id: str = None,
    run_id: str = None,
    limit: int = 100,
    filters: dict = None,       # Basic key-value only
    output_format: str = None,  # ❌ REMOVED
    version: str = None         # ❌ REMOVED
) -> Union[List[dict], dict]
```

#### v1.0.0  Signature
```python
def search(
    self,
    query: str,
    user_id: str = None,
    agent_id: str = None,
    run_id: str = None,
    limit: int = 100,
    filters: dict = None,       # βœ… ENHANCED: Advanced operators
    rerank: bool = True         # βœ… NEW: Reranking support
) -> dict  # Always returns dict with "results" key
```

#### Enhanced Filtering

**v0.x Filters (basic):**
```python
# Simple key-value filtering only
filters = {
    "category": "food",
    "user_id": "alice"
}
```

**v1.0.0  Filters (enhanced):**
```python
# Advanced filtering with operators
filters = {
    "AND": [
        {"category": "food"},
        {"score": {"gte": 0.8}},
        {
            "OR": [
                {"priority": "high"},
                {"urgent": True}
            ]
        }
    ]
}

# Comparison operators
filters = {
    "score": {"gt": 0.5},      # Greater than
    "priority": {"gte": 5},     # Greater than or equal
    "rating": {"lt": 3},        # Less than
    "confidence": {"lte": 0.9}, # Less than or equal
    "status": {"eq": "active"}, # Equal
    "archived": {"ne": True},   # Not equal
    "tags": {"in": ["work", "personal"]},     # In list
    "category": {"nin": ["spam", "deleted"]}  # Not in list
}
```

### get_all() Method

#### v0.x Signature
```python
def get_all(
    self,
    user_id: str = None,
    agent_id: str = None,
    run_id: str = None,
    filters: dict = None,
    output_format: str = None,  # ❌ REMOVED
    version: str = None         # ❌ REMOVED
) -> Union[List[dict], dict]
```

#### v1.0.0  Signature
```python
def get_all(
    self,
    user_id: str = None,
    agent_id: str = None,
    run_id: str = None,
    filters: dict = None        # βœ… ENHANCED: Advanced operators
) -> dict  # Always returns dict with "results" key
```

### update() Method

#### No Breaking Changes
```python
# Same signature in both versions
def update(
    self,
    memory_id: str,
    data: str
) -> dict
```

### delete() Method

#### No Breaking Changes
```python
# Same signature in both versions
def delete(
    self,
    memory_id: str
) -> dict
```

### delete_all() Method

#### Breaking Change β€” Empty filter no longer silently deletes everything

**Before:** calling `delete_all()` with no filters silently deleted **all memories in the project**.

**After:**
- No filters β†’ raises a validation error (prevents accidental full-project wipe).
- Concrete ID (e.g. `user_id="alice"`) β†’ deletes memories for that entity (unchanged).
- `"*"` for a filter β†’ deletes all memories for that entity type across the project (new).
- All four filters set to `"*"` β†’ explicit full project wipe (new, requires opt-in on every parameter).

This change replaces the silent full-project delete (triggered by an empty or missing filter) with a validation error, and introduces `"*"` wildcards as the intentional path for bulk deletion.

```python
# v0.x β€” no filter silently wiped all project memories
m.delete_all()                      # DANGER: deleted everything
m.delete_all(user_id="alice")       # deleted alice's memories

# v1.x β€” no filter now raises an error; use "*" for intentional bulk deletes
m.delete_all()                                                       # ERROR: at least one filter required
m.delete_all(user_id="alice")                                        # unchanged
m.delete_all(user_id="*")                                            # NEW β€” delete all users' memories
m.delete_all(user_id="*", agent_id="*", app_id="*", run_id="*")     # NEW β€” full project wipe
```

## Platform Client (MemoryClient) Changes

### async_mode Default Changed

#### v0.x
```python
from mem0 import MemoryClient

client = MemoryClient(api_key="your-key")

# async_mode had to be explicitly set or had different default
result = client.add("content", user_id="alice", async_mode=True)
```

#### v1.0.0
```python
from mem0 import MemoryClient

client = MemoryClient(api_key="your-key")

# async_mode defaults to True now (better performance)
result = client.add("content", user_id="alice")  # Uses async_mode=True by default

# Can still override if needed
result = client.add("content", user_id="alice", async_mode=False)
```

## Configuration Changes

### Memory Configuration

#### v0.x Config Options
```python
config = {
    "vector_store": {...},
    "llm": {...},
    "embedder": {...},
    "graph_store": {...},
    "version": "v1.0",              # ❌ v1.0 no longer supported
    "history_db_path": "...",
    "custom_fact_extraction_prompt": "..."
}
```

#### v1.0.0  Config Options
```python
config = {
    "vector_store": {...},
    "llm": {...},
    "embedder": {...},
    "graph_store": {...},
    "reranker": {                   # βœ… NEW: Reranker support
        "provider": "cohere",
        "config": {...}
    },
    "version": "v1.1",              # βœ… v1.1+ only
    "history_db_path": "...",
    "custom_fact_extraction_prompt": "...",
    "custom_update_memory_prompt": "..."  # βœ… NEW: Custom update prompt
}
```

### New Configuration Options

#### Reranker Configuration
```python
# Cohere reranker
"reranker": {
    "provider": "cohere",
    "config": {
        "model": "rerank-english-v3.0",
        "api_key": "your-api-key",
        "top_k": 10
    }
}

# Sentence Transformer reranker
"reranker": {
    "provider": "sentence_transformer",
    "config": {
        "model": "cross-encoder/ms-marco-MiniLM-L-6-v2",
        "device": "cuda"
    }
}

# Hugging Face reranker
"reranker": {
    "provider": "huggingface",
    "config": {
        "model": "BAAI/bge-reranker-base",
        "device": "cuda"
    }
}

# LLM-based reranker
"reranker": {
    "provider": "llm_reranker",
    "config": {
        "llm": {
            "provider": "openai",
            "config": {
                "model": "gpt-4",
                "api_key": "your-api-key"
            }
        }
    }
}
```

## Error Handling Changes

### New Error Types

#### v0.x Errors
```python
# Generic exceptions
try:
    result = m.add("content", user_id="alice", version="v1.0")
except Exception as e:
    print(f"Error: {e}")
```

#### v1.0.0  Errors
```python
# More specific error handling
try:
    result = m.add("content", user_id="alice")
except ValueError as e:
    if "v1.0 API format is no longer supported" in str(e):
        # Handle version compatibility error
        pass
    elif "Invalid filter operator" in str(e):
        # Handle filter syntax error
        pass
except TypeError as e:
    # Handle parameter errors
    pass
except Exception as e:
    # Handle unexpected errors
    pass
```

### Validation Changes

#### Stricter Parameter Validation

**v0.x (Lenient):**
```python
# Unknown parameters might be ignored
result = m.add("content", user_id="alice", unknown_param="value")
```

**v1.0.0  (Strict):**
```python
# Unknown parameters raise TypeError
try:
    result = m.add("content", user_id="alice", unknown_param="value")
except TypeError as e:
    print(f"Invalid parameter: {e}")
```

## Response Schema Changes

### Memory Object Schema

#### v0.x Schema
```python
{
    "id": "mem_123",
    "memory": "User loves pizza",
    "user_id": "alice",
    "metadata": {...},
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-01T00:00:00Z",
    "score": 0.95  # In search results
}
```

#### v1.0.0  Schema (Enhanced)
```python
{
    "id": "mem_123",
    "memory": "User loves pizza",
    "user_id": "alice",
    "agent_id": "assistant",     # βœ… More context
    "run_id": "session_001",     # βœ… More context
    "metadata": {...},
    "categories": ["food"],      # βœ… NEW: Auto-categorization
    "immutable": false,          # βœ… NEW: Immutability flag
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-01T00:00:00Z",
    "score": 0.95,              # In search results
    "rerank_score": 0.98        # βœ… NEW: If reranking used
}
```

## Migration Code Examples

### Simple Migration

#### Before (v0.x)
```python
from mem0 import Memory

m = Memory()

# Add with deprecated parameters
result = m.add(
    "I love pizza",
    user_id="alice",
    output_format="v1.1",
    version="v1.0"
)

# Handle variable response format
if isinstance(result, list):
    memories = result
else:
    memories = result.get("results", [])

for memory in memories:
    print(memory["memory"])
```

#### After (v1.0.0 )
```python
from mem0 import Memory

m = Memory()

# Add without deprecated parameters
result = m.add(
    "I love pizza",
    user_id="alice"
)

# Always dict format with "results" key
for memory in result["results"]:
    print(memory["memory"])
```

### Advanced Migration

#### Before (v0.x)
```python
# Basic filtering
results = m.search(
    "food preferences",
    user_id="alice",
    filters={"category": "food"},
    output_format="v1.1"
)
```

#### After (v1.0.0 )
```python
# Enhanced filtering with reranking
results = m.search(
    "food preferences",
    user_id="alice",
    filters={
        "AND": [
            {"category": "food"},
            {"score": {"gte": 0.8}}
        ]
    },
    rerank=True
)
```

## Summary

| Component | v0.x | v1.0.0  | Status |
|-----------|------|-----------|---------|
| `add()` method | Variable response | Standardized response | ⚠️ Breaking |
| `search()` method | Basic filtering | Enhanced filtering + reranking | ⚠️ Breaking |
| `get_all()` method | Variable response | Standardized response | ⚠️ Breaking |
| Response format | Variable | Always `{"results": [...]}` | ⚠️ Breaking |
| Reranking | ❌ Not available | βœ… Full support | βœ… New feature |
| Advanced filtering | ❌ Basic only | βœ… Full operators | βœ… Enhancement |
| Error handling | Generic | Specific error types | βœ… Improvement |

<Info>
Use this reference to systematically update your codebase. Test each change thoroughly before deploying to production.
</Info>