Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions integrations/pinecone/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ name = "pinecone_haystack"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
license = "Apache-2.0"
keywords = []
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -24,7 +23,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"haystack-ai>=2.11.0",
"haystack-ai>=2.22.0",
"pinecone[asyncio]>=7.0.0",
]

Expand Down Expand Up @@ -88,7 +87,6 @@ allow-direct-references = true


[tool.ruff]
target-version = "py39"
line-length = 120

[tool.ruff.lint]
Expand Down Expand Up @@ -137,10 +135,6 @@ ignore = [
# Ignore assertions
"S101",
]
unfixable = [
# Don't touch unused imports
"F401",
]

[tool.ruff.lint.isort]
known-first-party = ["haystack_integrations"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Optional, Union
from typing import Any

from haystack import component, default_from_dict, default_to_dict
from haystack.dataclasses import Document
Expand Down Expand Up @@ -55,9 +55,9 @@ def __init__(
self,
*,
document_store: PineconeDocumentStore,
filters: Optional[dict[str, Any]] = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
):
"""
:param document_store: The Pinecone Document Store.
Expand Down Expand Up @@ -114,8 +114,8 @@ def from_dict(cls, data: dict[str, Any]) -> "PineconeEmbeddingRetriever":
def run(
self,
query_embedding: list[float],
filters: Optional[dict[str, Any]] = None,
top_k: Optional[int] = None,
filters: dict[str, Any] | None = None,
top_k: int | None = None,
) -> dict[str, list[Document]]:
"""
Retrieve documents from the `PineconeDocumentStore`, based on their dense embeddings.
Expand Down Expand Up @@ -143,8 +143,8 @@ def run(
async def run_async(
self,
query_embedding: list[float],
filters: Optional[dict[str, Any]] = None,
top_k: Optional[int] = None,
filters: dict[str, Any] | None = None,
top_k: int | None = None,
) -> dict[str, list[Document]]:
"""
Asynchronously retrieve documents from the `PineconeDocumentStore`, based on their dense embeddings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

from copy import copy
from typing import Any, Literal, Optional, Union
from typing import Any, Literal

from haystack import default_from_dict, default_to_dict, logging
from haystack.dataclasses import Document
Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(
namespace: str = "default",
batch_size: int = 100,
dimension: int = 768,
spec: Optional[dict[str, Any]] = None,
spec: dict[str, Any] | None = None,
metric: Literal["cosine", "euclidean", "dotproduct"] = "cosine",
):
"""
Expand Down Expand Up @@ -73,8 +73,8 @@ def __init__(
self.dimension = dimension
self.index_name = index

self._index: Optional[_Index] = None
self._async_index: Optional[_IndexAsyncio] = None
self._index: _Index | None = None
self._async_index: _IndexAsyncio | None = None
self._dummy_vector = [-10.0] * self.dimension

def _initialize_index(self):
Expand Down Expand Up @@ -156,7 +156,7 @@ async def close_async(self):
self._async_index = None

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

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

def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
def filter_documents(self, filters: dict[str, Any] | None = None) -> list[Document]:
"""
Returns the documents that match the filters provided.

Expand Down Expand Up @@ -306,7 +306,7 @@ def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Doc
)
return documents

async def filter_documents_async(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
async def filter_documents_async(self, filters: dict[str, Any] | None = None) -> list[Document]:
"""
Asynchronously returns the documents that match the filters provided.

Expand Down Expand Up @@ -540,8 +540,8 @@ def _embedding_retrieval(
self,
query_embedding: list[float],
*,
namespace: Optional[str] = None,
filters: Optional[dict[str, Any]] = None,
namespace: str | None = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
) -> list[Document]:
"""
Expand Down Expand Up @@ -583,8 +583,8 @@ async def _embedding_retrieval_async(
self,
query_embedding: list[float],
*,
namespace: Optional[str] = None,
filters: Optional[dict[str, Any]] = None,
namespace: str | None = None,
filters: dict[str, Any] | None = None,
top_k: int = 10,
) -> list[Document]:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Optional
from typing import Any

from haystack.errors import FilterError

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


def _validate_filters(filters: Optional[dict[str, Any]]) -> None:
def _validate_filters(filters: dict[str, Any] | None) -> None:
"""
Helper method to validate filter syntax.
"""
Expand Down
2 changes: 1 addition & 1 deletion integrations/pinecone/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def assert_documents_are_equal(self, received: list[Document], expected: list[Do
assert len(received) == len(expected)
received.sort(key=lambda x: x.id)
expected.sort(key=lambda x: x.id)
for received_doc, expected_doc in zip(received, expected):
for received_doc, expected_doc in zip(received, expected, strict=True):
assert received_doc.meta == expected_doc.meta
assert received_doc.content == expected_doc.content
# unfortunately, Pinecone returns a slightly different embedding
Expand Down