PromptCause
Donate

7 / 11

Grounding and external context

RAG, Retrieval-Augmented Generation

Intermediate

In 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.

Wrong
What's our company's refund policy?
Right
Answer using ONLY the content in <policy>. If it's not there, say "not in the document", never invent. Cite the excerpt that supports it. <policy>[retrieved text]</policy> Question: What's the refund policy?

Restricting to the document + requiring a citation anchors the answer in the company's truth.

Why: Lewis et al. (2020) introduced RAG to combine parametric memory (the model) with non-parametric memory (the base), it cuts hallucination and allows updatable answers without retraining.

💡 Tip: The explicit "not in the document" is what prevents invention when the info is missing. Always include that instruction.

Generated Knowledge

Intermediate

In 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).

Right
Before answering whether an electric car is viable for urban deliveries, list 5 relevant facts about range, charging, cost per km and infrastructure. Then, based on those facts, give the recommendation.

Generating the facts first forces reasoning from an explicit base.

Why: Liu et al. (2022) showed that generating knowledge and then using it improves commonsense reasoning, the answer becomes more grounded and less generic.

💡 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

Intermediate

In 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.

Right
<document>[long text at the TOP]</document> First extract in <quotes> the excerpts relevant to the question. Then, based ONLY on those quotes, answer. Question: [goes at the END]

Extracting quotes cuts noise; data at top + question at end can improve quality by up to 30%.

Why: The "Lost in the Middle" research (Liu et al., 2023, Stanford) showed performance drops when relevant info is in the MIDDLE of long contexts, models do better with key info at the start or the end.

💡 Tip: Put what matters at the ends of the context and ask for quotes first, two cheap defenses against the middle effect.