Generative AI / Intermediate: retrieval and controlled workflows / Lesson 8
RAG, grounding, and citations
Connect authorized retrieval to claim support and explicit abstention while recognizing that added context does not automatically make an answer true.
On this page
Lesson goals
- Explain the assumptions and trust boundaries of rag, grounding, and citations.
- Interpret both examples and distinguish offline fixture results from model or production evidence.
- Diagnose the listed failures and justify the worked decisions while preserving task, data, permission, and uncertainty contracts.
Define the retrieval-augmented contract
Retrieval-augmented generation combines retrieved material with a generator so the application can condition answers on selected evidence. The original RAG research describes particular trained retrieval-generation systems; current applications use many different architectures. Do not claim every product called RAG has the same training, update, security, or citation guarantees. Define the corpus, access scope, question type, freshness, answer requirements, and insufficient-evidence behavior. The first offline classifier distinguishes a missing-evidence case from a candidate that contradicts a supplied synthetic fact. It performs no actual retrieval or generation and does not measure a modelโs groundedness.
def classify(evidence, candidate_days):
if evidence is None:
return "insufficient_evidence"
if candidate_days != evidence["refund_days"]:
return "candidate_support_failure"
return "supported_fixture"
print(classify(None, 14))
print(classify({"refund_days": 14}, 30))
print(classify({"refund_days": 14}, 14))
insufficient_evidence
candidate_support_failure
supported_fixture
The labels separate absent support from contradiction in one exact-field fixture. They do not establish which real retriever or model caused a natural-language error.
Keep evidence selection and answer production separate
A retriever can return irrelevant, stale, unauthorized, or incomplete passages. A generator can ignore a good passage, combine incompatible versions, invent a fact, or cite the wrong source. A context packer can drop the key exception between those stages. The second pseudocode makes each boundary visible and requires a release decision after validation. It is vendor-neutral and non-runnable. A successful retrieval call is not a successful answer, and a syntactically valid answer is not proof that its claims follow from the evidence. Preserve stage-level records so the failing boundary can be identified without exposing protected content.
scope = enforce_caller_access(trusted_actor)
passages = retrieve_versioned_evidence(question, scope)
context = pack_required_qualifiers(passages, budget)
candidate = generate_under_task_contract(question, context)
checks = validate_claims_citations_and_policy(candidate, context)
return supported_answer_or_explicit_abstention(checks)
These conceptual functions are not an SDK and are not executed. The application retains responsibility for access, evidence packing, validation, and release.
Check citations for existence and support
A source ID should resolve to the actual authorized passage and version used, not merely a document with a plausible title. Verify that the cited text supports the relevant claim, unit, date, and exception. Citation presence, citation correctness, and coverage of all important claims are different properties. A passage may be authoritative only for one jurisdiction, product version, or time period. Conflicting evidence needs an explicit policy or review outcome rather than silent averaging. A correct citation can still point to an incorrect source, so provenance and source authority remain application responsibilities beyond text matching.
Make unsupported questions visible
An evidence-only system should not replace missing support with remembered or plausible text without saying so under a separate contract. Return insufficient evidence, request a specific authorized source, or route the case for review. Evaluate answerable and unanswerable fixtures together so abstention is useful rather than universal. Preserve the userโs actual question during query rewriting and summarization, including negation and scope. Do not treat a retrieved instruction as authority to change the task or tool permissions. RAG adds data from another trust boundary and therefore also adds prompt-injection and privacy questions.
Evaluate the end-to-end system and the stages
Track corpus coverage, authorized retrieval recall, context preservation, claim support, citation accuracy, abstention, and user usefulness separately. Freeze relevant document and configuration versions for comparisons. A local exact-fact fixture is not a substitute for representative human-reviewed natural-language cases. No model API, external corpus, database, network request, customer data, or paid inference is used here. Use primary research as evidence about its experimental setting and test the selected application under its own requirements. Grounding is a maintained evidence relationship, not a label attached by adding a vector store or telling the model to cite sources.
Common errors and fixes
A vector store is called a hallucination cure
- Why it happens
- Retrieval capability was confused with guaranteed support.
- How to fix it
- Evaluate each evidence and answer stage explicitly.
- Prevent it next time
- Keep unsupported and conflicting-source fixtures.
Citations exist but do not support the answer
- Why it happens
- ID resolution replaced entailment and coverage review.
- How to fix it
- Compare claims and qualifiers with actual cited passages.
- Prevent it next time
- Test valid-ID wrong-passage examples.
Query rewriting changes the question
- Why it happens
- Negation or user scope was lost during transformation.
- How to fix it
- Preserve and verify the original task constraints.
- Prevent it next time
- Evaluate rewritten and original queries with labeled evidence.
Check your understanding
1. The retriever returned the correct policy, but the answer changes a date. Where should error analysis look?
Show worked solution
Confirm the date survived context packing, then inspect candidate generation and support validation. Do not blame corpus absence when the required passage was present. A stage record should establish what each component actually received and released.
2. A citation points to a current policy but the question concerns last year. Is current evidence necessarily sufficient?
Show worked solution
No. Temporal scope is part of the claim. Retrieve the authorized applicable version or state that historical evidence is missing. Do not silently answer a different question just because a newer document is easier to retrieve.
Key takeaways
- Retrieval-augmented generation combines retrieved material with a generator so the application can condition answers on selected evidence.
- A source ID should resolve to the actual authorized passage and version used, not merely a document with a plausible title.
- Track corpus coverage, authorized retrieval recall, context preservation, claim support, citation accuracy, abstention, and user usefulness separately.