RAG & groundedness

P11.ir-rag.04 · Audience: guest, it-ml, language-pro · Prerequisites: Information retrieval & hybrid search, Re-ranking & IR metrics

Real LLM grading for this pageLLM grading (this page):

A plain LLM answers from frozen, unattributable parametric memory — and is confidently wrong when the answer isn't in it. Retrieval-augmented generation grounds the answer in retrieved passages: fresh, cited, and able to abstain. Most RAG failures are retrieval failures — which is why P11.ir-rag.01/.02 carry the load. (Cross-link: P10.llm-essentials.03 — reliability & grounding.)

Step 1 / 6What RAG is and why

RAG fixes three failures of a plain LLM at once:

  • Fresh — retrieve from a live index, so the answer reflects today's data, not the training cut-off.
  • Attributable — the answer cites the retrieved passages it used.
  • Grounded — the model answers only from those passages, and abstains when they don't support an answer.
question ─▶ retrieve (IR1) ─▶ re-rank (IR2) ─▶ [context] + prompt ─▶ LLM ─▶ grounded answer + citations └▶ abstain if context is weak

🎯 RAG = grounding an LLM in retrieved content. The generator is the easy part; the retriever, the grounding rule, and the abstention rule make the answer trustworthy.

Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Ctrl/Cmd + Enter to send

🎓 Practice ladder

3 graded rungs · ~33 min

Now build the RAG pieces yourself. Each rung is a three-panel workspace: instructions on the left, a code editor in the middle, output + test results on the right. Run checks the visible tests; Submit grades against hidden edge cases — overlap ≥ chunk size must raise, the out-of-scope query abstains, a threshold sweep flips answer↔abstain, and faithfulness averages only the answered cases. The senior rung rebuilds the whole groundedness evaluator.

Rung 1 — Chunk with overlap

Loading exercise…

Rung 2 — Answer or abstain

Loading exercise…

Senior rung — Score the RAG pipeline

Loading exercise…

⚡ Interview Ref — the quick-scan Reference face
  • RAG = grounding an LLM in retrieved content: fresh (live index), attributable (citations), grounded (answer only from context, else abstain).
  • Chunking: size trade-off (dilution vs lost context) + small overlap for straddling facts; metadata for pre-filters + citations.
  • Pipeline: chunk/filter → hybrid retrieve → re-rank → generate. Most RAG failures are retrieval failures.
  • Grounding rules: constrain to context · cite · abstain below threshold.
  • Eval: faithfulness · answer relevance · retrieval recall (the ceiling) · abstain rate (healthy > 0). Recall bounds the rest — fix retrieval first.
  • Healthcare: hard grounding, conservative abstain+escalate, audit trail, PII/PHI at every hop.

Try it yourself

A scratch console for this page's ideas — ungraded, nothing you run here is recorded.

Scratch console

A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.

Output appears here.

Where next?