Start studying
Module 9 · RAG Module contents
Module 9  ·  Card 10 / 19intermediate

Context Construction

Context construction assembles retrieved chunks into the final prompt.

Order matters, because models attend most strongly to the start and end.

Each chunk should be clearly delimited and labelled with its source.

You must budget tokens across system prompt, context, question and answer.

Stuffing in more chunks than needed measurably hurts accuracy.

Learn in depth ↓
Module 09 · RAG · 19 concepts
In depth  /  15 lines

Context Construction, in more detail

Context construction is assembling the retrieved chunks into the prompt you actually send.

It is often treated as string concatenation and deserves more care than that.

Order matters, since models attend most reliably to the start and the end.

The strongest chunk should not be buried in the middle of twenty others.

Label every chunk with its source and an identifier the model can cite.

Delimit them clearly so instruction and evidence never blur together.

State plainly that the chunks are reference material and not instructions.

Retrieved text is untrusted, since anything inside it may attempt an injection.

Budget the tokens across system prompt, chunks, question, history and the answer itself.

Running out of room usually truncates the answer rather than the context, which is the wrong end.

More chunks is not better, and adding weak ones measurably lowers accuracy.

Five good chunks beat twenty mixed ones on nearly every real benchmark.

Deduplicate, because near-identical chunks waste budget and inflate false confidence.

Include dates when recency matters, so the model can prefer the newer statement.

Log the assembled prompt in development, since most failures are obvious when you read it.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
Why does the order of chunks in the prompt matter?
RAG

19 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close