Skip to content
RAG Explained Better

Context Assembly: Building the Prompt the Model Actually Sees

Retrieval returns candidates; assembly decides what reaches the model. The stage almost no tutorial names.

Context assembly in RAG is the stage after retrieval that decides which retrieved chunks enter the prompt, in what order, under what token budget, and whether near-duplicates or filler survive into generation. Retrieval returns a ranked candidate list; assembly packs that list into the evidence the model actually sees. Unrag.dev frames context packing as arranging retrieved content through ordering, formatting and labeling so the model can extract and synthesize; Praxen’s Medium guide (2025/26) calls the same object a budgeted evidence package. The four packing decisions are window budgeting, deduplication, ordering and compression, each owned by a child leaf under this hub. Index-time methods such as Anthropic contextual retrieval enrich chunks before embed and are a different stage. Vector stores such as Weaviate, Qdrant and Pinecone change what candidates exist; they do not replace packing at query packing time.

What is context assembly in RAG?

Context assembly in RAG is the post-retrieval stage that turns a ranked candidate list into the prompt context the model actually sees by selecting, budgeting, ordering, compressing and deduplicating chunks before generation. Place it in the pipeline: retrieval returns candidates, assembly packs the prompt, generation answers. Edugators-style guides describe the failure of feeding retrieval chunks without noise control; assembly is the named control point for that noise.

Redis (captured September 2026) publishes a same-named stage article on building the prompt the model sees, which confirms the assembly framing now appears among ranking write-ups rather than only as a named gap. Anthropic contextual retrieval prepends chunk-specific context at index and embed time. Name it once here as a different stage, then take depth on contextual retrieval. Assembly does not re-chunk the corpus, does not train a reranker, and does not choose the vector database; it spends a fixed token budget on whatever shortlist already arrived from retrieval. Tutorials that dump formatting code and grounded JSON on one page still skip naming that stage, which is why engineers change the wrong knob when mid-prompt answers fail.

The map gap that justified this hub was that packing rarely appeared as a named stage in earlier competitor sets. The September 2026 organic set now includes Redis under the same title, Respeak and glossary entries under the same term, and several context-engineering posts that absorb packing into a rename. The hub response is unchanged in structure: define the stage, walk the four decisions lean, and route depth to window, compression, ordering and dedup. That router is the citeable difference against mega-guides that still paste code without naming which packing control failed.

Context assembly stages after retrieval: retrieved candidates, then budget, dedupe, order and compress, then the packed prompt handed to the language model.
Assembly sits after retrieval: candidates enter a budget, near-duplicates drop, order places the best evidence on the edges, compression shrinks filler, then the packed prompt reaches the model.

When the gold chunk was retrieved and still ignored, the failure leaf is lost in the middle; the packing fix for position is ordering. When the question is whether to retrieve at all versus stuffing a long window, the scored comparison is RAG vs long context. The four packing decisions at overview depth are what packing actually does after those borders are set.

How does context packing work after retrieval?

Context packing after retrieval works by spending a fixed token budget across instructions, history and retrieved evidence, then dropping near-duplicates, placing the best chunks where the model attends, and compressing what still overflows. Unrag.dev’s token-budget guidance is reserve essentials first; evidence gets the remainder. Praxen’s packing tricks list the same family of moves without treating assembly as a named pipeline stage. Redis’s September 2026 assembly article uses the same stage title this hub locked on the map, which is why the cluster can no longer treat “assembly” as an unpublished name. This hub keeps the stage map lean and routes depth to children. Mega-guides that paste formatting code and grounded JSON on one page still leave the four decisions unnamed, which is the coverage gap this cluster closes. Adnan Sattar’s Part 3 Medium guide in the organic set dumps grounded prompting beside assembly; that formatting depth stays on RAG prompts.

Window budget: reserve system, history and generation tokens first; retrieved context gets the remainder on how many tokens evidence may spend. Dedup: near-duplicate chunks waste tokens and skew the answer toward whatever was repeated on removing redundant chunks before generation. Order: position changes whether a fact is used; Liu et al. (2023; TACL 2024) measured U-shaped multi-document QA accuracy with mid-context under-use, and Redis (February 2026) summarises double-digit percentage-point drops when gold sits mid-context; mechanism depth is context ordering. Compress: extractive and abstractive shrink keep evidence under budget on contextual compression.

Cost aside, Redis citing OpenAI GPT-4.1 list prices as of its February 2026 post lists $2.00 / $8.00 per million input / output tokens, so a 100,000-token input is about $0.20 before output; verify before you rely. A bigger window does not replace packing; the scored verdict lives on when long context replaces retrieval. Top-k maths before packing belong on top-k; formatting wrappers and grounded prompt templates belong on RAG prompts. Weaviate’s search concepts documentation (as of September 2026) sequences retrieval, optional rerank, then retrieval-augmented generation; assembly is the application packing gate between search results and that generative call. Once the four decisions are named, routing the reader’s symptom to the right leaf is the remaining hub job. Towards AI’s production-ready context-engineering write-up in the organic set folds packing into a broader reliability story; keep the four decisions named so the reader can open a leaf instead of rewriting the whole stack.

Which context problem is a token budget problem?

A token budget problem is the case where the evidence slice, history and reserved output no longer fit the model window, or where stuffing more chunks would only raise cost and mid-context mass. Symptoms include API truncation, silent mid-assembly cuts that NewPrompt-style planners flag when character estimates looked safe, and answers that degrade as sessions accumulate history. The leaf is budgeting the context window: named slices, an overflow cut order, and the dual stop on evidence tokens or top-k. Counting with the wrong tokenizer is enough to make a “safe” plan fail on the first Anthropic or OpenAI call after a model swap. Towards Data Science’s four typed inputs framing in the organic set is adjacent vocabulary for what enters the packed prompt; the budget leaf still owns the token arithmetic.

If the packed set still overflows after rank-drop, the shrink lever is query-conditioned compression, not a larger marketing maximum alone. If the question is whether retrieval should be replaced by stuffing the corpus into a long window, leave the packing leaves and open RAG versus stuffing the window. Budgeting does not fix a gold chunk that never entered the shortlist; that is retrieval diagnosis under the failure taxonomy. Anthropic contextual retrieval in the organic set is index-time enrichment, not a substitute for an evidence token cap at packing time.

Window and compression fit the window. Ordering and dedup shape what the model attends to inside that window, which is the second problem group. Teams that skip the budget leaf and jump straight to a new embedding model usually rediscover truncation the first week traffic includes multi-turn history. LinkedIn assembly posts in the same organic set often stop at naming the stage; the children below are where the controls become measurable.

Which context problem is a prompt-shape problem?

A prompt-shape problem is the case where the right evidence is already in the candidate list but position, repetition or filler decides whether the model uses it. Symptoms include a correct mid-ranked chunk ignored while edge chunks dominate, answers that parrot a duplicated policy paragraph, and long chunks that bury a one-sentence exception. Ordering places the best evidence on the edges on where to put the best chunk. Dedup removes exact and near copies, with MMR as the diversity sibling, on removing redundant chunks. Callstack’s “RAG is dead, long live context engineering” piece in the organic set collapses packing into a broader rename; the decisions comparison owns that vocabulary debate, while this hub stays on the four packing controls.

When the gold chunk was retrieved and still ignored after you confirm it sits mid-prompt, open the lost-in-the-middle position test for detection, then return to ordering for the reorder mechanism. When two sources disagree rather than one fact being buried, that is conflicting sources, not packing. Citation UX and hallucination residual rates are generation concerns on hallucination despite context. Reddit threads in the organic set often blur packing with “context engineering” as a single complaint; keep the symptom mapped to one of the four leaves before you change the model.

Context engineering as a vocabulary shift versus prompt engineering is a decisions comparison on RAG vs context engineering; this hub stays on the RAG packing stage. Runnable end-to-end assembly code belongs on building a RAG pipeline. The four children below are the complete packing map for this cluster. A hub that only lists tricks without naming the stage leaves engineers changing the wrong knob.

What are the four context packing decisions after retrieval?

The four context packing decisions after retrieval are how many tokens evidence may spend, whether near-duplicates stay, where the best chunk sits in the prompt, and whether filler inside a kept chunk is compressed before generation. Every ranking page that discusses packing covers some subset of that union; this hub is the lean router that names all four and refuses to dump leaf depth on the stage page. Readers who arrive from a failure symptom should still land on one of the four leaves rather than a single undifferentiated “improve context” checklist. Respeak’s RAG Explorer step on context assembly and the AI Search Glossary entry for the same term show the phrase spreading in teaching materials; depth still belongs on the mechanism children, not on a glossary-length hub.

Context window budgeting allocates system, history, evidence, query and reserved output, then enforces an evidence cap. Deduplicating retrieved context drops exact and near copies and optionally applies MMR so multi-aspect queries keep non-clones. Where the best chunk sits U-shapes scored chunks so edges hold the strongest evidence against lost-in-the-middle under-use. Extractive and abstractive compression shrinks kept chunks when signal is sparse inside long text.

Weaviate is the default retrieval example when a store is named: hybrid search fuses BM25F and vectors with Relative Score Fusion by default since v1.24, optional rerank reorders a smaller subset, and diversity selection (MMR) on hybrid is documented from v1.38.6 (Weaviate documentation, as of September 2026). Assembly still runs in application code on the objects search returned. Seed the wider pipeline from what retrieval-augmented generation is when the reader still needs the system definition. Measure packing with tokens kept, duplicate rate and position delta before you change the embedding model again. A glossary-length definition of assembly is not enough when the production failure is a mid-ranked gold chunk buried under duplicates inside an overflowing evidence slice. Measure tokens kept, duplicate rate, and position delta on a labelled sample before you change the embedding model again, because those three numbers tell you which of the four children to open first.

Context assembly is the named stage between retrieval and generation: a budgeted evidence package, not a dump of the top-k list. Packing spends tokens, drops duplicates, places the best chunks on the edges, and compresses filler when the slice still overflows. Unrag, Praxen, Redis and Liu et al. supply the practitioner and research vocabulary; the four children own the mechanisms. Route the symptom to the leaf that matches the failure, measure before you change the model, and keep index-time enrichment and long-context decisions on their own nodes. A lean hub that names the stage earns the citation that mega-guides leave on the table.

The practical test is simple. If the failure is tokens, open window or compression. If the failure is attention inside an already packed prompt, open ordering or dedup. If the gold text never entered the shortlist, leave the context cluster for the failure taxonomy under retrieval. Redis, Respeak, Adnan Sattar, Towards Data Science and Callstack show how widely the packing vocabulary now spreads; the gain here is still the four-decision router with explicit EXCLUDE destinations rather than another mega-guide that pastes formatting code beside a grounded JSON schema. Ship the hub as orientation, then measure the leaf that owns the control you just changed on a small labelled sample each production week.