-
Notifications
You must be signed in to change notification settings - Fork 204
feat: add client_settings to ChromaDocumentStore
#2651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3d72acf
Add client_settings param
SaraCalla 8b3f8ad
ruff fixes
SaraCalla e4e8708
fix integration mark in async tests
SaraCalla 069e9f3
handle invalid client_settings
SaraCalla 9458a8c
Merge branch 'main' into chroma_client_settings
SaraCalla 4d0a07c
Merge branch 'main' into chroma_client_settings
SaraCalla 6792471
Merge branch 'main' into chroma_client_settings
SaraCalla 5d5a952
Merge branch 'main' into chroma_client_settings
SaraCalla d41ab9c
apply PR comments
SaraCalla 4b4b96c
Merge branch 'main' into chroma_client_settings
SaraCalla d41c334
add comments and clearer error messages
SaraCalla 3347d26
Merge branch 'main' into chroma_client_settings
SaraCalla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import chromadb | ||
| from chromadb.api.models.AsyncCollection import AsyncCollection | ||
| from chromadb.api.types import GetResult, Metadata, OneOrMany, QueryResult | ||
| from chromadb.config import Settings | ||
| from haystack import default_from_dict, default_to_dict, logging | ||
| from haystack.dataclasses import Document | ||
| from haystack.document_stores.errors import DocumentStoreError | ||
|
|
@@ -40,6 +41,7 @@ def __init__( | |
| port: Optional[int] = None, | ||
| distance_function: Literal["l2", "cosine", "ip"] = "l2", | ||
| metadata: Optional[dict] = None, | ||
| client_settings: Optional[dict[str, Any]] = None, | ||
| **embedding_function_params: Any, | ||
| ): | ||
| """ | ||
|
|
@@ -67,6 +69,8 @@ def __init__( | |
| :param metadata: a dictionary of chromadb collection parameters passed directly to chromadb's client | ||
| method `create_collection`. If it contains the key `"hnsw:space"`, the value will take precedence over the | ||
| `distance_function` parameter above. | ||
| :param client_settings: a dictionary of Chroma Settings configuration options passed to | ||
| `chromadb.config.Settings`. These settings configure the underlying Chroma client behavior. | ||
| :param embedding_function_params: additional parameters to pass to the embedding function. | ||
| """ | ||
|
|
||
|
|
@@ -84,6 +88,7 @@ def __init__( | |
| self._embedding_function_params = embedding_function_params | ||
| self._distance_function = distance_function | ||
| self._metadata = metadata | ||
| self._client_settings = client_settings | ||
|
|
||
| self._persist_path = persist_path | ||
| self._host = host | ||
|
|
@@ -102,18 +107,28 @@ def _ensure_initialized(self): | |
| "You cannot specify both options." | ||
| ) | ||
| raise ValueError(error_message) | ||
|
|
||
| client_kwargs: dict[str, Any] = {} | ||
anakin87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if self._client_settings: | ||
| try: | ||
| client_kwargs["settings"] = Settings(**self._client_settings) | ||
| except Exception as e: | ||
anakin87 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| msg = f"Invalid client_settings: {e}" | ||
|
||
| raise ValueError(msg) from e | ||
|
|
||
| if self._host and self._port is not None: | ||
| # Remote connection via HTTP client | ||
| client = chromadb.HttpClient( | ||
| host=self._host, | ||
| port=self._port, | ||
| **client_kwargs, | ||
| ) | ||
| elif self._persist_path is None: | ||
| # In-memory storage | ||
| client = chromadb.Client() | ||
| client = chromadb.Client(**client_kwargs) | ||
| else: | ||
| # Local persistent storage | ||
| client = chromadb.PersistentClient(path=self._persist_path) | ||
| client = chromadb.PersistentClient(path=self._persist_path, **client_kwargs) | ||
|
|
||
| self._client = client # store client for potential future use | ||
|
|
||
|
|
@@ -148,9 +163,18 @@ async def _ensure_initialized_async(self): | |
| ) | ||
| raise ValueError(error_message) | ||
|
|
||
| client_kwargs: dict[str, Any] = {} | ||
| if self._client_settings: | ||
| try: | ||
| client_kwargs["settings"] = Settings(**self._client_settings) | ||
| except Exception as e: | ||
| msg = f"Invalid client_settings: {e}" | ||
| raise ValueError(msg) from e | ||
|
|
||
| client = await chromadb.AsyncHttpClient( | ||
| host=self._host, | ||
| port=self._port, | ||
| **client_kwargs, | ||
| ) | ||
|
|
||
| self._async_client = client # store client for potential future use | ||
|
|
@@ -862,6 +886,7 @@ def to_dict(self) -> dict[str, Any]: | |
| host=self._host, | ||
| port=self._port, | ||
| distance_function=self._distance_function, | ||
| client_settings=self._client_settings, | ||
| **self._embedding_function_params, | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.