From 141fba07b7904d0d915fa069704cf35b02094e94 Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Mon, 9 Sep 2024 13:59:05 +0200 Subject: [PATCH 1/6] Remove legacy filter support --- .../document_stores/pinecone/document_store.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py index 75d6270ca..a53e3c5b7 100644 --- a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py +++ b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py @@ -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 @@ -201,6 +200,9 @@ 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: + raise ValueError("Legacy filters support has been removed. Please see documentation for new filter syntax.") + # 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) @@ -253,7 +255,7 @@ def _embedding_retrieval( raise ValueError(msg) if filters and "operator" not in filters and "conditions" not in filters: - filters = convert(filters) + raise ValueError("Legacy filters support has been removed. Please see documentation for new filter syntax.") filters = _normalize_filters(filters) if filters else None result = self.index.query( From 7adb47c6cabc6a4aec5572de453b93fd5d8a10d3 Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Mon, 9 Sep 2024 14:31:56 +0200 Subject: [PATCH 2/6] Linting --- .../document_stores/pinecone/document_store.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py index a53e3c5b7..4bb97df3f 100644 --- a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py +++ b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py @@ -201,7 +201,8 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc """ if filters and "operator" not in filters and "conditions" not in filters: - raise ValueError("Legacy filters support has been removed. Please see documentation for new filter syntax.") + msg = "Legacy filters support has been removed. Please see documentation for new filter syntax." + raise ValueError(msg) # Pinecone only performs vector similarity search # here we are querying with a dummy vector and the max compatible top_k @@ -255,7 +256,8 @@ def _embedding_retrieval( raise ValueError(msg) if filters and "operator" not in filters and "conditions" not in filters: - raise ValueError("Legacy filters support has been removed. Please see documentation for new filter syntax.") + 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( From 16ab80e314ebb2a2594a2c9081fc18f6603ebea9 Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Wed, 11 Sep 2024 12:17:57 +0200 Subject: [PATCH 3/6] Improve error message --- .../document_stores/pinecone/document_store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py index 4bb97df3f..3968241f6 100644 --- a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py +++ b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py @@ -201,7 +201,7 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc """ if filters and "operator" not in filters and "conditions" not in filters: - msg = "Legacy filters support has been removed. Please see documentation for new filter syntax." + msg = "Legacy filters support has been removed. See https://docs.haystack.deepset.ai/docs/metadata-filtering for more details." raise ValueError(msg) # Pinecone only performs vector similarity search From a5ca26cec274ae244e7c350440aad4c16112d5f7 Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Wed, 11 Sep 2024 12:23:02 +0200 Subject: [PATCH 4/6] Improve error message - lint --- .../document_stores/pinecone/document_store.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py index 3968241f6..8bbb883aa 100644 --- a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py +++ b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py @@ -201,7 +201,8 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc """ if filters and "operator" not in filters and "conditions" not in filters: - msg = "Legacy filters support has been removed. See https://docs.haystack.deepset.ai/docs/metadata-filtering for more details." + msg = ("Legacy filters support has been removed. " + "See https://docs.haystack.deepset.ai/docs/metadata-filtering for more details.") raise ValueError(msg) # Pinecone only performs vector similarity search From 3337b39bb590be5cdfa0337333e58b95d0737c4c Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Wed, 11 Sep 2024 12:26:09 +0200 Subject: [PATCH 5/6] Change message to be more generic --- .../document_stores/pinecone/document_store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py index 8bbb883aa..04e66c186 100644 --- a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py +++ b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py @@ -201,7 +201,7 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc """ if filters and "operator" not in filters and "conditions" not in filters: - msg = ("Legacy filters support has been removed. " + msg = ("Invalid filter syntax. " "See https://docs.haystack.deepset.ai/docs/metadata-filtering for more details.") raise ValueError(msg) From b3331ac79d17f14efadbe6fb1f7b586cf0f8d193 Mon Sep 17 00:00:00 2001 From: Vladimir Blagojevic Date: Wed, 11 Sep 2024 12:33:27 +0200 Subject: [PATCH 6/6] Error msg fmt --- .../document_stores/pinecone/document_store.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py index 04e66c186..07f217f5b 100644 --- a/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py +++ b/integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py @@ -201,8 +201,7 @@ def filter_documents(self, filters: Optional[Dict[str, Any]] = None) -> List[Doc """ 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 more details.") + msg = "Invalid filter syntax. See https://docs.haystack.deepset.ai/docs/metadata-filtering for details." raise ValueError(msg) # Pinecone only performs vector similarity search