|
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | 5 | from copy import copy |
6 | | -from typing import Any, Literal, Optional, Union |
| 6 | +from typing import Any, Literal |
7 | 7 |
|
8 | 8 | from haystack import default_from_dict, default_to_dict, logging |
9 | 9 | from haystack.dataclasses import Document |
@@ -41,7 +41,7 @@ def __init__( |
41 | 41 | namespace: str = "default", |
42 | 42 | batch_size: int = 100, |
43 | 43 | dimension: int = 768, |
44 | | - spec: Optional[dict[str, Any]] = None, |
| 44 | + spec: dict[str, Any] | None = None, |
45 | 45 | metric: Literal["cosine", "euclidean", "dotproduct"] = "cosine", |
46 | 46 | ): |
47 | 47 | """ |
@@ -73,8 +73,8 @@ def __init__( |
73 | 73 | self.dimension = dimension |
74 | 74 | self.index_name = index |
75 | 75 |
|
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 |
78 | 78 | self._dummy_vector = [-10.0] * self.dimension |
79 | 79 |
|
80 | 80 | def _initialize_index(self): |
@@ -156,7 +156,7 @@ async def close_async(self): |
156 | 156 | self._async_index = None |
157 | 157 |
|
158 | 158 | @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: |
160 | 160 | """Convert the spec dictionary to a Pinecone spec object""" |
161 | 161 |
|
162 | 162 | if "serverless" in spec: |
@@ -274,7 +274,7 @@ async def write_documents_async( |
274 | 274 | # if the operation is successful, result will have the upserted_count attribute |
275 | 275 | return result.upserted_count # type: ignore[union-attr] |
276 | 276 |
|
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]: |
278 | 278 | """ |
279 | 279 | Returns the documents that match the filters provided. |
280 | 280 |
|
@@ -306,7 +306,7 @@ def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Doc |
306 | 306 | ) |
307 | 307 | return documents |
308 | 308 |
|
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]: |
310 | 310 | """ |
311 | 311 | Asynchronously returns the documents that match the filters provided. |
312 | 312 |
|
@@ -540,8 +540,8 @@ def _embedding_retrieval( |
540 | 540 | self, |
541 | 541 | query_embedding: list[float], |
542 | 542 | *, |
543 | | - namespace: Optional[str] = None, |
544 | | - filters: Optional[dict[str, Any]] = None, |
| 543 | + namespace: str | None = None, |
| 544 | + filters: dict[str, Any] | None = None, |
545 | 545 | top_k: int = 10, |
546 | 546 | ) -> list[Document]: |
547 | 547 | """ |
@@ -583,8 +583,8 @@ async def _embedding_retrieval_async( |
583 | 583 | self, |
584 | 584 | query_embedding: list[float], |
585 | 585 | *, |
586 | | - namespace: Optional[str] = None, |
587 | | - filters: Optional[dict[str, Any]] = None, |
| 586 | + namespace: str | None = None, |
| 587 | + filters: dict[str, Any] | None = None, |
588 | 588 | top_k: int = 10, |
589 | 589 | ) -> list[Document]: |
590 | 590 | """ |
|
0 commit comments