Skip to lesson
Exit
AI editor systems and design1 / 2

1 min lesson

Rank context under a token limit

Pack the highest value evidence into a fixed token budget while preserving the request and current edit.

Step 1 of 2

Cut context when it exceeds the budget

When candidates exceed the budget, keep the request and current edit intact. Rank the remaining material by how likely it is to change the answer, then remove the lowest-value items.

  • Score each candidate with search relevance, exact symbol matches, structural proximity and freshness.
  • Reserve output space before packing candidates into the input budget.
  • Use signatures or focused spans when a full file adds little evidence for the task.
  • Keep the user's request, selected code and current edit state ahead of loosely related search results.
Watch out

Extra context adds tokens, latency and cost, and irrelevant material can reduce answer quality. Evaluate retrieval by task outcome as well as recall. A system that retrieves every possibly related file has not solved the ranking problem.

Interview move

Describe this as a proposed design. Name the fixed context budget, the evidence kept intact, the search methods, the ranking features and the freshness check. Then explain how you would measure whether the retrieved code improved task outcomes.

Learn more

Optional practice

Check a retrieval plan

QWhy should a code agent combine semantic search with exact search instead of relying on embeddings alone?