fix(metadata): preserve empty AND results across filter conditions (#15386)

## Summary
- Fix `meta_filter()` AND logic so an empty result from an early
condition is not overwritten when a later condition matches.
- Add regression tests for empty-first AND, successful AND intersection,
and OR behavior after an empty first condition.

Fixes incorrect `/retrieval` metadata filtering when multiple AND
conditions are used and the first condition matches no documents.

Closes #15360

## Test plan
- [x] `pytest test/unit_test/common/test_metadata_filter_operators.py
-v` (19/19 passed)
This commit is contained in:
monsterDavid
2026-05-29 04:33:26 -07:00
committed by GitHub
parent 2d229dd8aa
commit 53bb2bd9e8
2 changed files with 42 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ def convert_conditions(metadata_condition):
def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):
doc_ids = set([])
doc_ids = None
def normalize_string_values(value):
if isinstance(value, str):
@@ -159,7 +159,7 @@ def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):
v2docs = metas[k]
ids = filter_out(v2docs, f["op"], f["value"])
if not doc_ids:
if doc_ids is None:
doc_ids = set(ids)
else:
if logic == "and":
@@ -169,8 +169,7 @@ def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):
return []
else:
doc_ids = doc_ids | set(ids)
logging.debug(f"meta_filter filters={filters}, logic={logic}, returning doc_ids={list(doc_ids)}")
return list(doc_ids)
return list(doc_ids or [])
async def apply_meta_data_filter(