-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add memory update with metadata support #3618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add memory update with metadata support #3618
Conversation
ad0163f to
876958b
Compare
|
Good catch @frederikb96 can. You check for failing tests?? Really appreciate the effort! |
|
@parshvadaftari Thanks for fast reply 🙂 The test expected that there are exactly 3 arguments. The code is still backward compatible, but the test was just too strict. I adjusted it, should work now. All tests pass again. |
|
I added two more commits here: Before this PR, update() in mem0 main.py didn't accept a metadata parameter, and internally all custom metadata was lost on every update. This happened because the internal _update_memory() function treated metadata=None as "start with empty dict", clearing everything. Now:
This makes updates more intuitive - updating content no longer accidentally erases metadata. I suspect that was also the intention back then, but it was just a bug in the code. Then I aligned the behavior of the new MCP update_memory function to handle metadata for the openmemory DB accordingly and fixed my code. |
|
Hey @frederikb96 can you share response for the update and update with metadata? Also please update your branch with the latest main inorder for the tests to pass. Thanks! |
7ad44bd to
a5cecb2
Compare
|
Hi, I rebased it, streamlined it again, and adjusted one of my test scripts. I had to include some of my other feature branches code to be able to run it to query metadata via search to display in test. And the test doesnt behave exactly as it will be later since some other fixes from other PRs are not incorporated yet. But its the best I managed to test this individually 😅 e.g. normally the metadata: is not lost thats just because of another db bug in the add memory function at moment, where I have not yet created PR for. I tried to make little mini PRs for now, but maybe I will create more big once which fix multiple things at once since then testing here for PR is easier 🙂 Here the test: |
a5cecb2 to
1f7268a
Compare
|
Hey @frederikb96 can you resolve merge conflicts as well? |
1f7268a to
73653c7
Compare
|
@parshvadaftari Yes sure 🙂 Rebased it 👍 Thanks for all the ongoing merging 🙂 |
Implements metadata update capability for memory operations across
mem0 core library and OpenMemory MCP interface.
mem0 core changes:
- Add optional metadata parameter to update() method (sync and async)
- Modify _update_memory() to preserve existing metadata when metadata=None
- When metadata is provided, it replaces custom metadata fields
- System fields (data, hash, timestamps) always managed automatically
- Session identifiers (user_id, agent_id, run_id) preserved if not in new metadata
MCP update_memory tool:
- Add new MCP tool for updating memory content and metadata
- Implement system field protection (user_id, agent_id, run_id, actor_id, role, source_app, mcp_client)
- System fields from existing metadata are preserved and cannot be overwritten
- User-provided system fields are silently filtered out before merge
- Sync both Qdrant and PostgreSQL databases
- Include_metadata parameter added to search_memory for metadata visibility
Behavior:
- metadata=None: Preserves all existing metadata (default)
- metadata={}: Clears custom fields, preserves system fields
- metadata={...}: Replaces custom fields, preserves system fields
Note: System field preservation depends on metadata being stored in PostgreSQL
during add operation. This functionality will work fully once the add_memories
database storage bug is fixed in a future PR.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
73653c7 to
6f2e02b
Compare
|
This PR would unblocks a bunch of band-aid fixes on our side (we had to reach the internal vector to update metadata), any ETA on merge? |
|
We really need this merge update and hope the core maintainers can review it as soon as possible |
Description
Adds metadata update capability to both mem0 core library and MCP API layer.
Context:
update()method currently only acceptsmemory_idanddataparameters_update_memory()already supports metadata with proper protection logicChanges:
1. mem0 Core Library (
mem0/memory/main.py)metadata: Optional[Dict[str, Any]] = Noneparameter to both sync/asyncupdate()methods_update_memory()call2. MCP API Layer (
openmemory/api/app/mcp_server.py)update_memorytool withmemory_id,text, and optionalmetadataparametersupdate()API (no direct internal method calls)Implementation Details:
The existing
_update_memory()method (lines 1145-1162) already implements proper metadata handling:This PR exposes that capability through the public API and makes it available via MCP, following the same pattern as
add()which already accepts metadata.Metadata Protection:
data,hash,created_at,updated_atuser_id,agent_id,run_idType of change
How Has This Been Tested?
Test verification:
category: "physics",topic: "quantum",updated_test: "true")Checklist: