Closed LikhithRishi closed 3 days ago
To resolve the ValueError
stating that the Query ID is not found in either retriever_dict
or query_engine_dict
when re-executing code that uses previously generated ChromaDB embeddings, ensure that the retriever
and query_engine
are correctly initialized and accessible. The RecursiveRetriever
class initializes these components, so you need to make sure that the retriever_dict
and query_engine_dict
contain the necessary entries.
Here is an example of how you can initialize and use the RecursiveRetriever
class to avoid the ValueError
:
from llama_index.core import Document, ServiceContext, VectorStoreIndex
from llama_index.core.retrievers import RecursiveRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
from llama_index.core.node_parser.text import SentenceSplitter
from llama_index.core.schema import TextNode, IndexNode
# Initialize the documents and other components
documents = [Document(text="your_document_text")] # Replace with your actual documents
text_splitter = SentenceSplitter()
nodes = text_splitter.get_nodes_from_documents(documents)
# Initialize the embedding model and service context
embed_model = OpenAIEmbedding(embed_batch_size=128)
service_context = ServiceContext.from_defaults(
llm=OpenAI(),
embed_model=embed_model,
num_output=750,
)
# Create the VectorStoreIndex
vector_index = VectorStoreIndex(
nodes, service_context=service_context, show_progress=True
)
# Initialize the retriever and query engine dictionaries
retriever_dict = {
"vector": vector_index.as_retriever(similarity_top_k=4)
}
all_nodes_dict = {n.node_id: n for n in nodes}
# Initialize the RecursiveRetriever
recursive_retriever = RecursiveRetriever(
"vector",
retriever_dict=retriever_dict,
node_dict=all_nodes_dict,
)
# Initialize the RetrieverQueryEngine
query_engine = RetrieverQueryEngine.from_args(
recursive_retriever,
service_context=service_context,
streaming=False,
)
# Create a query bundle
query_str = "your_query_string"
# Use the query engine to run a query
result = query_engine.query(query_str)
print(result)
This code ensures that the retriever
and query_engine
are correctly initialized and used, which should prevent the ValueError
related to missing Query IDs. Make sure that the root_id
is present in the retriever_dict
and that there are no overlapping keys between retriever_dict
and query_engine_dict
[1][2][3].
To continue talking to Dosu, mention @dosu.
Bug Description
I am encountering a ValueError when trying to re-execute code that uses previously generated ChromaDB embeddings. The code works perfectly on the first run, generating responses from the LLM based on user input. However, when I stop the execution and run the code again to reuse those embeddings, I get the following error:
ValueError: Query id d28e3de4-1c4f-420a-9184-97bf8556b11b not found in either
retriever_dict
orquery_engine_dict
.Actual Behavior On re-execution, the code raises a ValueError stating that the Query ID is not found in either retriever_dict or query_engine_dict.
Expected Behavior The code should run successfully using previous embeddings without raising any ValueError
Version
llama-index==0.10.12
Steps to Reproduce
Relevant Logs/Tracbacks
No response