How / What / When

How / Answer

How to implement RAG in an LLM application

Implement RAG as a small pipeline: prepare trustworthy documents, retrieve relevant passages, pass them to the model with a grounded instruction, and evaluate retrieval and answer quality separately.

For developers building a first reliable retrieval-augmented feature. · Reviewed 2026-09-29

1. Define the question set first

Write the questions your application must answer. Include questions whose answer is missing. This becomes the evaluation set and prevents you from choosing a database or embedding model before you know what “good retrieval” means.

2. Prepare documents with metadata

  • Keep the source title, URL, owner, version, and effective date.
  • Remove navigation, duplicate boilerplate, and obsolete versions.
  • Split content at meaningful boundaries rather than arbitrary character counts.
  • Keep enough context for a passage to make sense on its own.

3. Retrieve, filter, and ground

Retrieve more candidates than you plan to show, then filter by permissions, date, or document type. Tell the model to answer from the supplied passages, cite the supporting source, and say when the passages do not answer the question.

4. Evaluate before adding complexity

LayerUseful measurement
RetrievalRecall@K or whether the supporting passage appears in the candidates
GroundingWhether each material claim is supported by the context
AnswerUsefulness, completeness, and correct abstention
OperationsLatency, cost, document updates, and permission failures

The first production safeguard

Log the retrieved source IDs and the final answer version. Without that trail, a bad answer becomes a debate about the model instead of a debuggable failure in ingestion, retrieval, prompting, or review.

Keep learning

Get one useful AI answer each week.