llama_index
llama_index copied to clipboard
Prevent LLM request on querying a tree with a single root node
I have a tree index with non uniform shape. Some of the nodes have only a single child, and there is only one root node.
It seems like the tree_index query could be optimized something like:
cur_node_list = get_sorted_node_list(cur_nodes)
if len(cur_node_list) == 1:
# jump to recursive call on leaf node
I am happy to make the PR to do this if the maintainers would like.
The bug that brought me to this is that the LLM is more likely to select an invalid answer (e.g. ANSWER 4.) if there is only one node choice for it to pick.
@kpister thanks for surfacing, apologies for the delay. if you wanted to open a PR feel free to!
Closing issue since associated PR has been landed.