RAG
Intermediate 12 min read RAG

Citations & Sources

Every answer with its receipts

Citations turn RAG from a claim machine into an evidence machine. Design the citation format, verify them, and make them appear in the UI in the right places.

citationssourceschunk idsevidenceverification
Before we start

What you will learn

  • Design chunk-id citation format
  • Verify citations point at real content
  • Render citations in UI and APIs
Introduction

What is this?

Citations are the visible contract of grounding: each substantive claim carries the chunk id (ultimately a document link) that supports it. A citation system includes format (inline tags per sentence), verification (is the id real and containing?), and rendering (clickable footnotes in chat, structured metadata in APIs).

Motivation

Why do you need it?

  • Users must be able to check any claim — trust compounds.
  • Citations double as a debugging joystick: wrong citations are retrieval+verify signals.
  • Structured citations make downstream integrations AGREEABLE (CRMs, ticketing).
  • Verification converts 'the model said' into 'the source says'.
Think about it

Mental model

Imagine

A bibliography next to a research claim

Think of

RAG citations

A paper's vital first claim without a footnote gets challenged in review. Here every paragraph cites the exact chunk it rests on — not 'see whole library' but this page, this section, so a reader can flip to it and confirm.

Mechanics

How it works

  • Chunks carry stable ids and source metadata (doc, path, heading).
  • Prompt: 'End every claim with the id of the chunk that supports it.'
  • Parse the response for [id] markers; check each against the retrieved list.
  • Reject or re-send when citations reference unretrieved/fabricated ids.
  • Render: footnotes with links in chat; structured attribution objects in APIs.

Citation round trip.

Chunks
Generate
Parse
Verify
Render
Real world

In production

  • Support answers show which help-center page backs each step.
  • API responses include sources[] with docUrl, chunk, score for downstream legal flows.
  • Internal tools tint text by citation validity (good/bad link).
Guidelines

Best practices

  • Use a reserved marker format the model reliably emits (e.g. [1], <cite path=…>).
  • Verify every cited id: it must be in the retrieved set AND its text contains the claim.
  • Fall back to 'no citations' styling rather than showing unverified links.
  • Store citations with the answer for eval and audit.
Watch out

Common mistakes

  • No format: the model emits 'source' as free text you can't verify.
  • Showing citations that never get verified — fake receipts.
  • Splitting claims across chunks and citing only one.
  • Losing citation structure when chat history compacts.
Root cause analysis

Common issues

Error
Fabricated citation ids
Root cause

Model invents markers outside the retrieved set

Fix

Post-validate membership; provide the available ids explicitly to the model.

Error
Users click citations that don't match
Root cause

Verification missing or source metadata wrong

Fix

Containment-check each citation; fix source-metadata mapping.

When things break

Debugging tips

  • Citations to unretrieved ids = marker hallucination; enforce set membership.
  • Citations correct but wrong doc = reranker/retrieval confusion, not formatting.
  • Model refuses to cite = prompt tension (tone over rules); record and report.
Interviews

Interview checkpoint

Practice

Hands-on lab

Verifiable Citation Flow
35 min · intermediate
In progress
Objectives
  • Generate answers with chunk-id markers
  • Verify markers against the retrieved set
  • Deliver ungrounded answers to a review path

Verifiable Citation Flow

35 min · intermediate

0/4 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

A trustworthy citation must be…

2

Showing citations without verification is harmless.

Go deeper

Official documentation