Chunked, embedded corpus
Retriever (top-k by similarity)
Budget calculator
Assembler (fits + orders chunks)
The core engineering problem is a knapsack-flavored one: given a token budget and a ranked list of candidate chunks with known relevance scores and known token costs, choose which ones to include.