Skip to content

Commit 989affc

Browse files
authored
chore!: azure_ai_search - drop Python 3.9 and use X|Y typing (#2695)
1 parent 8094d0d commit 989affc

6 files changed

Lines changed: 27 additions & 33 deletions

File tree

integrations/azure_ai_search/pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ name = "azure-ai-search-haystack"
77
dynamic = ["version"]
88
description = 'Haystack 2.x Document Store for Azure AI Search'
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", 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",
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", "azure-search-documents>=11.5", "azure-identity"]
25+
dependencies = ["haystack-ai>=2.22.0", "azure-search-documents>=11.5", "azure-identity"]
2726

2827
[project.urls]
2928
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/azure_ai_search#readme"
@@ -80,7 +79,6 @@ allow-direct-references = true
8079

8180

8281
[tool.ruff]
83-
target-version = "py39"
8482
line-length = 120
8583

8684
[tool.ruff.lint]
@@ -127,10 +125,6 @@ ignore = [
127125
"PLR0913",
128126
"PLR0915",
129127
]
130-
unfixable = [
131-
# Don't touch unused imports
132-
"F401",
133-
]
134128
exclude = ["example"]
135129

136130
[tool.ruff.lint.isort]

integrations/azure_ai_search/src/haystack_integrations/components/retrievers/azure_ai_search/bm25_retriever.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Union
1+
from typing import Any
22

33
from haystack import Document, component, default_from_dict, default_to_dict, logging
44
from haystack.document_stores.types import FilterPolicy
@@ -21,9 +21,9 @@ def __init__(
2121
self,
2222
*,
2323
document_store: AzureAISearchDocumentStore,
24-
filters: Optional[dict[str, Any]] = None,
24+
filters: dict[str, Any] | None = None,
2525
top_k: int = 10,
26-
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
26+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
2727
**kwargs: Any,
2828
):
2929
"""
@@ -97,7 +97,7 @@ def from_dict(cls, data: dict[str, Any]) -> "AzureAISearchBM25Retriever":
9797

9898
@component.output_types(documents=list[Document])
9999
def run(
100-
self, query: str, filters: Optional[dict[str, Any]] = None, top_k: Optional[int] = None
100+
self, query: str, filters: dict[str, Any] | None = None, top_k: int | None = None
101101
) -> dict[str, list[Document]]:
102102
"""Retrieve documents from the AzureAISearchDocumentStore.
103103

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Union
1+
from typing import Any
22

33
from haystack import Document, component, default_from_dict, default_to_dict, logging
44
from haystack.document_stores.types import FilterPolicy
@@ -21,9 +21,9 @@ def __init__(
2121
self,
2222
*,
2323
document_store: AzureAISearchDocumentStore,
24-
filters: Optional[dict[str, Any]] = None,
24+
filters: dict[str, Any] | None = None,
2525
top_k: int = 10,
26-
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
26+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
2727
**kwargs: Any,
2828
):
2929
"""
@@ -94,7 +94,7 @@ def from_dict(cls, data: dict[str, Any]) -> "AzureAISearchEmbeddingRetriever":
9494

9595
@component.output_types(documents=list[Document])
9696
def run(
97-
self, query_embedding: list[float], filters: Optional[dict[str, Any]] = None, top_k: Optional[int] = None
97+
self, query_embedding: list[float], filters: dict[str, Any] | None = None, top_k: int | None = None
9898
) -> dict[str, list[Document]]:
9999
"""Retrieve documents from the AzureAISearchDocumentStore.
100100

integrations/azure_ai_search/src/haystack_integrations/components/retrievers/azure_ai_search/hybrid_retriever.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Union
1+
from typing import Any
22

33
from haystack import Document, component, default_from_dict, default_to_dict, logging
44
from haystack.document_stores.types import FilterPolicy
@@ -21,9 +21,9 @@ def __init__(
2121
self,
2222
*,
2323
document_store: AzureAISearchDocumentStore,
24-
filters: Optional[dict[str, Any]] = None,
24+
filters: dict[str, Any] | None = None,
2525
top_k: int = 10,
26-
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
26+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
2727
**kwargs: Any,
2828
):
2929
"""
@@ -100,8 +100,8 @@ def run(
100100
self,
101101
query: str,
102102
query_embedding: list[float],
103-
filters: Optional[dict[str, Any]] = None,
104-
top_k: Optional[int] = None,
103+
filters: dict[str, Any] | None = None,
104+
top_k: int | None = None,
105105
) -> dict[str, list[Document]]:
106106
"""Retrieve documents from the AzureAISearchDocumentStore.
107107

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

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

55
import logging as python_logging
66
from datetime import datetime
7-
from typing import Any, Optional, Union
7+
from typing import Any
88

99
from azure.core.credentials import AzureKeyCredential
1010
from azure.core.exceptions import (
@@ -100,8 +100,8 @@ def __init__(
100100
azure_endpoint: Secret = Secret.from_env_var("AZURE_AI_SEARCH_ENDPOINT", strict=True), # noqa: B008
101101
index_name: str = "default",
102102
embedding_dimension: int = 768,
103-
metadata_fields: Optional[dict[str, Union[SearchField, type]]] = None,
104-
vector_search_configuration: Optional[VectorSearch] = None,
103+
metadata_fields: dict[str, SearchField | type] | None = None,
104+
vector_search_configuration: VectorSearch | None = None,
105105
include_search_metadata: bool = False,
106106
**index_creation_kwargs: Any,
107107
):
@@ -148,8 +148,8 @@ def __init__(
148148
149149
For more information on parameters, see the [official Azure AI Search documentation](https://learn.microsoft.com/en-us/azure/search/).
150150
"""
151-
self._client: Optional[SearchClient] = None
152-
self._index_client: Optional[SearchIndexClient] = None
151+
self._client: SearchClient | None = None
152+
self._index_client: SearchIndexClient | None = None
153153
self._index_fields = [] # type: list[Any] # stores all fields in the final schema of index
154154
self._api_key = api_key
155155
self._azure_endpoint = azure_endpoint
@@ -202,7 +202,7 @@ def client(self) -> SearchClient:
202202

203203
@staticmethod
204204
def _normalize_metadata_index_fields(
205-
metadata_fields: Optional[dict[str, Union[SearchField, type]]],
205+
metadata_fields: dict[str, SearchField | type] | None,
206206
) -> dict[str, SearchField]:
207207
"""Create a list of index fields for storing metadata values."""
208208

@@ -516,7 +516,7 @@ def search_documents(self, search_text: str = "*", top_k: int = 10) -> list[Docu
516516
result = self.client.search(search_text=search_text, top=top_k)
517517
return self._convert_search_result_to_documents(list(result))
518518

519-
def filter_documents(self, filters: Optional[dict[str, Any]] = None) -> list[Document]:
519+
def filter_documents(self, filters: dict[str, Any] | None = None) -> list[Document]:
520520
"""
521521
Returns the documents that match the provided filters.
522522
Filters should be given as a dictionary supporting filtering by metadata. For details on
@@ -567,7 +567,7 @@ def _convert_search_result_to_documents(self, azure_docs: list[dict[str, Any]])
567567
documents.append(doc)
568568
return documents
569569

570-
def _index_exists(self, index_name: Optional[str]) -> bool:
570+
def _index_exists(self, index_name: str | None) -> bool:
571571
"""
572572
Check if the index exists in the Azure AI Search service.
573573
@@ -614,7 +614,7 @@ def _embedding_retrieval(
614614
query_embedding: list[float],
615615
*,
616616
top_k: int = 10,
617-
filters: Optional[str] = None,
617+
filters: str | None = None,
618618
**kwargs: Any,
619619
) -> list[Document]:
620620
"""
@@ -648,7 +648,7 @@ def _bm25_retrieval(
648648
self,
649649
query: str,
650650
top_k: int = 10,
651-
filters: Optional[str] = None,
651+
filters: str | None = None,
652652
**kwargs: Any,
653653
) -> list[Document]:
654654
"""
@@ -681,7 +681,7 @@ def _hybrid_retrieval(
681681
query: str,
682682
query_embedding: list[float],
683683
top_k: int = 10,
684-
filters: Optional[str] = None,
684+
filters: str | None = None,
685685
**kwargs: Any,
686686
) -> list[Document]:
687687
"""

integrations/azure_ai_search/tests/test_document_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def _assert_documents_are_equal(received: list[Document], expected: list[Documen
243243
sorted_expected = sorted(expected, key=lambda doc: doc.id)
244244
assert len(sorted_received) == len(sorted_expected)
245245

246-
for received_doc, expected_doc in zip(sorted_received, sorted_expected):
246+
for received_doc, expected_doc in zip(sorted_received, sorted_expected, strict=True):
247247
# Compare all attributes except score
248248
assert received_doc.id == expected_doc.id
249249
assert received_doc.content == expected_doc.content

0 commit comments

Comments
 (0)