Reference · How-to · ~10 min

How to add citations to RAG answers

Last updated

Users trust answers they can **click back to source chunks**.

Users trust answers they can **click back to source chunks**.

Steps

1. **Tag chunks** with stable IDs and human labels (`faq.md § Refunds`)

2. **Pass IDs in context** — prefix each chunk: `[doc:faq#3] …text…`

3. **Prompt for cites** — "Quote supporting lines; cite chunk IDs"

4. **Parse citations** from model output or use structured JSON

5. **Render links** in UI — map chunk ID → URL or modal snippet

6. **Validate** — refuse to show cite if ID wasn't in retrieved set

Prompt snippet

Use ONLY the notes below. After each claim, cite the chunk ID in brackets.
If unsupported, say "Not in the notes."
Notes:
[doc:policy#1] Annual plans refund within 14 days…
[doc:policy#2] Monthly plans are non-refundable…
Question: Can I refund my annual plan after 20 days?

Quality check

Ask a question whose answer spans two docs — both sources should appear.

**Try the lessons:** `build-mini-rag` (Lane D) · `rag-pipeline-steps` (Lane C)