Skip to content

resolveFilters produces AND/OR filter format incompatible with self-host server's /search endpoint #1

Description

@peterkostadinov

Describe the bug

The resolveFilters function in opencode-mem0-selfhost produces filters in {AND: [{user_id: "..."}, {app_id: "..."}]} format, which is designed for the Mem0 Platform/cloud API. However, the self-host Mem0 server's /search endpoint expects flat filters like {user_id: "...", app_id: "..."} with user_id, agent_id, or run_id as direct keys at the top level.

This causes every search_memories call to fail with:

mem0 self-host POST /search failed (400): filters must contain at least one of: user_id, agent_id, run_id. Example: filters={'user_id': 'u1'}

To Reproduce

  1. Install opencode-mem0-selfhost v0.1.7
  2. Configure with a self-host Mem0 server
  3. Call the search_memories tool with any query
  4. Observe the 400 error

Expected behavior

The search_memories tool should successfully search memories scoped to the current user/project.

Root Cause

The resolveFilters function (defined at around line 12932 in dist/index.js) always wraps filters in {AND: [...]} or {OR: [...]} structures:

https://github.com/imsudip/opencode-mem0-selfhost/blob/main/dist/index.js#L12932-L12984

The self-host server validates that filters (from the SearchRequest schema) contains at least one of user_id, agent_id, or run_id as a direct key. Since the plugin nests these inside AND, none of them appear at the top level and the server rejects the request.

Additionally, the search method in SelfHostMemoryClient sends filters directly to the server without any client-side post-processing. The self-host server stores app_id inside metadata.app_id and cannot filter on it server-side, so search results are not scoped to the current project.

Fix Applied Locally

I hotfixed dist/index.js with two changes:

  1. resolveFilters: Now produces flat objects like {user_id: "peterkostadinov", app_id: "AI-Shorts"} instead of {AND: [{user_id: "..."}, {app_id: "..."}]}. Legacy AND/OR input is flattened.

  2. search method: After getting the server response, applies memoryMatches client-side for non-first-class filter keys (like app_id which lives in metadata). This ensures app_id filtering works for search results.

Environment

  • Plugin version: 0.1.7
  • Self-host Mem0 server version: latest (REST API via docker)
  • OpenCode version: latest

Additional context
Full source for resolveFilters is at dist/index.js ~L12932 and selfhost-client.ts in the SelfHostMemoryClient.search() method.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions