Skip to content

Commit 0734e97

Browse files
anakin87davidsbatista
authored andcommitted
chore!: jina - drop Python 3.9 and use X|Y typing (#2708)
1 parent 7a4e80a commit 0734e97

6 files changed

Lines changed: 27 additions & 33 deletions

File tree

integrations/jina/pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "jina-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 = [
@@ -17,15 +17,14 @@ classifiers = [
1717
"License :: OSI Approved :: Apache Software License",
1818
"Development Status :: 4 - Beta",
1919
"Programming Language :: Python",
20-
"Programming Language :: Python :: 3.9",
2120
"Programming Language :: Python :: 3.10",
2221
"Programming Language :: Python :: 3.11",
2322
"Programming Language :: Python :: 3.12",
2423
"Programming Language :: Python :: 3.13",
2524
"Programming Language :: Python :: Implementation :: CPython",
2625
"Programming Language :: Python :: Implementation :: PyPy",
2726
]
28-
dependencies = ["requests>=2.25.0", "haystack-ai>=2.16.1"]
27+
dependencies = ["requests>=2.25.0", "haystack-ai>=2.22.0"]
2928

3029
[project.urls]
3130
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/jina#readme"
@@ -79,7 +78,6 @@ check_untyped_defs = true
7978
disallow_incomplete_defs = true
8079

8180
[tool.ruff]
82-
target-version = "py39"
8381
line-length = 120
8482

8583
[tool.ruff.lint]
@@ -123,10 +121,6 @@ ignore = [
123121
"PLR0913",
124122
"PLR0915",
125123
]
126-
unfixable = [
127-
# Don't touch unused imports
128-
"F401",
129-
]
130124

131125
[tool.ruff.lint.isort]
132126
known-first-party = ["haystack_integrations"]

integrations/jina/src/haystack_integrations/components/connectors/jina/reader.py

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

55
import json
6-
from typing import Any, Optional, Union
6+
from typing import Any
77
from urllib.parse import quote
88

99
import requests
@@ -42,7 +42,7 @@ class JinaReaderConnector:
4242

4343
def __init__(
4444
self,
45-
mode: Union[JinaReaderMode, str],
45+
mode: JinaReaderMode | str,
4646
api_key: Secret = Secret.from_env_var("JINA_API_KEY"), # noqa: B008
4747
json_response: bool = True,
4848
):
@@ -104,7 +104,7 @@ def _json_to_document(self, data: dict) -> Document:
104104
return document
105105

106106
@component.output_types(documents=list[Document])
107-
def run(self, query: str, headers: Optional[dict[str, str]] = None) -> dict[str, list[Document]]:
107+
def run(self, query: str, headers: dict[str, str] | None = None) -> dict[str, list[Document]]:
108108
"""
109109
Process the query/URL using the Jina AI reader service.
110110

integrations/jina/src/haystack_integrations/components/embedders/jina/document_embedder.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
4+
from typing import Any
55

66
import requests
77
from haystack import Document, component, default_from_dict, default_to_dict
@@ -43,11 +43,11 @@ def __init__(
4343
suffix: str = "",
4444
batch_size: int = 32,
4545
progress_bar: bool = True,
46-
meta_fields_to_embed: Optional[list[str]] = None,
46+
meta_fields_to_embed: list[str] | None = None,
4747
embedding_separator: str = "\n",
48-
task: Optional[str] = None,
49-
dimensions: Optional[int] = None,
50-
late_chunking: Optional[bool] = None,
48+
task: str | None = None,
49+
dimensions: int | None = None,
50+
late_chunking: bool | None = None,
5151
):
5252
"""
5353
Create a JinaDocumentEmbedder component.
@@ -156,7 +156,7 @@ def _prepare_texts_to_embed(self, documents: list[Document]) -> list[str]:
156156
return texts_to_embed
157157

158158
def _embed_batch(
159-
self, texts_to_embed: list[str], batch_size: int, parameters: Optional[dict] = None
159+
self, texts_to_embed: list[str], batch_size: int, parameters: dict | None = None
160160
) -> tuple[list[list[float]], dict[str, Any]]:
161161
"""
162162
Embed a list of texts in batches.
@@ -219,7 +219,7 @@ def run(self, documents: list[Document]) -> dict[str, Any]:
219219
texts_to_embed=texts_to_embed, batch_size=self.batch_size, parameters=parameters
220220
)
221221

222-
for doc, emb in zip(documents, embeddings):
222+
for doc, emb in zip(documents, embeddings, strict=True):
223223
doc.embedding = emb
224224

225225
return {"documents": documents, "meta": metadata}

integrations/jina/src/haystack_integrations/components/embedders/jina/document_image_embedder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
from dataclasses import replace
5-
from typing import Any, Optional
5+
from typing import Any
66

77
import requests
88
from haystack import Document, component, default_from_dict, default_to_dict, logging
@@ -58,9 +58,9 @@ def __init__(
5858
api_key: Secret = Secret.from_env_var("JINA_API_KEY"), # noqa: B008
5959
model: str = "jina-clip-v2",
6060
file_path_meta_field: str = "file_path",
61-
root_path: Optional[str] = None,
62-
embedding_dimension: Optional[int] = None,
63-
image_size: Optional[tuple[int, int]] = None,
61+
root_path: str | None = None,
62+
embedding_dimension: int | None = None,
63+
image_size: tuple[int, int] | None = None,
6464
batch_size: int = 5,
6565
):
6666
"""
@@ -166,7 +166,7 @@ def _extract_images_to_embed(self, documents: list[Document]) -> list[str]:
166166
documents=documents, file_path_meta_field=self.file_path_meta_field, root_path=self.root_path
167167
)
168168

169-
images_to_embed: list[Optional[str]] = [None] * len(documents)
169+
images_to_embed: list[str | None] = [None] * len(documents)
170170
pdf_page_infos: list[_PDFPageInfo] = []
171171

172172
for doc_idx, image_source_info in enumerate(images_source_info):
@@ -256,7 +256,7 @@ def run(self, documents: list[Document]) -> dict[str, list[Document]]:
256256
embeddings.extend(batch_embeddings)
257257

258258
docs_with_embeddings = []
259-
for doc, emb in zip(documents, embeddings):
259+
for doc, emb in zip(documents, embeddings, strict=True):
260260
# we store this information for later inspection
261261
new_meta = {
262262
**doc.meta,

integrations/jina/src/haystack_integrations/components/embedders/jina/text_embedder.py

Lines changed: 4 additions & 4 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
import requests
77
from haystack import component, default_from_dict, default_to_dict
@@ -39,9 +39,9 @@ def __init__(
3939
model: str = "jina-embeddings-v3",
4040
prefix: str = "",
4141
suffix: str = "",
42-
task: Optional[str] = None,
43-
dimensions: Optional[int] = None,
44-
late_chunking: Optional[bool] = None,
42+
task: str | None = None,
43+
dimensions: int | None = None,
44+
late_chunking: bool | None = None,
4545
):
4646
"""
4747
Create a JinaTextEmbedder component.

integrations/jina/src/haystack_integrations/components/rankers/jina/ranker.py

Lines changed: 5 additions & 5 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
import requests
77
from haystack import Document, component, default_from_dict, default_to_dict
@@ -33,8 +33,8 @@ def __init__(
3333
self,
3434
model: str = "jina-reranker-v1-base-en",
3535
api_key: Secret = Secret.from_env_var("JINA_API_KEY"), # noqa: B008,
36-
top_k: Optional[int] = None,
37-
score_threshold: Optional[float] = None,
36+
top_k: int | None = None,
37+
score_threshold: float | None = None,
3838
):
3939
"""
4040
Creates an instance of JinaRanker.
@@ -107,8 +107,8 @@ def run(
107107
self,
108108
query: str,
109109
documents: list[Document],
110-
top_k: Optional[int] = None,
111-
score_threshold: Optional[float] = None,
110+
top_k: int | None = None,
111+
score_threshold: float | None = None,
112112
):
113113
"""
114114
Returns a list of Documents ranked by their similarity to the given query.

0 commit comments

Comments
 (0)