Grounded RAG
query → authorization/filter → retrieval → rerank → context builder
→ model → schema validator → citation/grounding check → answer or abstain- Evidence policy exists before and after generation.
Build a retrieval-augmented generation (RAG) pipeline that finds relevant evidence, gives it to the model, cites sources and abstains when the available evidence is not good enough.
Engineering focus: RAG: grounding, citations and failure modes
Build a retrieval-augmented generation (RAG) pipeline that finds relevant evidence, gives it to the model, cites sources and abstains when the available evidence is not good enough.
The rest of this module introduces the formal terminology and production controls behind that idea. You are not expected to memorize the vocabulary before using it.
Carry the same support assistant forward: approved KB, source citations, explicit insufficient-evidence fallback and one bounded read-only asset lookup. Reuse prior artifacts so each module adds evidence to one production AI system.
Retrieval-augmented generation supplies selected external evidence at inference time. It does not make the model intrinsically truthful, and it can introduce stale, irrelevant, poisoned or unauthorized context.
A grounded answer should be supported by the supplied evidence for the claims it makes. Citation presence alone is weak: a citation can be irrelevant or fail to support the nearby claim.
When retrieval returns no sufficient evidence, a trustworthy assistant should follow the fallback contract. Forcing an answer turns missing evidence into hallucination risk.
Deduplicate near-identical chunks, preserve source IDs, prioritize authoritative/fresh sources, apply access filters before model generation and reserve context budget for the actual answer.
Track retrieval recall/precision, context relevance, answer groundedness, citation correctness and task usefulness. A single aggregate score can hide the failing stage.
query → authorization/filter → retrieval → rerank → context builder
→ model → schema validator → citation/grounding check → answer or abstainMISS: evidence not retrieved
NOISE: irrelevant evidence dominates
CONFLICT: sources disagree
STALE: old version retrieved
INJECTION: retrieved text attacks instructions
UNGROUNDED: answer adds unsupported claimGoal: Use the KB and retrieval cases to create answer records that must carry source IDs and abstain when evidence is missing.
python3 - <<'PY2'
cases=[
{'q':'When is maintenance?','retrieved':['kb-22'],'answer':'Sunday at 02:00 UTC.','sources':['kb-22'],'status':'ANSWERED'},
{'q':'What is the VPN password?','retrieved':[],'answer':'','sources':[],'status':'INSUFFICIENT_EVIDENCE'}
]
for c in cases:
if c['status']=='ANSWERED': assert c['sources'] and set(c['sources'])<=set(c['retrieved'])
else: assert not c['answer'] and not c['sources']
print('PASS: answer/fallback contract',len(cases))
PY2Create two KB snippets with different maintenance windows and specify which metadata (effective date/authority) the retriever must use to resolve or expose the conflict.
For each answer claim, record the source passage that supports it. Do not give credit merely because a source ID appears somewhere in the response.
Enterprise RAG quality depends on evidence selection and attribution, not only model eloquence.
Use the lab pack to retrieve a small approved context and send only that context to a local chat model.
unzip -q public/labs/ai/AI-Engineering-Lab-Pack-v0.3.19-r2.zip -d /tmp/ai-lab-packpython3 /tmp/ai-lab-pack/scripts/simple_retriever.py 'password reset'MODEL=${MODEL:-qwen3:8b}; python3 /tmp/ai-lab-pack/scripts/build_grounded_prompt.py 'password reset' > /tmp/grounded-prompt.txt; head -80 /tmp/grounded-prompt.txtConcept and scenario checks. Reveal the answer only after you commit to a decision.
It supplies selected external evidence at inference time; it does not guarantee truthfulness.
The cited source actually supports the associated claim, not merely that a citation exists.
Before unauthorized content reaches model context, with policy enforced by trusted application logic.
Use the explicit insufficient-evidence fallback or escalation path rather than fabricate an answer.
Progress is saved in this browser immediately. When you sign in to My Learning, it can also sync across devices.
Attempt the core lab and knowledge checks before marking the module complete.