Closed ecerulm closed 1 year ago
Answer generated by a π€
I understand that you're encountering an AttributeError
when trying to initialize a Chroma
object with a pre-existing client
. This error is happening because the _client_settings
attribute is only set when a client
is not provided. If a client
is provided, _client_settings
is not set, which leads to the AttributeError
when it is accessed later.
To address this issue, you can modify the __init__
method of the Chroma
class to ensure the _client_settings
attribute is always set. Here's how you can do it:
def __init__(
self,
collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
embedding_function: Optional[Embeddings] = None,
persist_directory: Optional[str] = None,
client_settings: Optional[chromadb.config.Settings] = None,
collection_metadata: Optional[Dict] = None,
client: Optional[chromadb.Client] = None,
) -> None:
"""Initialize with Chroma client."""
try:
import chromadb
import chromadb.config
except ImportError:
raise ValueError(
"Could not import chromadb python package. "
"Please install it with `pip install chromadb`."
)
if client is not None:
self._client = client
self._client_settings = client.settings # Assuming the client object has a settings attribute
else:
if client_settings:
self._client_settings = client_settings
else:
self._client_settings = chromadb.config.Settings()
if persist_directory is not None:
self._client_settings = chromadb.config.Settings(
chroma_db_impl="duckdb+parquet",
persist_directory=persist_directory,
)
self._client = chromadb.Client(self._client_settings)
This solution assumes that the client
object has a settings
attribute. If it doesn't, you'll need to adjust the code accordingly.
Please note that this is one potential solution based on the information provided. If this doesn't resolve your issue or if your experience contradicts this solution, I recommend checking if you're using the latest version of the software as the issue might have been addressed in a more recent update.
If you believe this is a bug that could impact other users and you're comfortable with the proposed solution, I encourage you to make a pull request with this change. Your contribution could help improve the experience for others using this software.
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a π if this is helpful and π if it is irrelevant.
The workaround is to downgrade to langchain==0.0.226
Can this be merged ? I'm waiting on this fix. Thanks ps i'm solving it for the moment using
Chroma._client_settings= chromadb.config.Settings
Chroma._client_settings.persist_directory = None
System Info
on Python 3.10.10
with requirements.txt
Who can help?
@hwchase17
Information
Related Components
Reproduction
I'm getting
AttributeError: 'Chroma' object has no attribute '_client_settings'
when runningthe traceback is
Expected behavior
It should not raise an exception,
It seems to me that https://github.com/hwchase17/langchain/blob/5eec74d9a5435c671382e69412072a8725b2ec60/langchain/vectorstores/chroma.py#L93-L95
was introduced by commit https://github.com/hwchase17/langchain/commit/a2830e3056e4e616160b150bf5ea212a97df2dc4 from @nb-programmer and @rlancemartin
that commit assumes that self._client_settings exists always when in reality that won't be created if a client is passed