Skip to content

Conversation

@HScarb
Copy link
Contributor

@HScarb HScarb commented Jul 22, 2025

Description

Fix #3207

This PR fixes incorrect handling of the search method's return value structure in documentation examples across docs/integrations/ and docs/examples/ directories. The search method returns {"results": [...]} but many
examples were accessing results directly or using incorrect field names, causing runtime errors when users follow these examples.

Fixes #(issue number - to be filled when issue is created)

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

Changes Made

Problem Patterns Fixed:

  1. Wrong field access: mem['text']mem['memory']
  2. Direct iteration: for mem in memoriesfor mem in memories.get('results', [])
  3. Wrong root field: memories['memories']memories.get('results', [])
  4. Missing safety: Added proper null checks and safe field access

Files Updated:

docs/integrations/ (10 files):

  • multion.mdx - Fixed field name and added results field access
  • langchain.mdx - Added safe results field access
  • langgraph.mdx - Added safe results field access
  • autogen.mdx - Fixed both search result handling locations
  • openai-agents-sdk.mdx - Added safety checks for results
  • agentops.mdx - Fixed iteration pattern
  • agno.mdx - Updated memory context construction
  • elevenlabs.mdx - Fixed memory extraction logic
  • google-ai-adk.mdx - Updated search_memory function
  • livekit.mdx - Updated search results handling

docs/examples/ (5 files):

  • ai_companion.mdx - Fixed field name and direct iteration issues
  • personal-travel-assistant.mdx - Fixed wrong root field access
  • llamaindex-multiagent-learning-system.mdx - Added results field access
  • openai-inbuilt-tools.mdx - Added compatibility handling for results
  • memory-guided-content-writing.mdx - Fixed direct iteration

Unified Fix Pattern Applied:

Before (Incorrect):

memories = client.search(query, user_id=user_id)
for mem in memories:  # Direct iteration - ERROR
    content = mem['text']  # Wrong field name - ERROR

After (Correct):
memories = client.search(query, user_id=user_id)
for mem in memories.get('results', []):  # Safe access
    content = mem['memory']  # Correct field name

How Has This Been Tested?

  • Manual verification of all modified code patterns
  • Verified no remaining incorrect field access (mem['text'])
  • Verified no remaining wrong root fields (memories['memories'])
  • Confirmed consistent safe access patterns across all files
  • Cross-checked with current API documentation structure

Please delete options that are not relevant.

  • Unit Test
  • Test Script (please provide)

Note: This is a documentation-only fix. The changes ensure examples match the current API structure without requiring code changes to the library itself.

Impact & Benefits

  • ✅ Prevents Runtime Errors: Users can now successfully run all documentation examples
  • ✅ Consistent Patterns: All integrations now use the same correct access patterns
  • ✅ Better Developer Experience: Clear, working examples improve onboarding
  • ✅ API Compliance: All examples now properly handle the current {"results": [...]} structure

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 (N/A - documentation only)
  • New and existing unit tests pass locally with my changes (N/A - documentation only)
  • Any dependent changes have been merged and published in downstream modules (N/A)
  • I have checked my code and corrected any misspellings

Additional Notes

This PR ensures that all integration and example documentation now correctly demonstrates the current mem0 API usage patterns. Users following these examples will no longer encounter KeyError or AttributeError exceptions,
significantly improving the developer experience for new users of the mem0 library.

The changes are backward-compatible and use safe access patterns (get() method with defaults) to handle edge cases gracefully.

@CLAassistant
Copy link

CLAassistant commented Jul 22, 2025

CLA assistant check
All committers have signed the CLA.

@deshraj
Copy link
Collaborator

deshraj commented Jul 24, 2025

Hey @HScarb, thanks for opening the PR. Can you please sign the CLA so that we can review and merge the PR? Thanks!

@HScarb
Copy link
Contributor Author

HScarb commented Jul 25, 2025

Hey @HScarb, thanks for opening the PR. Can you please sign the CLA so that we can review and merge the PR? Thanks!

@deshraj Thanks for your reply. I have signed the CLA.

@prateekchhikara prateekchhikara merged commit c2792c6 into mem0ai:main Aug 11, 2025
1 of 2 checks passed
kirex0 pushed a commit to kirex0/mem0 that referenced this pull request Aug 12, 2025
thestumonkey pushed a commit to thestumonkey/mem0 that referenced this pull request Sep 7, 2025
jamesnavinhill pushed a commit to jamesnavinhill/ltm that referenced this pull request Sep 25, 2025
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.

DOC: Documentation Examples Have Incorrect Search Method Return Value Handling

4 participants