7 / 11
Grounding and external context
RAG, Retrieval-Augmented Generation
IntermediateIn short: Fetch real data and answer based on it.
What is: Before answering, fetch relevant information from an external source (documents, knowledge base) and inject it into the prompt, so the model answers from it rather than from what it "remembers". The most used technique in production.
When to use: Questions about private, current or specific data the model doesn't have in training (manuals, policies, company docs).
When to avoid: General knowledge the model already has, RAG there only adds latency.
Restricting to the document + requiring a citation anchors the answer in the company's truth.
💡 Tip: The explicit "not in the document" is what prevents invention when the info is missing. Always include that instruction.
Generated Knowledge
IntermediateIn short: The model generates relevant knowledge before answering.
What is: Ask the model to generate relevant knowledge about the topic BEFORE answering, and use that knowledge as the basis. A cheap alternative to RAG when there's no external source.
When to use: Common-sense or general-knowledge questions where activating the right context helps, and you have no base to fetch from.
When to avoid: When you need verifiable, specific facts, use RAG, not generated knowledge (which can hallucinate).
Generating the facts first forces reasoning from an explicit base.
💡 Tip: Unlike RAG: here the knowledge is generated by the model (it can be wrong). For critical facts, prefer real retrieval.
Grounding by quotes and the "Lost in the Middle" effect
IntermediateIn short: Extract relevant quotes before answering; put the key info at the ends.
What is: On long-document tasks, ask the model to first extract the relevant quotes and only then perform the task. And position key information at the start or end, never the middle.
When to use: Any long-document analysis (20k+ tokens).
When to avoid: Short texts where everything fits in the model's attention.
Extracting quotes cuts noise; data at top + question at end can improve quality by up to 30%.
💡 Tip: Put what matters at the ends of the context and ask for quotes first, two cheap defenses against the middle effect.