Open
Description
In the search function of GraphRAG class, theres a step to retrieve data:
If the result comes empty, then the value for retriever_result.items is an empty list ([]). This is fine.
Problem is the function later does not validate for this scenario, finally passing the input, message_history and system_instruction to the function:
Which could lead to potential problems, hallucinations and undesired answers.
A simple solution could be to just validate the items:
if not retriever_result.items:
result: dict[str, Any] = {"answer": ""}
A more robust solution would be to return either a predefined message or user defined message (as an argument to the function) before the invoke of the llm (as to not invoke an llm over an empty answer) in scenarios where the result is an empty list.