#7468·mem0

bug(vector_stores/qdrant): two operators on one field apply only the first, so AND on one field returns excluded memories

Author: breken-aiCreated Sep 26, 2026Updated Sep 28, 2026
Labelsvector-store

Component

Vector Store

Description

Summary

With the default Qdrant store, two operators on the same metadata field only apply the first one. AND: [{"status": {"ne": "archived"}}, {"status": {"nin": ["deleted"]}}] returns the deleted memory, so search(), get_all(), list() and delete_all() return (or delete) memories the caller excluded.

Memory._process_metadata_filters merges the AND conditions on one field into a single operator dict, {"status": {"ne": "archived", "nin": ["deleted"]}}. Qdrant._build_field_condition (mem0/vector_stores/qdrant.py:311-313, an if "eq" / elif "ne" / elif "in" ... chain) then builds a condition from the first matching key only, so nin is dropped. A range plus a non-range operator ({"gte": 1, "ne": 5}) raises Cannot mix range operators ... Use AND to combine them (qdrant.py:298), but following that advice produces the same merged dict and raises again.

Steps to Reproduce

python
from mem0 import Memory

m = Memory()  # default local Qdrant store (needs an embedder, e.g. OPENAI_API_KEY)
for s in ["active", "archived", "deleted"]:
    m.add(f"note {s}", user_id="u", metadata={"status": s}, infer=False)

m.search("note", filters={"user_id": "u", "AND": [{"status": {"ne": "archived"}}, {"status": {"nin": ["deleted"]}}]})

Expected Behavior

Only the active memory (the docs, docs/open-source/features/metadata-filtering.mdx, list Qdrant as fully supporting these operators).

Actual Behavior

active and deleted are returned.

Environment

  • mem0 version: 2.2.1 (main @ 94c3fe9f238f3dbf29c9ce98643bd71eb13077cd)
  • Python/Node version: Python 3.12
  • OS: macOS

How You Verified This

What I Ran

A regression test against a real in-memory Qdrant (QdrantClient(":memory:")), tests/vector_stores/test_qdrant.py::TestQdrantEveryOperatorOnAField, on unmodified main @ 94c3fe9f238f3dbf29c9ce98643bd71eb13077cd:

python -m pytest -q tests/vector_stores/test_qdrant.py -k TestQdrantEveryOperatorOnAField

What I Saw

E       AssertionError: Lists differ: ['active', 'deleted'] != ['active']
...
E               ValueError: Cannot mix range operators ({'gte'}) with non-range operators ({'ne'}) for field 'priority'. Use AND to combine them as separate conditions.
mem0/vector_stores/qdrant.py:297: ValueError
FAILED tests/vector_stores/test_qdrant.py::TestQdrantEveryOperatorOnAField::test_ne_and_nin_on_one_field_both_apply
FAILED tests/vector_stores/test_qdrant.py::TestQdrantEveryOperatorOnAField::test_range_and_ne_on_one_field_both_apply
2 failed, 1 passed, 96 deselected, 1 warning in 3.07s

An end-to-end run of the snippet above (Memory.from_config with local Qdrant and a configured embedder, infer=False adds) returned ['active', 'deleted']; that run was on main @ 8d6c0019 (2026-09-25), and mem0/vector_stores/qdrant.py and mem0/memory/main.py are unchanged since.

Why This Is a Bug

Both conditions of an AND must hold; the metadata-filtering docs say Qdrant supports ne/nin/range operators. The TypeScript counterparts were fixed in #6264 and #6510.

What I Ruled Out

The single-operator cases still work (existing _build_field_condition tests pass). The loss happens only when _process_metadata_filters merges several operators for one field.

A fix with a regression test is ready: _create_filter splits a field's operator dict (range operators together in one Range, every other operator its own condition, all in must); the 3 tests above pass and test_qdrant.py + test_qdrant_config.py pass (101). Branch: https://github.com/breken-ai/mem0/tree/fix/qdrant-every-field-operator. We'll open the PR only once this issue is accepted.

AI Assistance

AI found and wrote this, and I have not reproduced it myself

(To be precise: an AI coding agent, Claude Code running for the breken-ai account, found the bug, wrote the regression test and ran it against current main; the output above is from that run. No human has reproduced it separately.)