A query updater rewrites outstanding questions using the original question and answers returned by earlier retrievals. It makes dependent follow-up questions more complete, atomic, specific, and easier to answer without requesting information beyond the original question. section 5.3.2
Dependent questions
Rewrite “Who has won the most Oscars, and is that person alive?” as “Who won the most Oscars?” and “Is that person alive?” After answering the first question, update the second with the identified person. section 5.3.2
Implement the updater as a sequential retrieval step:
- Pass the original question and previous retriever answers to the updater. section 5.3.2
- Instruct the LLM to preserve already-complete questions and return only a JSON question field. section 5.3.2
- Feed the updated question into retriever routing before collecting the next answer. section 5.3.2
Listing 5.5 Query updater function
def query_update(input: str, answers: list[any]) -> str:
messages = [
{"role": "system", "content": query_update_prompt},
*answers,
{"role": "user", "content": f"The user question to rewrite: '{input}'"},
]
config = {"response_format": {"type": "json_object"}}
output = chat(messages, model = "gpt-4o", config=config, )
try:
return json.loads(output)["question"]
except json.JSONDecodeError:
print("Error decoding JSON")
return []
Use the Python function pattern to assemble prior answers, invoke the model with structured JSON output, and extract the rewritten question. section 5.3.2
