From f190bc3e83d6ba2c1e4ed236cda8c11b09542c64 Mon Sep 17 00:00:00 2001 From: Kristelle Widjaja <133298344+kristellewidjaja@users.noreply.github.com> Date: Tue, 1 Aug 2023 15:31:35 -0500 Subject: [PATCH] Bug fix: feature/issue-7804-chroma-client_settings-bug (#8267) Description: Made Chroma constructor more robust when client_settings is provided. Otherwise, existing embeddings will not be loaded correctly from Chroma. Issue: #7804 Dependencies: None Tag maintainer: @rlancemartin, @eyurtsev --------- Co-authored-by: Bagatur --- libs/langchain/langchain/vectorstores/chroma.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/langchain/langchain/vectorstores/chroma.py b/libs/langchain/langchain/vectorstores/chroma.py index 87e71995bc..59edb26831 100644 --- a/libs/langchain/langchain/vectorstores/chroma.py +++ b/libs/langchain/langchain/vectorstores/chroma.py @@ -92,6 +92,17 @@ class Chroma(VectorStore): self._persist_directory = persist_directory else: if client_settings: + # If client_settings is provided with persist_directory specified, + # then it is "in-memory and persisting to disk" mode. + client_settings.persist_directory = ( + persist_directory or client_settings.persist_directory + ) + if client_settings.persist_directory is not None: + # Maintain backwards compatibility with chromadb < 0.4.0 + major, minor, _ = chromadb.__version__.split(".") + if int(major) == 0 and int(minor) < 4: + client_settings.chroma_db_impl = "duckdb+parquet" + _client_settings = client_settings elif persist_directory: # Maintain backwards compatibility with chromadb < 0.4.0