Retrieval-Augmented Generation (RAG) with Python

Lesson 7 of 9

Augmentation

Retrieval found the relevant chunks, but an LLM doesn't automatically know they exist, they need to actually be inserted into the prompt sent to the model. This step is called augmentation, and it's the "A" in RAG.

Building the augmented prompt

Pythonshares state with other Python blocks

Why "ONLY the context"

That instruction is doing real work, an LLM without it will happily blend its own training knowledge with whatever you gave it, sometimes producing a plausible-sounding but wrong answer for your specific system (a classic hallucination). Explicitly restricting it to the provided context, and telling it what to say when the answer isn't there, is what makes the final response trustworthy and traceable back to your actual data instead of the model's guesswork.

The final prompt formula

Every RAG system boils down to the same combination:

Final prompt = Query + Retrieved Context

Everything from Data Collection through Retrieval exists purely to produce a good Context, augmentation is where that context and the original question finally get combined into the single string the LLM will actually see.

NOTE

build_prompt is plain string formatting, nothing here calls an LLM yet, that's deliberately the very last step, covered next.

📝 Augmentation Quiz

Passing score: 70%
  1. 1.Why does build_prompt() explicitly instruct the model to answer "using ONLY the context"?

  2. 2.The augmentation step itself makes an API call to an LLM.

  3. 3.The final prompt formula is: Final prompt = Query + Retrieved ____.