Lesson 04 · Applied LLM Engineering

RAG & Grounding

Why retrieval quality beats vector-database worship, how to make a model prove its answers with citations — and how to tell when RAG is the wrong tool entirely.

FDE skill · build Q&A systems a clinician could trust
🎧 Listen to this lesson · ~10 min · narrated audiobook edition

⏱ ~9 min read · 🎧 10 min listen · ✎ 3 quizzes · 🧪 ~90 min lab

Every FDE posting on your gap map asks for RAG — Databricks names it explicitly, right next to multi-agent systems and evals.6 But here's the field reality behind the buzzword: most RAG systems that fail in the enterprise don't fail because someone picked the wrong vector database. They fail because retrieval returns the wrong chunks, or because the model answers confidently even when retrieval returned nothing useful. In your capstone domain — a virtual-care provider whose clinicians will ask an assistant about clinical protocols — a confidently wrong answer isn't an embarrassing demo moment. It's a safety incident. This lesson is about engineering the two things that actually decide whether a RAG system is trustworthy: retrieval quality and grounding.

What RAG actually is — and where it actually breaks

RAG is one idea: instead of hoping the model memorised your customer's documents, you retrieve the relevant passages at question time and put them in the context window, then ask the model to answer from those passages. Everything else — embeddings, vector stores, rerankers — is plumbing in service of that idea. The practitioners' consensus from a year of production deployments is blunt: teams over-invest in the database and under-invest in retrieval quality, and hybrid keyword-plus-semantic search plus sensible chunking beats an exotic vector store almost every time.3

When a RAG system gives a wrong answer, an FDE's first job is diagnosis, and there are exactly two places to look. A retrieval failure means the right passage never made it into the context — the model literally couldn't have answered correctly. A grounding failure means the right passage was in the context and the model ignored it, blended it with its own prior knowledge, or answered a question the documents don't cover. The fixes are completely different, which is why guessing is expensive:

FailureSymptomWhere to fix it
Retrieval failureAnswer cites nothing relevant; correct passage absent from retrieved chunksChunking, embeddings, hybrid search, contextual retrieval, reranking
Grounding failureCorrect passage retrieved, but the answer contradicts it or adds unsupported claimsPrompting: mandatory quotes/citations, permission to say "I don't know"
Model failureRight passage retrieved AND faithfully used — answer still wrong (rare)Better model, or the task exceeds what RAG can do

Retrieval quality I: chunking is a real decision

Documents get split into chunks before embedding, and how you split them is a genuine engineering trade-off, not a default to accept. Small chunks embed precisely — the vector captures one idea — but strip away the context that makes the idea interpretable. Large chunks keep context but blur the embedding, so retrieval gets noisier and you burn context-window tokens on padding. And naive fixed-size splitting can cut a protocol's dosage table away from the heading that says which patients it applies to. The durable advice: chunk along the document's own structure (sections, headings, paragraphs) before reaching for fancier schemes, and test retrieval on real questions before trusting any strategy.3

Retrieval quality II: contextual retrieval. Anthropic's technique attacks chunking's core problem — a chunk that says "the escalation threshold is 39.5°C" loses meaning once separated from the document titled "Paediatric fever protocol". The fix: before embedding each chunk, have a model prepend a short chunk-specific explanation situating it in its source document. Combined with BM25 keyword matching, this cut retrieval failures by 49%; adding reranking — a second model that re-scores the top candidates for relevance before they reach the context — pushed the reduction to 67%.1 That's a two-thirds cut in the dominant failure mode, from preprocessing and a reranker, with no exotic infrastructure. You'll implement the contextual half in this lesson's lab and measure the improvement yourself.

Vintage check The tactical RAG advice cited in this lesson from applied-llms.org dates to mid-2024 — model names and prices in it are stale, but the retrieval-quality-first lessons have held up. FDE habit: always check a source's date, and separate its durable patterns from its perishable specifics.

Now grounding — the other half of trust. Anthropic's guidance for reducing hallucinations is refreshingly unmagical: explicitly allow the model to say "I don't know", and for document-based tasks, make it extract verbatim quotes first and cite them in the answer.2 Both work for the same reason: they change the model's job from "produce a plausible answer" to "produce an answer supported by this evidence, or decline." For the virtual-care provider, that's the difference between an assistant that says "per §3 of the fever protocol, escalate at 39.5°C" and one that improvises a threshold. A citation the clinician can check in one click is a trust feature, an audit feature, and a debugging feature all at once.

Refusals are a feature Product owners sometimes push back on "I don't know" — it feels like the AI failing. The FDE translation: a wrong answer costs you the customer's trust permanently; a refusal costs one escalation to a human. In regulated domains that trade is not close.

When RAG is the wrong tool

This is the AI-judgment rep for this lesson: customers now ask for "a RAG chatbot" by name, and part of your job is knowing when to talk them out of it. If the whole corpus is small — say, under a few hundred thousand tokens — you may not need retrieval at all: current models take 1M-token context windows, and putting the documents directly in context sidesteps every retrieval failure mode at the cost of more tokens per call.5 If the question needs live data — "what's this patient's current medication list?" — the answer is a tool call to the system of record (Lesson 03), not a stale document index. And if the customer wants deterministic answers to a small fixed set of questions, a curated FAQ beats any model. Persuasive models make bad architectures look good in demos; the FDE is paid to notice.7

SituationRight toolWhy
Large, mostly-static corpus; open-ended questionsRAGCan't fit everything in context; retrieval scales
Small corpus (fits in context comfortably)Long contextNo retrieval failures possible; simpler system
Answer lives in a live system (EHR, CRM, database)Tool useDocuments go stale; the API is the source of truth
Small fixed question set; zero error toleranceNo AIA curated FAQ is cheaper, deterministic, auditable
The mental model in one line A trustworthy RAG system is two disciplines, not one database: retrieval that reliably surfaces the right passage (chunking, contextual retrieval, reranking), and grounding that forces every answer to cite that passage — or decline.

🧪 Practical steps: grounded policy Q&A with before/after numbers (~90 min)

This lab produces the portfolio artifact hiring managers ask about in RAG interviews: not "I built a chatbot" but "I measured retrieval failures, applied contextual retrieval, and cut them — here are the numbers." You'll build a grounded Q&A system over synthetic clinical protocols for the virtual-care provider, with mandatory citations and honest refusals. Cost and latency tuning waits for Lesson 09 — today is about correctness. Full instructions live in labs/0004-grounded-policy-qa.md; the shape:

  1. Generate a synthetic corpus — use Claude to write ~10 short clinical protocol documents (triage escalation, telehealth prescribing, after-hours workflows…) for the fictional provider. Generating realistic synthetic data is itself an FDE skill — you'll lean on it hard in the Lesson 11 capstone.
  2. Build naive RAG — fixed-size chunking, embed or keyword-score the chunks, retrieve top-k into the prompt.
  3. Enforce grounding — the answer prompt requires a verbatim quote plus a citation (doc + section) for every claim, and instructs the model to answer INSUFFICIENT_CONTEXT when the retrieved passages don't support an answer.2
  4. Write 10 test questions with expected source sections — including 2 deliberately unanswerable ones (topics your corpus doesn't cover). Those two are where most RAG demos secretly fail.
  5. Measure — for each question, log whether the correct chunk was retrieved (retrieval), whether the answer cited it faithfully (grounding), and whether the unanswerable questions were refused. Count failures by type.
  6. Add contextual retrieval — use Claude to prepend a situating sentence to every chunk (the technique from the primary source1), re-index, re-run.
  7. Report before/after — a small table in README.md: retrieval failures, grounding failures, unanswerables handled, naive vs contextual. Honest numbers only — "contextual retrieval fixed 2 of my 3 retrieval failures" is a better interview story than fake perfection.
  8. Save everything to D:\Projects\FDE-Portfolio\l04-rag-qa\.

Feedback loop: bring your before/after table and one failing question to me in chat and I'll review it like a customer's sceptical clinical lead — are the numbers honest, is every answer actually traceable to a quote, and did the unanswerable questions get refused rather than improvised? This artifact feeds the Lesson 11 capstone engagement and is tracked in the course's artifact tracker.

🤖 Get your work reviewed

No chat here — this box replaces it. Copy the prompt into any AI assistant (Claude, ChatGPT, Gemini…), then paste your before/after report and code after it.

You are a senior Forward Deployed Engineer reviewing my work: a grounded RAG Q&A system over ~10 synthetic clinical-protocol documents for a virtual-care provider. It includes naive-chunking RAG, mandatory quote+citation grounding with refusal on unsupported questions, a 10-question test set (2 deliberately unanswerable), and a before/after measurement comparing naive chunking vs contextual retrieval (chunk-context prepending).

Grade each criterion as Strong / Adequate / Missing, with one sentence of evidence:
- Measurement honesty: failures are counted per type (retrieval vs grounding), the before/after numbers are plausible for a 10-question set, and remaining failures are reported rather than hidden.
- Citation enforcement: every answered question carries a verbatim quote plus a doc+section citation that actually appears in the corpus — spot-check two.
- Handling of unanswerables: both out-of-corpus questions produce a refusal (INSUFFICIENT_CONTEXT or equivalent), not a plausible-sounding improvised answer.

Be skeptical — pick the answer most likely to be subtly ungrounded and trace its citation back to the source text. Then ask me 2-3 follow-up questions a clinical-safety reviewer would ask. Finish with the single highest-leverage improvement before this could face real clinicians.

My report and code follow below.
🧭 Field practice this week

Check yourself — think like an FDE

Scenarios, not recall. Diagnose from the mental model — don't scroll up. Wrong picks stay live.

Scenario A

Your deployed policy Q&A assistant tells a nurse the after-hours escalation contact is "the on-call GP", but the current protocol says "the virtual ED team". You pull the logs: the correct protocol section WAS in the retrieved chunks sent to the model. The model's answer cited nothing. What's the failure — and the fix?

Scenario B

You're indexing the provider's clinical protocols. Retrieval keeps returning a chunk containing just a dosage table — with no indication of which protocol or patient group it belongs to — and the model misapplies it. A teammate suggests doubling the chunk size so tables keep their headings. What's the sharper call?

Scenario C

A customer asks you to "build a RAG chatbot" for three use cases: (a) answering questions over their 40-page onboarding handbook, (b) telling support agents a customer's current subscription status, and (c) open-ended Q&A over 20,000 historical policy documents. Where does RAG actually belong?

Primary source — read this
The standard writeup of the technique you implement in the lab: why chunks lose context, how prepending chunk-specific context plus BM25 cuts retrieval failures 49%, and how reranking pushes it to 67%. Includes the prompt and cost math. Pair it with Anthropic's reduce-hallucinations guide — the grounding half of this lesson in vendor-doc form.
Your one tangible win You can now diagnose a wrong RAG answer in minutes — retrieval, grounding, or model — instead of guessing at fixes. And your portfolio holds the proof: a grounded clinical Q&A system with mandatory citations, honest refusals, and a measured before/after showing what contextual retrieval bought you.
Questions? Any AI assistant is your teacher. Unsure whether your failure is retrieval or grounding, or whether your corpus is small enough for long context? Paste the relevant section of this lesson into your AI assistant along with your question — and for lab feedback, the review box above has you covered.

Recommended learning

Hand-picked follow-ups. None are required — the primary source above comes first.

References

  1. Anthropic, "Introducing Contextual Retrieval" (2024) — chunk-context prepending + BM25 cuts retrieval failures 49%; adding reranking reaches 67%.
  2. Anthropic, "Reduce hallucinations", Claude docs (current) — allow "I don't know"; ground answers in verbatim quotes and citations.
  3. Yan, Husain, Bischof, Frye, Liu, Shankar, "What We Learned from a Year of Building with LLMs" (2024) — retrieval quality over vector-store choice; hybrid search; chunking along document structure.
  4. Eugene Yan, "Patterns for Building LLM-based Systems & Products" (2023) — RAG among the seven core LLM-product patterns (framing only).
  5. Anthropic, "Context windows", Claude docs (current) — 1M-token context windows and long-context behaviour.
  6. Databricks, AI Engineer, FDE — job posting (2026) — "Experience building GenAI applications, including RAG, multi-agent systems, Text2SQL".
  7. Matt Gold, LinkedIn post on FDE hiring criteria (2026) — AI judgment: knowing when AI (or a given AI architecture) is the wrong answer; models are persuasive when wrong.