From 10246375a5fad74412682f5d8fba123d4da29b17 Mon Sep 17 00:00:00 2001 From: Gergely Papp Date: Wed, 19 Jul 2023 02:03:42 +0200 Subject: [PATCH] Gpapp/chromadb (#7891) - Description: version check to make sure chromadb >=0.4.0 does not throw an error, and uses the default sqlite persistence engine when the directory is set, - Issue: the issue #7887 For attention of - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev --------- Co-authored-by: Bagatur --- langchain/vectorstores/chroma.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/langchain/vectorstores/chroma.py b/langchain/vectorstores/chroma.py index 46c057077c5..810d3cc4908 100644 --- a/langchain/vectorstores/chroma.py +++ b/langchain/vectorstores/chroma.py @@ -94,10 +94,15 @@ class Chroma(VectorStore): if client_settings: _client_settings = client_settings elif persist_directory: - _client_settings = chromadb.config.Settings( - chroma_db_impl="duckdb+parquet", - persist_directory=persist_directory, - ) + # Maintain backwards compatibility with chromadb < 0.4.0 + major, minor, _ = chromadb.__version__.split(".") + if int(major) == 0 and int(minor) < 4: + _client_settings = chromadb.config.Settings( + chroma_db_impl="duckdb+parquet", + ) + else: + _client_settings = chromadb.config.Settings(is_persistent=True) + _client_settings.persist_directory = persist_directory else: _client_settings = chromadb.config.Settings() self._client_settings = _client_settings @@ -459,7 +464,12 @@ class Chroma(VectorStore): "You must specify a persist_directory on" "creation to persist the collection." ) - self._client.persist() + import chromadb + + # Maintain backwards compatibility with chromadb < 0.4.0 + major, minor, _ = chromadb.__version__.split(".") + if int(major) == 0 and int(minor) < 4: + self._client.persist() def update_document(self, document_id: str, document: Document) -> None: """Update a document in the collection.