Closed tonyaw closed 2 months ago
To determine if a user's question should be answered by a single RAG query or if it requires an agent to break down the query and perform multiple retrievals, you can follow these guidelines:
Single Document Query: If the question pertains to a specific aspect or summary of a single document, a single RAG query is sufficient. For example:
Multi-Document Query: If the question involves comparing or summarizing information across multiple documents, it requires an agent to break down the query and perform multiple retrievals. For example:
For implementation, you can consider the following approaches:
For simple queries:
response = self._client.search(
collection_name=self.collection_name,
query_vector=query_embedding,
limit=query.similarity_top_k,
query_filter=query_filter,
)
For complex queries:
sub_questions = sub_question_query_engine.generate_sub_questions(main_query)
sub_questions = prune_sub_questions(sub_questions)
answers = []
for sub_question in sub_questions:
answer = sub_question_query_engine.retrieve_answer(sub_question)
answers.append(answer)
final_answer = combine_answers(answers)
Additionally, consider using the Router Query Engine
, which may be useful for routing queries to the appropriate engine based on their complexity [1].
By following these guidelines and approaches, you can effectively determine whether a user's question should be answered by a single RAG query or if it requires an agent to perform multiple retrievals.
To continue talking to Dosu, mention @dosu.
@jerryjliu, could you please help to check my question as you are the author of https://learn.deeplearning.ai/courses/building-agentic-rag-with-llamaindex/lesson/1/introduction? :-)
Could you please help to provide some suggestion? Thanks!
Question Validation
Question
I want to use llama-index to build an Agentic RAG, like mentioned in https://learn.deeplearning.ai/courses/building-agentic-rag-with-llamaindex/lesson/1/introduction. I want the system to query RAG once for most of simple questions. For complex question, I want the system to use agent to do multiple retrievals, and give a summary based on the answers. My question is how to judge if user's question shall be answered by a single RAG query or an agent to break down the query and do multiple retrievals?
I have two ideas here:
Could you please provide your suggestion about how it shall be handled?
Question examples:
Thanks in advance!