88import chromadb
99from chromadb .api .models .AsyncCollection import AsyncCollection
1010from chromadb .api .types import GetResult , Metadata , OneOrMany , QueryResult
11+ from chromadb .config import Settings
1112from haystack import default_from_dict , default_to_dict , logging
1213from haystack .dataclasses import Document
1314from haystack .document_stores .errors import DocumentStoreError
@@ -40,6 +41,7 @@ def __init__(
4041 port : Optional [int ] = None ,
4142 distance_function : Literal ["l2" , "cosine" , "ip" ] = "l2" ,
4243 metadata : Optional [dict ] = None ,
44+ client_settings : Optional [dict [str , Any ]] = None ,
4345 ** embedding_function_params : Any ,
4446 ):
4547 """
@@ -67,6 +69,11 @@ def __init__(
6769 :param metadata: a dictionary of chromadb collection parameters passed directly to chromadb's client
6870 method `create_collection`. If it contains the key `"hnsw:space"`, the value will take precedence over the
6971 `distance_function` parameter above.
72+ :param client_settings: a dictionary of Chroma Settings configuration options passed to
73+ `chromadb.config.Settings`. These settings configure the underlying Chroma client behavior.
74+ For available options, see [Chroma's config.py](https://github.com/chroma-core/chroma/blob/main/chromadb/config.py).
75+ **Note**: specifying these settings may interfere with standard client initialization parameters.
76+ This option is intended for advanced customization.
7077 :param embedding_function_params: additional parameters to pass to the embedding function.
7178 """
7279
@@ -84,6 +91,7 @@ def __init__(
8491 self ._embedding_function_params = embedding_function_params
8592 self ._distance_function = distance_function
8693 self ._metadata = metadata
94+ self ._client_settings = client_settings
8795
8896 self ._persist_path = persist_path
8997 self ._host = host
@@ -102,18 +110,29 @@ def _ensure_initialized(self):
102110 "You cannot specify both options."
103111 )
104112 raise ValueError (error_message )
113+
114+ # Use dict to conditionally pass settings because Chroma doesn't accept settings=None
115+ client_kwargs : dict [str , Any ] = {}
116+ if self ._client_settings :
117+ try :
118+ client_kwargs ["settings" ] = Settings (** self ._client_settings )
119+ except ValueError as e :
120+ msg = f"Invalid client_settings ({ self ._client_settings } ): { e } "
121+ raise ValueError (msg ) from e
122+
105123 if self ._host and self ._port is not None :
106124 # Remote connection via HTTP client
107125 client = chromadb .HttpClient (
108126 host = self ._host ,
109127 port = self ._port ,
128+ ** client_kwargs ,
110129 )
111130 elif self ._persist_path is None :
112131 # In-memory storage
113- client = chromadb .Client ()
132+ client = chromadb .Client (** client_kwargs )
114133 else :
115134 # Local persistent storage
116- client = chromadb .PersistentClient (path = self ._persist_path )
135+ client = chromadb .PersistentClient (path = self ._persist_path , ** client_kwargs )
117136
118137 self ._client = client # store client for potential future use
119138
@@ -148,9 +167,19 @@ async def _ensure_initialized_async(self):
148167 )
149168 raise ValueError (error_message )
150169
170+ # Use dict to conditionally pass settings because Chroma doesn't accept settings=None
171+ client_kwargs : dict [str , Any ] = {}
172+ if self ._client_settings :
173+ try :
174+ client_kwargs ["settings" ] = Settings (** self ._client_settings )
175+ except ValueError as e :
176+ msg = f"Invalid client_settings ({ self ._client_settings } ): { e } "
177+ raise ValueError (msg ) from e
178+
151179 client = await chromadb .AsyncHttpClient (
152180 host = self ._host ,
153181 port = self ._port ,
182+ ** client_kwargs ,
154183 )
155184
156185 self ._async_client = client # store client for potential future use
@@ -862,6 +891,7 @@ def to_dict(self) -> dict[str, Any]:
862891 host = self ._host ,
863892 port = self ._port ,
864893 distance_function = self ._distance_function ,
894+ client_settings = self ._client_settings ,
865895 ** self ._embedding_function_params ,
866896 )
867897
0 commit comments