Skip to content

Mem0 Support for filters in V2 Search API#2725

Closed
giles17 wants to merge 4 commits intomicrosoft:mainfrom
giles17:mem0_fix
Closed

Mem0 Support for filters in V2 Search API#2725
giles17 wants to merge 4 commits intomicrosoft:mainfrom
giles17:mem0_fix

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Dec 9, 2025

Motivation and Context

This PR updates the Mem0Provider to support dynamic, per-invocation filters that align with the mem0 v2 API design. The change enables flexible memory filtering at query time while maintaining backward compatibility.

In _provider.py:

  • Updated invoking() method to accept filters via **kwargs and pass to mem0 search API
  • Added _build_filters() method to build filter dictionaries from:
    • Init parameters (user_id, agent_id, thread_id, application_id) as base scope
    • Optional per-invocation filters passed through kwargs
    • Invocation filters take precedence for overrides
  • Changed search API call from individual parameters to unified filters dict

In mem0_basic.py:

  • Added 12-second delay for memory processing

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings December 9, 2025 17:00
@github-actions github-actions bot changed the title support for filters in search v2 api Python: support for filters in search v2 api Dec 9, 2025
@giles17 giles17 changed the title Python: support for filters in search v2 api Mem0 Support for filters in V2 Search API Dec 9, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Dec 9, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _agents.py2895282%329, 390–392, 438, 492, 510, 672, 853, 856–858, 987–990, 992, 995–997, 1085, 1126, 1128, 1137–1142, 1148, 1150, 1160–1161, 1168, 1170–1171, 1179–1183, 1191–1192, 1194, 1199, 1201, 1235, 1280–1281, 1283, 1285, 1296
packages/mem0/agent_framework_mem0
   _provider.py86396%188–189, 192
TOTAL16300254684% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2329 130 💤 0 ❌ 0 🔥 57.213s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the Mem0 search v2 API's filter parameter, transitioning from passing individual filter parameters (user_id, agent_id, run_id) to a unified filters dictionary. This enables more advanced filtering capabilities including logical operators, date ranges, and complex queries.

Key Changes:

  • Modified the invoking() method to accept an optional filters kwarg and use a centralized _build_filters() method
  • Updated all tests to verify the new filters dictionary format instead of individual parameters
  • Added a 12-second delay in the sample to accommodate Mem0's asynchronous memory processing

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
python/packages/mem0/agent_framework_mem0/_provider.py Implemented _build_filters() method to consolidate init parameters into a filters dict and merge with optional invocation filters; updated invoking() to pass filters dict to mem0 search API
python/packages/mem0/tests/test_mem0_context_provider.py Updated existing tests to verify filters dict format; added comprehensive test coverage for _build_filters() method with various scenarios including merging, overriding, and exclusion of None values
python/samples/getting_started/context_providers/mem0/mem0_basic.py Added 12-second sleep between memory storage and retrieval to handle Mem0's asynchronous processing

Comment on lines +60 to +61
For advanced filtering (OR logic, date ranges, comparisons, etc.), pass a `filters`
parameter to the `invoking()` through `agent.run()` method.
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to add an example how it looks like from user perspective?

@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Dec 10, 2025
@giles17 giles17 closed this Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants