Skip to content

Commit

Permalink
chore: Pinecone - remove legacy filter support (#1069)
Browse files Browse the repository at this point in the history
* Remove legacy filter support

* Linting

* Improve error message

* Improve error message - lint

* Change message to be more generic

* Error msg fmt
  • Loading branch information
vblagoje authored and Amnah199 committed Oct 2, 2024
1 parent f6bee4a commit 59a5b31
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from haystack.dataclasses import Document
from haystack.document_stores.types import DuplicatePolicy
from haystack.utils import Secret, deserialize_secrets_inplace
from haystack.utils.filters import convert

from pinecone import Pinecone, PodSpec, ServerlessSpec

Expand Down Expand Up @@ -201,6 +200,10 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc
:returns: A list of Documents that match the given filters.
"""

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)

# Pinecone only performs vector similarity search
# here we are querying with a dummy vector and the max compatible top_k
documents = self._embedding_retrieval(query_embedding=self._dummy_vector, filters=filters, top_k=TOP_K_LIMIT)
Expand Down Expand Up @@ -253,7 +256,8 @@ def _embedding_retrieval(
raise ValueError(msg)

if filters and "operator" not in filters and "conditions" not in filters:
filters = convert(filters)
msg = "Legacy filters support has been removed. Please see documentation for new filter syntax."
raise ValueError(msg)
filters = _normalize_filters(filters) if filters else None

result = self.index.query(
Expand Down

0 comments on commit 59a5b31

Please sign in to comment.