Skip to content

Fix condition check for memories_result type in Memory class#3596

Merged
parshvadaftari merged 1 commit intomem0ai:mainfrom
aesher9o1:ash/mongodb-vectordb-lookup-fix
Oct 16, 2025
Merged

Fix condition check for memories_result type in Memory class#3596
parshvadaftari merged 1 commit intomem0ai:mainfrom
aesher9o1:ash/mongodb-vectordb-lookup-fix

Conversation

@aesher9o1
Copy link
Copy Markdown
Contributor

Description

Fixed a critical bug in _get_all_from_vector_store method that caused MongoDB vector store to fail when retrieving memories via get_all() operation.

Root Cause:
The original code incorrectly unwrapped both tuples AND lists by taking the first element [0]. Different vector store backends return data in different formats:

  • Qdrant returns a tuple: ([OutputData, ...], metadata)
  • MongoDB returns a list directly: [OutputData, ...]

When MongoDB returned a list of memories, the code would extract only the first memory object instead of keeping the entire list. This caused the subsequent iteration loop to fail with AttributeError: 'tuple' object has no attribute 'id'.

The Fix:
Changed the type check from isinstance(memories_result, (tuple, list)) to isinstance(memories_result, tuple), ensuring only tuple-wrapped results are unwrapped while lists are preserved as-is.

# Before (incorrect):
actual_memories = (
    memories_result[0]
    if isinstance(memories_result, (tuple, list)) and len(memories_result) > 0
    else memories_result
)

# After (correct):
if isinstance(memories_result, tuple) and len(memories_result) > 0:
    actual_memories = memories_result[0]
else:
    actual_memories = memories_result

Impact:

  • ✅ Fixes MongoDB vector store get_all() operations
  • ✅ Maintains backward compatibility with Qdrant and other vector stores
  • ✅ No breaking changes to API or functionality

Fixes # (issue)

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?

Tested with MongoDB vector store backend:

Test Configuration:

  • Vector Store: MongoDB
  • Operation: memory_client.get_all(user_id=..., agent_id=..., run_id=...)
  • Test Data: Multiple memories stored in MongoDB collection

Test Results:

  • Before Fix: AttributeError: 'tuple' object has no attribute 'id' at line 1496
  • After Fix: Successfully retrieves and formats all memories from MongoDB

Test Script:

# Retrieve memories using MongoDB backend
memories = await memory_client.get_all(
    user_id="alice",
    agent_id="debug-cli", 
    run_id="session-001"
)
# Verify memories are returned correctly with proper structure
assert isinstance(memories, list)
assert all(hasattr(m, 'id') for m in memories)
  • Test Script (please provide)
  • Unit Test

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
  • 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
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 16, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@parshvadaftari parshvadaftari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@parshvadaftari parshvadaftari merged commit 7afbaae into mem0ai:main Oct 16, 2025
6 of 7 checks passed
@parshvadaftari
Copy link
Copy Markdown
Contributor

Thank you for contributing to mem0 @aesher9o1 !

@aesher9o1
Copy link
Copy Markdown
Contributor Author

aesher9o1 commented Oct 17, 2025

@parshvadaftari any chance we could do a minor release with my fix? We at Quillbot at trying to go live with mem0, currently blocked because of the bug.

@aesher9o1 aesher9o1 deleted the ash/mongodb-vectordb-lookup-fix branch October 17, 2025 15:42
@parshvadaftari
Copy link
Copy Markdown
Contributor

Hey @aesher9o1 we'll be making a next release next week as we just made the public release for 1.0.0. Sorry for the blocker from our end, we'll try to make the next release as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants