Retrieval and RAGScale and federated operationsPrincipal
How should an agent traverse a changing search index without skipping or repeating documents?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
An agent pages through a live index, then claims every incident was inspected. Updates move hits between page boundaries, and even cursor traversal uses inconsistent views or ties. Design snapshot identity, deterministic sort, cursor and expiration handling, then distinguish deduplication, current disclosure permissions and a complete as-of traversal.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Each page can be a new query against a changed index. An ingest or update changes scores or sort positions between page one and page two. With offset pagination, a hit can slide across the boundary and appear twice or never appear. Even search_after needs a stable sort with a unique tiebreaker and a consistent index view. Elasticsearch's pagination documentation describes missing and duplicate hits after refresh and recommends a point-in-time view with search_after for deep pagination.
That matters if an agent says “I checked all incidents” after reading a hundred pages. It has made a completeness claim about a set that may never have existed as one snapshot. I would log the PIT or snapshot ID, sort tuple and last cursor on each request, returned document IDs and revisions, shard failures, and whether the PIT expired. Do not equate a total hit count from one query with a guarantee that all subsequent pages traversed that same result set. A score tie without a unique tiebreaker can cause a second problem even on an otherwise quiet index.
Open a point in time, use a deterministic sort and tiebreaker, pass the full search_after tuple, and carry the returned PIT identifier forward as the API requires. Keep the PIT lifetime bounded because an old view retains resources while the live index changes. If it expires midway, restarting under a new PIT is a new traversal, not a seamless continuation. For very large exhaustive jobs, a purpose-built scan or source-database export may be more appropriate than ranking-oriented search. Deduplicate by stable ID and version, but know that deduplication only fixes repeats. It cannot prove there were no omissions.
A point in time freezes an index view, not the user’s current right to read every old document. Recheck disclosure authority before returning protected contents. If permission changes remove items during the job, state the requested snapshot scope and what could still be disclosed separately. Consistent pagination is not permission to preserve a revoked grant.
If the search job feeds an answer, expose the as-of boundary and completion status. If it did not finish, let the assistant say what it checked, not “no matching documents exist.” Individually valid search responses can still combine into an incomplete traversal.
Related questions
Keep practising retrieval and rag
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux