Retrieval and Boundaries for Agent Runs

Lesson 1 of 4

Order Candidates by the Question

Estimated time: 10 minutes

Order Candidates by the Question

A first-stage retriever optimises for recall, so the list it returns is wide and loosely ordered. Passing that list straight to a model lets a roughly related item crowd out the right one.

Score against the actual question

A rerank pass reads the question and each candidate together and returns an order. The first stage decides what is available; the rerank decides what is used. Rerank against the question being answered, not the search string that produced the candidates.

def trim(scored, budget):
    scored.sort(key=lambda c: c.score, reverse=True)
    return scored[:budget]

Keep the cut auditable

Trim to the context budget, but retain the scored order so a surprising answer can be traced to a ranking decision rather than re-guessed.