英文:
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?
英文:
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?
答案1
得分: 1
尝试在创建向量数据库后调用 vectordb.persist()
。
您的代码应该是:
persist_directory = "./db"
embeddings = OpenAIEmbeddings()
vectordb = Chroma.from_documents(documents=documents, embedding=embeddings, persist_directory=persist_directory)
vectordb.persist()
英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论