Iterative Retrieval
In this article
- Build a retrieval loop that searches, grades what came back, names the gap and searches again for that gap only.
- Keep the state a loop needs between rounds: the original question, the queries run, the evidence with chunk ids, the open gaps and the spend.
- Stop the loop with a round cap, a token budget and a repeat check written in code, not with the model's judgment.
- Spot query drift in a trace and prevent it by building each new query from the question plus the gap.
- Terms defined here: iterative retrieval.
Overview
A customer asks what an error code means and whether they can still return the router. The first search finds the error page and nothing about returns. A person would search again for the missing part. A program that searches "until it has enough" can do that too, or search forty times, drift to the wrong product and pay for the same query twice.
Brightline, a made-up home-internet provider, runs a support assistant that searches its help pages and router manuals and puts the best 3 chunks, short pieces of those pages, into each request. It serves home and business customers, and each reply has a 5 s deadline. By the end you can build a loop that searches again only for what is missing, keeps its evidence, and stops on limits written in code.
This article is part of Pro
Pro includes the staff-level and expert articles in every path. It opens after the four core paths are complete.
Still to read in this article
- One search, then another
- A trace you can follow
- What the loop remembers
- How a loop drifts
- Caps written in code
- What each round costs
- Common mistakes
- In production
- Sources
- Check yourself, 13 questions