Article

RAG Fundamentals

Build answers from retrieved passages and test retrieval separately from generation.

5 min read2026-12-02beginnerBy m7mdbook
On this page

RAG Fundamentals

What retrieval adds

Retrieval-augmented generation (RAG) finds relevant material and supplies it to a language model as context for an answer. For a library question about renewing a loan, the system can retrieve renewal rules from the current policy and pass them to the model with the question. Updating the policy index can make the current wording available without retraining the model.

Prepare and retrieve passages

Split documents into passages that preserve useful context, such as a section heading with its paragraphs. Store identifiers, source URLs, and dates alongside the text. At query time, use keyword search, vector similarity, or both. Apply access and version filters before text reaches the model.

Answer with verifiable evidence

Give the model the selected passages and ask it to cite the ones it uses. Treat retrieved text as reference material and keep operational instructions separate. If the passages lack the answer, report the missing evidence or ask a focused follow-up.

Test retrieval and generation separately

Use questions with known answers and record the passages that support each one. First check whether retrieval returns those passages. Then check whether the answer accurately reflects them and the citations point to the right sources. Include an expired policy, a question with no answer, and a query containing an exact policy ID.