1

I'm persisting the Chroma Database but it's giving me an error.

I'm basically redoing what's in this link.

https://github.com/hwchase17/chroma-langchain/blob/master/persistent-qa.ipynb

Is there any update in chromadb version and they have removed persist I don't get it.

!pip -q install chromadb openai langchain tiktoken

!pip install -q langchain-chroma

!pip install -q langchain_chroma  langchain_openai langchain_community

from langchain_chroma import Chroma
from langchain_openai import OpenAI
from langchain_community.embeddings import OpenAIEmbeddings
from langchain_community.document_loaders import TextLoader
from langchain_community.document_loaders import DirectoryLoader

persist_directory ='db'

embedding = OpenAIEmbeddings()

vectordb = Chroma.from_documents(documents=texts,
                                 embedding=embedding,
                                 persist_directory=persist_directory)

vectordb.persist()

Then I'm getting the below error:


AttributeError Traceback (most recent call last) Cell In[47], line 1 1 vectordb.persist()

AttributeError: 'Chroma' object has no attribute 'persist'

1
  • Did you find a solution to this issue? Commented May 18, 2024 at 23:05

6 Answers 6

7

In newer versions the documents are automatically persisted.

You just need to update the import. Where you import Chroma, use this:

from langchain_chroma import Chroma

And delete the persist in your code.

Sign up to request clarification or add additional context in comments.

Comments

2

Might be a little late to the thread, but the source code is here: https://python.langchain.com/api_reference/_modules/langchain_chroma/vectorstores.html#Chroma

When persist_directory is provided, Chroma will set is_persistent=True.

Hope this helps!

Comments

1

The following import solved the problem

from langchain_community.vectorstores.chroma import Chroma

persist_directory = "/tmp/chromadb"
vectordb = Chroma.from_documents(documents=texts, embedding=embeddings,
                                 persist_directory=persist_directory)
vectordb.persist()

I too was unable to find the persist() method in the earlier import

from langchain_community.vectorstores import Chroma

Comments

1

The new version of langchain_chroma will automatically perform persistence, so you don't need to execute: vectordb.persist().

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
No need to further information , this is the solution , remove the line as the persist mode is on by default
0

Try this

from langchain_community.vectorstores import Chroma
persist_directory = "/tmp/chromadb"
vectordb = Chroma.from_documents(documents=texts, embedding=embeddings,
                                 persist_directory=persist_directory)
vectordb.persist()

Comments

0
  1. Since Chroma 0.4.x the manual persistence method is no longer supported as docs are automatically persisted. So you can just get rid of vectordb.persist() and it will work fine

  2. The class Chroma was deprecated in LangChain 0.2.9 and will be removed in 0.4. An updated version of the class exists in the langchain-chroma package and should be used instead. To use it run pip install -U langchain-chroma and import as from langchain_chroma import Chroma.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.