Skip to content

Commit db276bc

Browse files
committed
updating NOT filter handling
1 parent 6e41c97 commit db276bc

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ def _check_condition(self, doc: Document, condition: dict[str, Any]) -> bool:
290290
if "conditions" not in condition:
291291
msg = "Missing 'conditions' for NOT operator"
292292
raise FilterError(msg)
293-
return not self._check_condition(doc, condition.get("conditions", [])[0])
293+
conditions = condition.get("conditions")
294+
if not isinstance(conditions, list) or not conditions:
295+
msg = "NOT operator expects at least one condition"
296+
raise FilterError(msg)
297+
return not all(self._check_condition(doc, cond) for cond in conditions)
294298

295299
# Leaf condition
296300
if "field" not in condition:

integrations/faiss/tests/test_document_store.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from haystack.dataclasses import Document
7+
from haystack.errors import FilterError
78
from haystack.testing.document_store import (
89
CountDocumentsTest,
910
DeleteAllTest,
@@ -149,3 +150,9 @@ def test_count_unique_metadata_by_filter(self, document_store):
149150
)
150151
assert "meta.status" in counts
151152
assert counts["meta.status"] == 1 # Only "active" status for category A
153+
154+
def test_not_filter_with_empty_conditions_raises_filter_error(self, document_store):
155+
document_store.write_documents([Document(content="test", meta={"category": "A"})])
156+
157+
with pytest.raises(FilterError, match="NOT operator expects at least one condition"):
158+
document_store.filter_documents(filters={"operator": "NOT", "conditions": []})

0 commit comments

Comments
 (0)