Advanced context management & RAG
Lesson 7 of 8 · 30 min · part of the AI Prompt Engineer certification
A bigger context window does not mean you should fill it. More tokens cost more, respond slower, and can dilute attention: models are often better at using information at the beginning and end of a long context than in the middle (the "lost in the middle" effect).
Good context management means giving the model the right information, in the right place, at the right size.
- Put long documents first, and the question/instructions after them — for long inputs, this ordering typically improves answer quality.
- Summarize old conversation turns instead of resending them verbatim once they stop being relevant.
- Retrieve, don't paste: use retrieval-augmented generation (RAG) to include only the passages relevant to the current question.
- Label sources (
<source id="3">) and ask the model to cite them, so answers can be verified.
Interactive exercise: Build a RAG pipeline
Interactive exercise: Curate the context