Log inBook a Demo
BuildSeniorData / MLAuto-graded

Fit the highest-scoring passages into a token budget

The obvious ranking approach quietly wastes the budget, and the test is whether someone notices and selects optimally instead.Retrieval has given you a pile of candidate chunks, each with a relevance score and a token cost, and your context window has a hard budget. You cannot send them all, so you must choose the subset that buys the most relevance within the budget. Get it wrong and you either overflow the window and the call fails, or you spend everything on one flashy chunk and starve the prompt of two cheaper ones that together would have said more.
40 min
python

You're done when

  • The selected chunks never exceed the token budget.
  • Selection maximises total relevance for the budget rather than simply taking the highest-scoring chunk first.
  • A chunk larger than the entire budget is excluded rather than breaking the packing.
  • When nothing fits, the result is empty rather than an overflow or an error.
  • The selection is returned in a usable order for assembling the prompt.

What it measures

Context engineeringTreating the context window as a budget to allocate rather than a container to fill.
AI cost and value managementMaximising the value bought per token, which is where naive greedy selection loses badly.
Constrained optimisationRecognising the packing problem underneath and handling the degenerate cases it brings with it.

Your environment

Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards

Start this lab

40 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo