From a2830e3056e4e616160b150bf5ea212a97df2dc4 Mon Sep 17 00:00:00 2001 From: imaprogrammer <46126206+nb-programmer@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:50:27 +0530 Subject: [PATCH] Update chroma.py: Persist directory from client_settings if provided there (#7087) Change details: - Description: When calling db.persist(), a check prevents from it proceeding as the constructor only sets member `_persist_directory` from parameters. But the ChromaDB client settings also has this parameter, and if the client_settings parameter is used without passing the persist_directory (which is optional), the `persist` method raises `ValueError` for not setting `_persist_directory`. This change fixes it by setting the member `_persist_directory` variable from client_settings if it is set, else uses the constructor parameter. - Issue: I didn't find any github issue of this, but I discovered it after calling the persist method - Dependencies: None - Tag maintainer: vectorstore related change - @rlancemartin, @eyurtsev - Twitter handle: Don't have one :( *Additional discussion*: We may need to discuss the way I implemented the fallback using `or`. --------- Co-authored-by: rlm --- langchain/vectorstores/chroma.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/langchain/vectorstores/chroma.py b/langchain/vectorstores/chroma.py index 47d3b4a149..c9eca71372 100644 --- a/langchain/vectorstores/chroma.py +++ b/langchain/vectorstores/chroma.py @@ -90,7 +90,9 @@ class Chroma(VectorStore): self._client = chromadb.Client(self._client_settings) self._embedding_function = embedding_function - self._persist_directory = persist_directory + self._persist_directory = ( + self._client_settings.persist_directory or persist_directory + ) self._collection = self._client.get_or_create_collection( name=collection_name, embedding_function=self._embedding_function.embed_documents