Find answers from the community

Updated 6 months ago

subquery metadata

At a glance

The community member is following an implementation to get subquery QA and metadata node.text citations used for each subquery. They are iterating through sub_question items captured in the SUB_QUESTION event and printing the sub-question and answer. The community member is asking how they can access the source_nodes for each subquestion to extract the node.metadata, node.text, and score used.

In the comments, other community members suggest that the information may already be in the response.source_nodes, or that the community member could write a custom callback handler to access the sub-questions as they happen. However, there is no explicitly marked answer.

Hello everyone,

I'm fallowing this implementation to get subquery QA and metadata node.text citations used for each subquery.

Plain Text
# iterate through sub_question items captured in SUB_QUESTION event
from llama_index.core.callbacks import CBEventType, EventPayload

for i, (start_event, end_event) in enumerate(
    llama_debug.get_event_pairs(CBEventType.SUB_QUESTION)
):
    qa_pair = end_event.payload[EventPayload.SUB_QUESTION]
    print("Sub Question " + str(i) + ": " + qa_pair.sub_q.sub_question.strip())
    print("Answer: " + qa_pair.answer.strip())
    print("====================================")


How I can access for each subquestion source_nodes to extract node.metadata, node.text, score used ?

Thank you
A
L
5 comments
@Logan M @WhiteFang_Jr any sugestion here ? I can loop throw for elem in llm_response.source_nodes but if I have more subquestions I don't know if we sent same chunks each time or for each question are different chunks retrived from query engine ? if we have different chunks then how I can get what is used for each subquestion ? Thanks
Hi @Logan M @WhiteFang_Jr any recomandation how to get node.text used for each subquestion generated in SubQuerEngine ?
I think they are already in response.source_nodes
Either that, or you can write a custom callback handler to pick into the sub-questions as they happen
Add a reply
Sign up and join the conversation on Discord