**ValueError:** Expected IDs to be a non-empty list, got []
**Traceback:**
File "C:\Users\scite\Desktop\HAMBOTAI\HAMBotAI\HAMBotAI\homehambotai.py", line 96, in app
db = Chroma.from_documents(texts, embeddings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\scite\AppData\Roaming\Python\Python311\site-packages\langchain_community\vectorstores\chroma.py", line 771, in from_documents
return cls.from_texts(
^^^^^^^^^^^^^^^
File "C:\Users\scite\AppData\Roaming\Python\Python311\site-packages\langchain_community\vectorstores\chroma.py", line 729, in from_texts
chroma_collection.add_texts(
File "C:\Users\scite\AppData\Roaming\Python\Python311\site-packages\langchain_community\vectorstores\chroma.py", line 324, in add_texts
self._collection.upsert(
File "C:\Users\scite\AppData\Roaming\Python\Python311\site-packages\chromadb\api\models\Collection.py", line 449, in upsert
) = self._validate_embedding_set(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\scite\AppData\Roaming\Python\Python311\site-packages\chromadb\api\models\Collection.py", line 512, in _validate_embedding_set
valid_ids = validate_ids(maybe_cast_one_to_many_ids(ids))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\scite\AppData\Roaming\Python\Python311\site-packages\chromadb\api\types.py", line 228, in validate_ids
raise ValueError(f"Expected IDs to be a non-empty list, got {ids}")
字符串
代码块:
if 'processed' in query_params:
# Create a temporary text file
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as temp_file:
temp_file.write(text)
temp_file_path = temp_file.name
# load document
loader = TextLoader(temp_file_path)
documents = loader.load()
# split the documents into chunks
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)
# select which embeddings we want to use
embeddings = OpenAIEmbeddings()
# ids =[str(i) for i in range(1, len(texts) + 1)]
# create the vectorestore to use as the index
db = Chroma.from_documents(texts, embeddings)
# expose this index in a retriever interface
retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 2})
# create a chain to answer questions
qa = ConversationalRetrievalChain.from_llm(OpenAI(), retriever)
chat_history = []
# query = "What's the Name of patient and doctor as mentioned in the data?"
# result = qa({"question": query, "chat_history": chat_history})
# st.write("Patient and Doctor name:", result['answer'])
#
# chat_history = [(query, result["answer"])]
query = "Provide summary of medical and health related info from this data in points, every point should be in new line (Formatted in HTML)?"
result = qa({"question": query, "chat_history": chat_history})
toshow = result['answer']
# chat_history = [(query, result["answer"])]
# chat_history.append((query, result["answer"]))
# print(chat_history)
st.title("Data Fetched From Your Health & Medical Reports")
components.html(
f"""
{toshow}
""",
height=250,
scrolling=True,
)
if st.button('Continue to Questionarrie'):
st.write('Loading')
st.text("(OR)")
if st.button('Chat with BotAI'):
st.title("Chat with BotAI")
型
我成功地能够从llm得到我的问题的答案,但只要我点击下面的任何按钮,“继续浏览”/“与BotAI聊天”,它给出了如上所示的错误,但它不应该出现.我想确定什么是主要原因,我如何才能删除此错误.
2条答案
按热度按时间6ljaweal1#
错误消息
ValueError: Expected IDs to be a non-empty list, got []
有点令人困惑,因为实际问题是documents
是空列表,ids
是基于以下文档创建的:字符串
您可以使用以下代码重现错误:
型
在您的例子中,我假设
text
是一个空字符串""
,当使用CharacterTextSplitter
拆分documents
时,会导致一个空列表texts
。为了避免这种情况,添加一个检查以确保
text
不为空:型
5w9g7ksd2#
我测试了你的代码,它可以工作:
的数据
我点击按钮没有错误抛出,它打印“聊天与BotAi `标题。这是进口:
字符串
版本:
型