RAG Pipelines and Citations
Connect retrieval to generation
Retrieval augmented generation supplies external evidence to a generative model. The retrieval index does not change the generator's weights. This makes it practical to refresh documents independently, but every component still needs measurement.
flowchart TD A[Documents] --> B[Parse and chunk] B --> C[Embed and index] D[User question] --> E[Authorize and retrieve] C --> E E --> F[Build evidence context] F --> G[Generate answer with source IDs] G --> H[Validate support and references] H --> I[Answer or abstain]
A complete evidence contract
For each selected chunk, supply a stable source ID, a title, version information, and the relevant passage. Ask the generator to cite only IDs in that context. Validate references against the retrieved source set before displaying them.
EVIDENCE
[refund-v2] Effective policy: Standard purchases are refundable
within 14 days. Custom orders are excluded.
QUESTION
Can I refund a custom order bought yesterday?
SUPPORTED ANSWER
The supplied policy excludes custom orders [refund-v2].Do not allow a generated source ID to become an arbitrary URL fetched by your backend. Resolve IDs through your own trusted source registry.
Failure diagnosis
Separate retrieval failure from generation failure. If the correct passage was not retrieved, change indexing, query construction, or ranking. If correct evidence was present but the model ignored the exception, improve instructions, evidence layout, model choice, or validation.
Evaluate answerable and unanswerable questions. Asking “What is the CEO's private phone number?” when no authorized source contains it should not produce a guessed answer or retrieve inaccessible records.
Tradeoffs and extensions
Query rewriting can recover vocabulary mismatches but may change intent. Multi-query retrieval can improve coverage at extra latency. Parent-child retrieval searches small chunks then adds a larger source context. Graph-based retrieval can help relationship-heavy datasets, but introduces extraction and maintenance complexity. Choose extensions based on measured failure patterns.
Fine-tuning can improve a model's use of evidence or output format, while retrieval provides changing knowledge. A bigger context window can complement retrieval but does not remove the need for access control and relevance selection.
Checkpoint with answers
Does a valid source ID establish claim support? No. It establishes that the reference exists; inspect whether the cited passage supports each important claim.
What should a RAG evaluation store? Question, expected answerability, expected supporting sources, acceptable answer criteria, retrieved sources, and actual output.
Reference
Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks is a foundational paper on combining retrieval and generation.