Skip to content

Commit 90365e2

Browse files
anakin87davidsbatista
authored andcommitted
chore!: pinecone - drop Python 3.9 and use X|Y typing (#2723)
1 parent 6896600 commit 90365e2

5 files changed

Lines changed: 23 additions & 29 deletions

File tree

integrations/pinecone/pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ name = "pinecone_haystack"
77
dynamic = ["version"]
88
description = ''
99
readme = "README.md"
10-
requires-python = ">=3.9"
10+
requires-python = ">=3.10"
1111
license = "Apache-2.0"
1212
keywords = []
1313
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
1414
classifiers = [
1515
"License :: OSI Approved :: Apache Software License",
1616
"Development Status :: 4 - Beta",
1717
"Programming Language :: Python",
18-
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
2120
"Programming Language :: Python :: 3.12",
@@ -24,7 +23,7 @@ classifiers = [
2423
"Programming Language :: Python :: Implementation :: PyPy",
2524
]
2625
dependencies = [
27-
"haystack-ai>=2.11.0",
26+
"haystack-ai>=2.22.0",
2827
"pinecone[asyncio]>=7.0.0",
2928
]
3029

@@ -88,7 +87,6 @@ allow-direct-references = true
8887

8988

9089
[tool.ruff]
91-
target-version = "py39"
9290
line-length = 120
9391

9492
[tool.ruff.lint]
@@ -137,10 +135,6 @@ ignore = [
137135
# Ignore assertions
138136
"S101",
139137
]
140-
unfixable = [
141-
# Don't touch unused imports
142-
"F401",
143-
]
144138

145139
[tool.ruff.lint.isort]
146140
known-first-party = ["haystack_integrations"]

integrations/pinecone/src/haystack_integrations/components/retrievers/pinecone/embedding_retriever.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Optional, Union
4+
from typing import Any
55

66
from haystack import component, default_from_dict, default_to_dict
77
from haystack.dataclasses import Document
@@ -55,9 +55,9 @@ def __init__(
5555
self,
5656
*,
5757
document_store: PineconeDocumentStore,
58-
filters: Optional[dict[str, Any]] = None,
58+
filters: dict[str, Any] | None = None,
5959
top_k: int = 10,
60-
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
60+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
6161
):
6262
"""
6363
:param document_store: The Pinecone Document Store.
@@ -114,8 +114,8 @@ def from_dict(cls, data: dict[str, Any]) -> "PineconeEmbeddingRetriever":
114114
def run(
115115
self,
116116
query_embedding: list[float],
117-
filters: Optional[dict[str, Any]] = None,
118-
top_k: Optional[int] = None,
117+
filters: dict[str, Any] | None = None,
118+
top_k: int | None = None,
119119
) -> dict[str, list[Document]]:
120120
"""
121121
Retrieve documents from the `PineconeDocumentStore`, based on their dense embeddings.
@@ -143,8 +143,8 @@ def run(
143143
async def run_async(
144144
self,
145145
query_embedding: list[float],
146-
filters: Optional[dict[str, Any]] = None,
147-
top_k: Optional[int] = None,
146+
filters: dict[str, Any] | None = None,
147+
top_k: int | None = None,
148148
) -> dict[str, list[Document]]:
149149
"""
150150
Asynchronously retrieve documents from the `PineconeDocumentStore`, based on their dense embeddings.

integrations/pinecone/src/haystack_integrations/document_stores/pinecone/document_store.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
from copy import copy
6-
from typing import Any, Literal, Optional, Union
6+
from typing import Any, Literal
77

88
from haystack import default_from_dict, default_to_dict, logging
99
from haystack.dataclasses import Document
@@ -41,7 +41,7 @@ def __init__(
4141
namespace: str = "default",
4242
batch_size: int = 100,
4343
dimension: int = 768,
44-
spec: Optional[dict[str, Any]] = None,
44+
spec: dict[str, Any] | None = None,
4545
metric: Literal["cosine", "euclidean", "dotproduct"] = "cosine",
4646
):
4747
"""
@@ -73,8 +73,8 @@ def __init__(
7373
self.dimension = dimension
7474
self.index_name = index
7575

76-
self._index: Optional[_Index] = None
77-
self._async_index: Optional[_IndexAsyncio] = None
76+
self._index: _Index | None = None
77+
self._async_index: _IndexAsyncio | None = None
7878
self._dummy_vector = [-10.0] * self.dimension
7979

8080
def _initialize_index(self):
@@ -156,7 +156,7 @@ async def close_async(self):
156156
self._async_index = None
157157

158158
@staticmethod
159-
def _convert_dict_spec_to_pinecone_object(spec: dict[str, Any]) -> Union[ServerlessSpec, PodSpec]:
159+
def _convert_dict_spec_to_pinecone_object(spec: dict[str, Any]) -> ServerlessSpec | PodSpec:
160160
"""Convert the spec dictionary to a Pinecone spec object"""
161161

162162
if "serverless" in spec:
@@ -274,7 +274,7 @@ async def write_documents_async(
274274
# if the operation is successful, result will have the upserted_count attribute
275275
return result.upserted_count # type: ignore[union-attr]
276276

277-
def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
277+
def filter_documents(self, filters: dict[str, Any] | None = None) -> list[Document]:
278278
"""
279279
Returns the documents that match the filters provided.
280280
@@ -306,7 +306,7 @@ def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Doc
306306
)
307307
return documents
308308

309-
async def filter_documents_async(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
309+
async def filter_documents_async(self, filters: dict[str, Any] | None = None) -> list[Document]:
310310
"""
311311
Asynchronously returns the documents that match the filters provided.
312312
@@ -540,8 +540,8 @@ def _embedding_retrieval(
540540
self,
541541
query_embedding: list[float],
542542
*,
543-
namespace: Optional[str] = None,
544-
filters: Optional[dict[str, Any]] = None,
543+
namespace: str | None = None,
544+
filters: dict[str, Any] | None = None,
545545
top_k: int = 10,
546546
) -> list[Document]:
547547
"""
@@ -583,8 +583,8 @@ async def _embedding_retrieval_async(
583583
self,
584584
query_embedding: list[float],
585585
*,
586-
namespace: Optional[str] = None,
587-
filters: Optional[dict[str, Any]] = None,
586+
namespace: str | None = None,
587+
filters: dict[str, Any] | None = None,
588588
top_k: int = 10,
589589
) -> list[Document]:
590590
"""

integrations/pinecone/src/haystack_integrations/document_stores/pinecone/filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Optional
4+
from typing import Any
55

66
from haystack.errors import FilterError
77

@@ -181,7 +181,7 @@ def _in(field: str, value: Any) -> dict[str, Any]:
181181
LOGICAL_OPERATORS = {"AND": "$and", "OR": "$or"}
182182

183183

184-
def _validate_filters(filters: Optional[dict[str, Any]]) -> None:
184+
def _validate_filters(filters: dict[str, Any] | None) -> None:
185185
"""
186186
Helper method to validate filter syntax.
187187
"""

integrations/pinecone/tests/test_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def assert_documents_are_equal(self, received: list[Document], expected: list[Do
2121
assert len(received) == len(expected)
2222
received.sort(key=lambda x: x.id)
2323
expected.sort(key=lambda x: x.id)
24-
for received_doc, expected_doc in zip(received, expected):
24+
for received_doc, expected_doc in zip(received, expected, strict=True):
2525
assert received_doc.meta == expected_doc.meta
2626
assert received_doc.content == expected_doc.content
2727
# unfortunately, Pinecone returns a slightly different embedding

0 commit comments

Comments
 (0)