chore: Deprecate legacy document/metadata filters (#8004)

This commit is contained in:
Madeesh Kannan 2024-07-09 16:18:38 +02:00 committed by GitHub
parent 7e35280d4f
commit f19131f13a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import warnings
from dataclasses import fields from dataclasses import fields
from datetime import datetime from datetime import datetime
from typing import Any, Dict, List, Union from typing import Any, Dict, List, Union
@ -103,7 +104,8 @@ def _less_than_equal(document_value: Any, filter_value: Any) -> bool:
def _in(document_value: Any, filter_value: Any) -> bool: def _in(document_value: Any, filter_value: Any) -> bool:
if not isinstance(filter_value, list): if not isinstance(filter_value, list):
msg = ( msg = (
f"Filter value must be a `list` when using operator 'in' or 'not in', received type '{type(filter_value)}'" f"Filter value must be a `list` when using operator 'in' or 'not in', "
f"received type '{type(filter_value)}'"
) )
raise FilterError(msg) raise FilterError(msg)
return any(_equal(e, document_value) for e in filter_value) return any(_equal(e, document_value) for e in filter_value)
@ -214,6 +216,13 @@ def convert(filters: Dict[str, Any]) -> Dict[str, Any]:
} }
``` ```
""" """
warnings.warn(
"The use of legacy (Haystack 1.x) filters is deprecated and will be removed in the future. "
"Please use the new filter style as described in the documentation - "
"https://docs.haystack.deepset.ai/docs/metadata-filtering",
DeprecationWarning,
)
if not isinstance(filters, dict): if not isinstance(filters, dict):
msg = f"Can't convert filters from type '{type(filters)}'" msg = f"Can't convert filters from type '{type(filters)}'"
raise ValueError(msg) raise ValueError(msg)

View File

@ -0,0 +1,5 @@
---
deprecations:
- |
Haystack 1.x legacy filters are deprecated and will be removed in a future release. Please use the new
filter style as described in the documentation - https://docs.haystack.deepset.ai/docs/metadata-filtering