fix: preserve custom metadata when updating memory#4495
Merged
kartik-mem0 merged 3 commits intomainfrom Mar 24, 2026
Merged
Conversation
Contributor
|
I think the issue is prevalent in other vector stores as well. On exploration I found that the same metadata loss still happens on Qdrant, Pinecone, Milvus, PGVector, Supabase, and Redis. If that's the case, I feel the better fix would be to have to have the change in It would be great if you can check this out once @kartik-mem0 . |
utkarsh240799
approved these changes
Mar 23, 2026
Contributor
Author
|
@whysosaket merging this for now but there will be a follow up for other providers where we will test each providers and see if this problem exist for them or not. current scope fixes the mongodb part. |
This was referenced Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MongoDB's
update()method in the vector store used{"$set": {"payload": new_payload}}which replaces the entirepayloaddocument on update, causing all existing metadata fields (e.g.,bucket_id,category,source,context_id) to be silently lost.The fix uses MongoDB dot notation —
{"$set": {"payload.data": ..., "payload.hash": ...}}— which only updates the specified fields and preserves everything else. This is the documented MongoDBbehavior for partial updates on embedded documents.
Fixes #3966
Type of change
How Has This Been Tested?
3 tests added/updated in
tests/vector_stores/test_mongodb.py:test_update— updated to verify$setuses dot notation (payload.key) instead of full replacement (payload)test_update_payload_only_uses_dot_notation— verifies only specified fields appear in$set, no full payload keytest_update_vector_only_does_not_touch_payload— verifies vector-only updates don't touch any payload fieldsAll 39 tests pass locally (21 in
test_memory.py+ 18 intest_mongodb.py).Checklist:
Maintainer Checklist