Skip to content

[Bug]:mem0 filter for metadata has syntax error; user_id, agent_id in filter is OR not AND logic #823

@fengyinqiao

Description

@fengyinqiao

Mem0Client.java: private <T> Mono<String> executePostRaw(String endpoint, T request, String operationName)
after debug i found that the request body is as follow:

{"query":"xxx","version":"v2","filters":{"system":"bifrost-agent","agent_id":"BifrostDiagnosisAgent","agent_name":"BifrostDiagnosisAgent","user_id":"default","type":"diagnosis","version":"1.0.0"},"top_k":5,"user_id":"default"}

but found error:

{"filters":["Top-level key must be a logical operator or an allowed field: ['AND', 'OR', 'NOT', 'user_id', 'agent_id', 'app_id', 'run_id', 'created_at', 'updated_at', 'timestamp', 'text', 'categories', 'metadata', 'keywords_search', 'memory_ids', 'keywords']."]}

the correct syntax is expected as below:

{
  "query": "xxx",
  "version": "v2",
  "filters": {
    "OR": [
      { "user_id": "default" },
      { "agent_id": { "in": ["BifrostDiagnosisAgent"] } },
      {
        "AND": [
          { "metadata": { "system": "bifrost-agent" } },
          { "metadata": { "agent_name": "BifrostDiagnosisAgent" } },
          { "metadata": { "type": "diagnosis" } },
          { "metadata": { "version": "1.0.0" } }
        ]
      }
    ]
  },
  "top_k": 5,
  "user_id": "default"
}

also,user_id, agent_id in filter is OR not AND logic, because the message in mem0 belongs to only one entity not both:

Image

the follow logic need to fix, i think:
Image

ref: https://docs.mem0.ai/api-reference/memory/search-memories#body-filters-metadata

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions