**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}")
Code Piece:
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")
I was successfully able to get answers of my question from llm but as soon as I click any of the button below, 'Continue to Questionnaire'/'Chat with BotAI', it gives the error as shown above but it should not appear. I want to identify what's the main cause and how can I remove this error.
The error message ValueError: Expected IDs to be a non-empty list, got [] is a bit confusing as the actual problem is that documents is empty list, ids is created based on documents here :
# texts created based on documents in Chroma.from_documents
texts = [doc.page_content for doc in documents]
# ids created based on texts in Chroma.add_texts
if ids is None:
ids = [str(uuid.uuid1()) for _ in texts]
You can reproduce the error using this code:
from langchain.vectorstores import Chroma
vectordb = Chroma.from_documents(documents=[])
In your case, I assume that text is an empty string "" that cause an empty list texts when split documents using the CharacterTextSplitter.
To avoid that, add a check to ensure that the text is not empty :
if text and 'processed' in query_params:
# your code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With