失去了使用Langchain的向量存储Chromadb的数据。

huangapple go评论43阅读模式
英文:

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()

huangapple
  • 本文由 发表于 2023年5月29日 22:41:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358247.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定