33# SPDX-License-Identifier: Apache-2.0
44
55from collections .abc import Sequence
6- from typing import Any , Literal , Optional , cast
6+ from typing import Any , Literal , cast
77
88import chromadb
99from 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
0 commit comments