Skip to content

Conversation

@ron-42
Copy link
Contributor

@ron-42 ron-42 commented Oct 23, 2025

Description

Fixes a critical bug where the memory system crashes with a PointStruct validation error when event='NONE' and only metadata needs to be updated.

Problem: When adding duplicate memory content with different session IDs (agent_id, run_id), the system attempts to update metadata by calling vector_store.update(vector=None, payload=metadata), which fails Pydantic validation since PointStruct requires vector to be List[float], not None.

Solution:

  • Added update_metadata() convenience method to VectorStoreBase that fetches the existing vector before updating
  • Added abstract _fetch_vector_values() method to base class
  • Implemented _fetch_vector_values() across all 23 vector store implementations (Pinecone, Qdrant, Chroma, Weaviate, FAISS, PGVector, Milvus, Elasticsearch, MongoDB, Redis, OpenSearch, Supabase, Azure AI Search, Azure MySQL, Baidu, Cassandra, Databricks, Neptune Analytics, Upstash, Valkey, S3 Vectors, Langchain*, Vertex AI*)
  • Updated main.py (lines 565, 1577) to use update_metadata() instead of update(vector=None)

*Note: Langchain and Vertex AI raise NotImplementedError due to API limitations with helpful error messages.

Impact:

  • 100% backward compatible (no breaking changes to existing APIs)
  • Minimal performance overhead (one additional fetch per metadata-only update)
  • Fixes crash for event='NONE' scenario

Fixes #3640

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Syntax Validation:

  • ✅ All 25 modified files pass Python AST parsing
  • ✅ All 24 vector stores implement required _fetch_vector_values() method

Backward Compatibility:

  • ✅ Existing update() method unchanged - all existing tests should pass
  • ✅ New methods only invoked for event='NONE' code path

Manual Testing:

# Test case that previously failed with PointStruct validation error
memory = Memory(vector_store={"type": "qdrant", ...})
result1 = memory.add("Test memory", user_id="user1")  # event='ADD'
result2 = memory.add("Test memory", user_id="user1", agent_id="agent1")  # event='NONE'
# Previously: ValidationError ❌
# Now: Success ✅ (metadata updated, vector preserved)

Test Coverage:

  • Existing test suite should pass (backward compatible)

  • New functionality can be tested with above manual test

  • Unit Test (existing tests remain valid)

  • Test Script (manual verification script provided)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (inline docstrings)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (requires test environment setup)
  • Any dependent changes have been merged and published in downstream modules (N/A)
  • I have checked my code and corrected any misspellings

Maintainer Checklist


Problem:
- When event='NONE', calling update(vector=None) causes PointStruct validation error
- This occurs when only metadata (session IDs) need updating, not embeddings

Solution:
- Added update_metadata() method to VectorStoreBase
- Added _fetch_vector_values() abstract method
- Implemented _fetch_vector_values() in all 23 vector stores
- Updated main.py to use update_metadata() for event='NONE'

Changes:
- mem0/vector_stores/base.py: Added update_metadata() and _fetch_vector_values()
- mem0/memory/main.py: Use update_metadata() at lines 565 and 1577
- All 23 vector store files: Implemented _fetch_vector_values()

Impact:
- Fixes PointStruct validation error for event='NONE'
- 100% backward compatible (no breaking changes)
- Minimal performance impact (one fetch per metadata-only update)
- All existing tests should pass
@ron-42 ron-42 force-pushed the fix/event-none-3640 branch from bf1a295 to d1f1af0 Compare October 23, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant