3

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?

Jason Gilmore
  • 3,698
  • 3
  • 23
  • 28
kheirq
  • 31
  • 2

1 Answers1

1

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()
Breno
  • 11
  • 1