fix(qdrant): handle $or/$not keys injected by Memory middleware

Memory._process_metadata_filters() renames OR→$or and NOT→$not before
passing filters to the vector store. Without this fix, $or/$not keys
with list values hit _build_field_condition and crash with
ValidationError (MatchValue rejects lists).

Normalize $or→OR, $not→NOT, $and→AND at the start of _create_filter
so both naming conventions work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
kartik-mem0
2026-03-21 18:32:57 +05:30
co-authored by Claude Opus 4.6
parent 269d784c0f
commit b1dbd08c63
2 changed files with 62 additions and 5 deletions
+9 -5
View File
@@ -222,24 +222,28 @@ class Qdrant(VectorStoreBase):
must_not = []
for key, value in filters.items():
if key in ("AND", "OR", "NOT"):
# Normalize $or/$not (injected by Memory._process_metadata_filters)
# to OR/NOT so they're handled uniformly.
normalized_key = {"$or": "OR", "$not": "NOT", "$and": "AND"}.get(key, key)
if normalized_key in ("AND", "OR", "NOT"):
if not isinstance(value, list):
raise ValueError(
f"{key} filter value must be a list of filter dicts, "
f"{normalized_key} filter value must be a list of filter dicts, "
f"got {type(value).__name__}"
)
if key == "AND":
if normalized_key == "AND":
for sub in value:
built = self._create_filter(sub)
if built:
must.append(built)
elif key == "OR":
elif normalized_key == "OR":
for sub in value:
built = self._create_filter(sub)
if built:
should.append(built)
elif key == "NOT":
elif normalized_key == "NOT":
for sub in value:
built = self._create_filter(sub)
if built: