Skip to content

Commit 5d77868

Browse files
authored
chore!: chroma - drop Python 3.9 and use X|Y typing (#2701)
1 parent 3942dd3 commit 5d77868

6 files changed

Lines changed: 37 additions & 43 deletions

File tree

integrations/chroma/pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ name = "chroma-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 = "John Doe", email = "jd@example.com" }]
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",
2221
"Programming Language :: Python :: 3.13",
2322
"Programming Language :: Python :: Implementation :: CPython",
2423
"Programming Language :: Python :: Implementation :: PyPy",
2524
]
26-
dependencies = ["haystack-ai>=2.11.0", "chromadb>=1.0.2"]
25+
dependencies = ["haystack-ai>=2.22.0", "chromadb>=1.0.2"]
2726

2827
[project.urls]
2928
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/chroma#readme"
@@ -78,7 +77,6 @@ disallow_incomplete_defs = true
7877
allow-direct-references = true
7978

8079
[tool.ruff]
81-
target-version = "py39"
8280
line-length = 120
8381

8482
[tool.ruff.lint]
@@ -129,10 +127,6 @@ ignore = [
129127
# Allow assertions
130128
"S101",
131129
]
132-
unfixable = [
133-
# Don't touch unused imports
134-
"F401",
135-
]
136130
exclude = ["example"]
137131

138132
[tool.ruff.lint.isort]

integrations/chroma/src/haystack_integrations/components/retrievers/chroma/retriever.py

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

5-
from typing import Any, Optional, Union
5+
from typing import Any
66

77
from haystack import Document, component, default_from_dict, default_to_dict
88
from haystack.document_stores.types import FilterPolicy
@@ -48,9 +48,9 @@ class ChromaQueryTextRetriever:
4848
def __init__(
4949
self,
5050
document_store: ChromaDocumentStore,
51-
filters: Optional[dict[str, Any]] = None,
51+
filters: dict[str, Any] | None = None,
5252
top_k: int = 10,
53-
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
53+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
5454
):
5555
"""
5656
:param document_store: an instance of `ChromaDocumentStore`.
@@ -69,8 +69,8 @@ def __init__(
6969
def run(
7070
self,
7171
query: str,
72-
filters: Optional[dict[str, Any]] = None,
73-
top_k: Optional[int] = None,
72+
filters: dict[str, Any] | None = None,
73+
top_k: int | None = None,
7474
) -> dict[str, Any]:
7575
"""
7676
Run the retriever on the given input data.
@@ -94,8 +94,8 @@ def run(
9494
async def run_async(
9595
self,
9696
query: str,
97-
filters: Optional[dict[str, Any]] = None,
98-
top_k: Optional[int] = None,
97+
filters: dict[str, Any] | None = None,
98+
top_k: int | None = None,
9999
) -> dict[str, Any]:
100100
"""
101101
Asynchronously run the retriever on the given input data.
@@ -161,9 +161,9 @@ class ChromaEmbeddingRetriever:
161161
def __init__(
162162
self,
163163
document_store: ChromaDocumentStore,
164-
filters: Optional[dict[str, Any]] = None,
164+
filters: dict[str, Any] | None = None,
165165
top_k: int = 10,
166-
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
166+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
167167
):
168168
"""
169169
:param document_store: an instance of `ChromaDocumentStore`.
@@ -182,8 +182,8 @@ def __init__(
182182
def run(
183183
self,
184184
query_embedding: list[float],
185-
filters: Optional[dict[str, Any]] = None,
186-
top_k: Optional[int] = None,
185+
filters: dict[str, Any] | None = None,
186+
top_k: int | None = None,
187187
) -> dict[str, Any]:
188188
"""
189189
Run the retriever on the given input data.
@@ -209,8 +209,8 @@ def run(
209209
async def run_async(
210210
self,
211211
query_embedding: list[float],
212-
filters: Optional[dict[str, Any]] = None,
213-
top_k: Optional[int] = None,
212+
filters: dict[str, Any] | None = None,
213+
top_k: int | None = None,
214214
) -> dict[str, Any]:
215215
"""
216216
Asynchronously run the retriever on the given input data.

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

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

55
from collections.abc import Sequence
6-
from typing import Any, Literal, Optional, cast
6+
from typing import Any, Literal, cast
77

88
import chromadb
99
from chromadb.api.models.AsyncCollection import AsyncCollection
@@ -36,12 +36,12 @@ def __init__(
3636
self,
3737
collection_name: str = "documents",
3838
embedding_function: str = "default",
39-
persist_path: Optional[str] = None,
40-
host: Optional[str] = None,
41-
port: Optional[int] = None,
39+
persist_path: str | None = None,
40+
host: str | None = None,
41+
port: int | None = None,
4242
distance_function: Literal["l2", "cosine", "ip"] = "l2",
43-
metadata: Optional[dict] = None,
44-
client_settings: Optional[dict[str, Any]] = None,
43+
metadata: dict | None = None,
44+
client_settings: dict[str, Any] | None = None,
4545
**embedding_function_params: Any,
4646
):
4747
"""
@@ -97,8 +97,8 @@ def __init__(
9797
self._host = host
9898
self._port = port
9999

100-
self._collection: Optional[chromadb.Collection] = None
101-
self._async_collection: Optional[AsyncCollection] = None
100+
self._collection: chromadb.Collection | None = None
101+
self._async_collection: AsyncCollection | None = None
102102

103103
def _ensure_initialized(self):
104104
if not self._collection:
@@ -208,7 +208,7 @@ async def _ensure_initialized_async(self):
208208
)
209209

210210
@staticmethod
211-
def _prepare_get_kwargs(filters: Optional[dict[str, Any]] = None) -> dict[str, Any]:
211+
def _prepare_get_kwargs(filters: dict[str, Any] | None = None) -> dict[str, Any]:
212212
"""
213213
Prepare kwargs for Chroma get operations.
214214
"""
@@ -226,7 +226,7 @@ def _prepare_get_kwargs(filters: Optional[dict[str, Any]] = None) -> dict[str, A
226226
return kwargs
227227

228228
@staticmethod
229-
def _prepare_query_kwargs(filters: Optional[dict[str, Any]] = None) -> dict[str, Any]:
229+
def _prepare_query_kwargs(filters: dict[str, Any] | None = None) -> dict[str, Any]:
230230
"""
231231
Prepare kwargs for Chroma query operations.
232232
"""
@@ -264,7 +264,7 @@ async def count_documents_async(self) -> int:
264264

265265
return value
266266

267-
def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
267+
def filter_documents(self, filters: dict[str, Any] | None = None) -> list[Document]:
268268
"""
269269
Returns the documents that match the filters provided.
270270
@@ -282,7 +282,7 @@ def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Doc
282282

283283
return self._get_result_to_documents(result)
284284

285-
async def filter_documents_async(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
285+
async def filter_documents_async(self, filters: dict[str, Any] | None = None) -> list[Document]:
286286
"""
287287
Asynchronously returns the documents that match the filters provided.
288288
@@ -353,7 +353,7 @@ def _prepare_metadata_update(
353353
return ids_to_update, updated_metadata
354354

355355
@staticmethod
356-
def _convert_document_to_chroma(doc: Document) -> Optional[dict[str, Any]]:
356+
def _convert_document_to_chroma(doc: Document) -> dict[str, Any] | None:
357357
"""
358358
Converts a Haystack Document to a Chroma document.
359359
"""
@@ -755,7 +755,7 @@ def search(
755755
self,
756756
queries: list[str],
757757
top_k: int,
758-
filters: Optional[dict[str, Any]] = None,
758+
filters: dict[str, Any] | None = None,
759759
) -> list[list[Document]]:
760760
"""
761761
Search the documents in the store using the provided text queries.
@@ -781,7 +781,7 @@ async def search_async(
781781
self,
782782
queries: list[str],
783783
top_k: int,
784-
filters: Optional[dict[str, Any]] = None,
784+
filters: dict[str, Any] | None = None,
785785
) -> list[list[Document]]:
786786
"""
787787
Asynchronously search the documents in the store using the provided text queries.
@@ -809,7 +809,7 @@ def search_embeddings(
809809
self,
810810
query_embeddings: list[list[float]],
811811
top_k: int,
812-
filters: Optional[dict[str, Any]] = None,
812+
filters: dict[str, Any] | None = None,
813813
) -> list[list[Document]]:
814814
"""
815815
Perform vector search on the stored document, pass the embeddings of the queries instead of their text.
@@ -837,7 +837,7 @@ async def search_embeddings_async(
837837
self,
838838
query_embeddings: list[list[float]],
839839
top_k: int,
840-
filters: Optional[dict[str, Any]] = None,
840+
filters: dict[str, Any] | None = None,
841841
) -> list[list[Document]]:
842842
"""
843843
Asynchronously perform vector search on the stored document, pass the embeddings of the queries instead of

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from collections import defaultdict
66
from dataclasses import dataclass
7-
from typing import Any, Optional, cast
7+
from typing import Any, cast
88

99
from chromadb.api.types import WhereDocument, validate_where, validate_where_document
1010

@@ -38,8 +38,8 @@ class ChromaFilter:
3838
"""
3939

4040
ids: list[str]
41-
where: Optional[dict[str, Any]]
42-
where_document: Optional[dict[str, Any]]
41+
where: dict[str, Any] | None
42+
where_document: dict[str, Any] | None
4343

4444

4545
def _convert_filters(filters: dict[str, Any]) -> ChromaFilter:

integrations/chroma/tests/test_document_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def assert_documents_are_equal(self, received: list[Document], expected: list[Do
6464
received.sort(key=operator.attrgetter("id"))
6565
expected.sort(key=operator.attrgetter("id"))
6666

67-
for doc_received, doc_expected in zip(received, expected):
67+
for doc_received, doc_expected in zip(received, expected, strict=True):
6868
assert doc_received.content == doc_expected.content
6969
assert doc_received.meta == doc_expected.meta
7070

integrations/chroma/tests/test_document_store_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def assert_documents_are_equal(received: list[Document], expected: list[Document
4747
received.sort(key=operator.attrgetter("id"))
4848
expected.sort(key=operator.attrgetter("id"))
4949

50-
for doc_received, doc_expected in zip(received, expected):
50+
for doc_received, doc_expected in zip(received, expected, strict=True):
5151
assert doc_received.content == doc_expected.content
5252
assert doc_received.meta == doc_expected.meta
5353

0 commit comments

Comments
 (0)