kheirq
kheirq

Reputation: 81

Losing data of vector store Chromadb using Langchain

I am writing a question-answering bot using langchain. For storing my data in a database, I have chosen Chromadb. I have written the code below and it works fine

persist_directory = "./db"
embeddings = OpenAIEmbeddings()

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

When I run this code, I get a list of my documents which I stored. vectordb.get()['documents']

I can see that some files are saved in the ./db directory.

When I want to restart the program and instead of initializing a new database and store data again, reuse the saved database, I get unexpected results.

I used this code to reuse the database vectordb2 = Chroma(persist_directory=persist_directory, embedding_function=embeddings)

But this time when I run the code below it returns an empty list vectordb2.get()['documents']

What is the problem here?

Upvotes: 6

Views: 5298

Answers (1)

Breno
Breno

Reputation: 21

Try calling vectordb.persist() after creating your vector db.

Your code should have been:

persist_directory = "./db"
embeddings = OpenAIEmbeddings()
vectordb = Chroma.from_documents(documents=documents,
embedding=embeddings, persist_directory=persist_directory)
vectordb.persist()

Upvotes: 2

Related Questions