Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Deprecate legacy document/metadata filters #8004

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion haystack/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

import warnings
from dataclasses import fields
from datetime import datetime
from typing import Any, Dict, List, Union
Expand Down Expand Up @@ -103,7 +104,8 @@ def _less_than_equal(document_value: Any, filter_value: Any) -> bool:
def _in(document_value: Any, filter_value: Any) -> bool:
if not isinstance(filter_value, list):
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)
return any(_equal(e, document_value) for e in filter_value)
Expand Down Expand Up @@ -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):
msg = f"Can't convert filters from type '{type(filters)}'"
raise ValueError(msg)
Expand Down
Original file line number Diff line number Diff line change
@@ -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