Corpus
all available documents
Retrieve top-k
embedding similarity search
Re-rank
cross-encoder or LLM scoring
Fit to budget
trim to token limit
Assemble + order
place in the prompt
Concretely, context engineering for a RAG-style system is a pipeline of shrinking, re-ranked candidate sets: start with an entire corpus, use a cheap method (vector similarity) to pull a broad top-, use a more expensive but more accurate method (a cross-encoder or an LLM) to re-rank that smaller set, then fit as many of the top results as the token budget allows.