Skip to content

Commit

Permalink
feat: Add utility function to check metadata filter syntax (#8386)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadeMe authored Sep 19, 2024
1 parent caf465b commit 151bd53
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion haystack/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

from dataclasses import fields
from datetime import datetime
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional

import pandas as pd

from haystack.dataclasses import Document
from haystack.errors import FilterError


def raise_on_invalid_filter_syntax(filters: Optional[Dict[str, Any]] = None):
"""
Raise an error if the filter syntax is invalid.
"""
if filters and "operator" not in filters and "conditions" not in filters:
msg = "Invalid filter syntax. See https://docs.haystack.deepset.ai/docs/metadata-filtering for details."
raise ValueError(msg)


def document_matches_filter(filters: Dict[str, Any], document: Document) -> bool:
"""
Return whether `filters` match the Document.
Expand Down

0 comments on commit 151bd53

Please sign in to comment.