|
4 | 4 |
|
5 | 5 | import logging as python_logging |
6 | 6 | from datetime import datetime |
7 | | -from typing import Any, Optional, Union |
| 7 | +from typing import Any |
8 | 8 |
|
9 | 9 | from azure.core.credentials import AzureKeyCredential |
10 | 10 | from azure.core.exceptions import ( |
@@ -100,8 +100,8 @@ def __init__( |
100 | 100 | azure_endpoint: Secret = Secret.from_env_var("AZURE_AI_SEARCH_ENDPOINT", strict=True), # noqa: B008 |
101 | 101 | index_name: str = "default", |
102 | 102 | 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, |
105 | 105 | include_search_metadata: bool = False, |
106 | 106 | **index_creation_kwargs: Any, |
107 | 107 | ): |
@@ -148,8 +148,8 @@ def __init__( |
148 | 148 |
|
149 | 149 | For more information on parameters, see the [official Azure AI Search documentation](https://learn.microsoft.com/en-us/azure/search/). |
150 | 150 | """ |
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 |
153 | 153 | self._index_fields = [] # type: list[Any] # stores all fields in the final schema of index |
154 | 154 | self._api_key = api_key |
155 | 155 | self._azure_endpoint = azure_endpoint |
@@ -202,7 +202,7 @@ def client(self) -> SearchClient: |
202 | 202 |
|
203 | 203 | @staticmethod |
204 | 204 | def _normalize_metadata_index_fields( |
205 | | - metadata_fields: Optional[dict[str, Union[SearchField, type]]], |
| 205 | + metadata_fields: dict[str, SearchField | type] | None, |
206 | 206 | ) -> dict[str, SearchField]: |
207 | 207 | """Create a list of index fields for storing metadata values.""" |
208 | 208 |
|
@@ -516,7 +516,7 @@ def search_documents(self, search_text: str = "*", top_k: int = 10) -> list[Docu |
516 | 516 | result = self.client.search(search_text=search_text, top=top_k) |
517 | 517 | return self._convert_search_result_to_documents(list(result)) |
518 | 518 |
|
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]: |
520 | 520 | """ |
521 | 521 | Returns the documents that match the provided filters. |
522 | 522 | 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]]) |
567 | 567 | documents.append(doc) |
568 | 568 | return documents |
569 | 569 |
|
570 | | - def _index_exists(self, index_name: Optional[str]) -> bool: |
| 570 | + def _index_exists(self, index_name: str | None) -> bool: |
571 | 571 | """ |
572 | 572 | Check if the index exists in the Azure AI Search service. |
573 | 573 |
|
@@ -614,7 +614,7 @@ def _embedding_retrieval( |
614 | 614 | query_embedding: list[float], |
615 | 615 | *, |
616 | 616 | top_k: int = 10, |
617 | | - filters: Optional[str] = None, |
| 617 | + filters: str | None = None, |
618 | 618 | **kwargs: Any, |
619 | 619 | ) -> list[Document]: |
620 | 620 | """ |
@@ -648,7 +648,7 @@ def _bm25_retrieval( |
648 | 648 | self, |
649 | 649 | query: str, |
650 | 650 | top_k: int = 10, |
651 | | - filters: Optional[str] = None, |
| 651 | + filters: str | None = None, |
652 | 652 | **kwargs: Any, |
653 | 653 | ) -> list[Document]: |
654 | 654 | """ |
@@ -681,7 +681,7 @@ def _hybrid_retrieval( |
681 | 681 | query: str, |
682 | 682 | query_embedding: list[float], |
683 | 683 | top_k: int = 10, |
684 | | - filters: Optional[str] = None, |
| 684 | + filters: str | None = None, |
685 | 685 | **kwargs: Any, |
686 | 686 | ) -> list[Document]: |
687 | 687 | """ |
|
0 commit comments