Commit 7ad44bd
committed
Fix MCP update_memory metadata handling and database sync
Fixed three critical bugs in MCP update_memory tool:
1. SQLAlchemy mutation tracking: Create new dict object instead of
modifying and reassigning same reference (change detection failed)
2. Empty metadata clearing: Filter system fields first, then update
with request metadata. Empty {} now correctly clears custom fields
while preserving system fields (source_app, mcp_client, etc.)
3. Database synchronization: Prepare merged metadata once and send
same data to both mem0 (Qdrant) and PostgreSQL. Previously they
received different metadata causing divergence.
Behavior:
- metadata=None: PostgreSQL unchanged, Qdrant preserved by mem0 core
- metadata={}: Clear custom fields, keep system fields in both DBs
- metadata={"key": "val"}: System + custom fields in both DBs
Pattern follows add_memories: prepare combined metadata once, send to
both databases for perfect synchronization.1 parent 84a2655 commit 7ad44bd
1 file changed
+27
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
292 | | - | |
| 293 | + | |
293 | 294 | | |
294 | 295 | | |
295 | 296 | | |
| |||
318 | 319 | | |
319 | 320 | | |
320 | 321 | | |
321 | | - | |
322 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
323 | 327 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 328 | + | |
329 | 329 | | |
330 | | - | |
331 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
332 | 349 | | |
333 | 350 | | |
334 | 351 | | |
| |||
0 commit comments