Skip to main content

Practical AI

RAG Explained: How AI Uses Your Own Data

Understand retrieval-augmented generation from document search and embeddings through context augmentation, generation, citations, and failure testing.

Role
Beginners, Product teams, Developers, Knowledge managers
Language
en
Duration
2026-08-28

Retrieval-augmented generation, or RAG, lets an AI application search a collection of information and place relevant excerpts into the model’s context before generating an answer. The model is not automatically retrained on those documents. It receives selected evidence for the current request.

The RAG flow

1. Prepare the source collection

Documents are cleaned, divided into useful chunks, and stored with metadata such as title, date, permissions, or product area. Chunk boundaries matter: pieces that are too small lose context, while pieces that are too large dilute the relevant passage.

2. Represent and search

An embedding maps text to a numerical representation useful for similarity. A query embedding can retrieve semantically related chunks even when wording differs. Keyword, metadata, and semantic search can be combined; reranking can improve the order.

3. Augment the context

The application places retrieved excerpts, source labels, and instructions into the model request. It should define how to handle insufficient or conflicting evidence and preserve the identifiers needed for citations.

4. Generate the answer

The model answers using the supplied context. A good interface makes sources visible so a reader can inspect whether the cited passage supports the claim. Retrieval reduces some knowledge problems, but it does not force the model to reason correctly.

RAG is not training or fine-tuning

Training changes model parameters by learning from data. Fine-tuning adjusts a model using examples, often to influence behavior or task performance. RAG changes the information supplied at request time. Use RAG when answers need current, private, or traceable knowledge; consider fine-tuning when the problem is repeatable behavior rather than missing facts.

Common failure modes

  • The correct document was never ingested or is out of date.
  • Chunking separates a rule from its exception.
  • Search retrieves text that is topically similar but not answer-bearing.
  • Permission filters expose a document the user should not see.
  • The prompt includes the right passage, but the answer contradicts or ignores it.
  • Citations point to retrieved text that does not support the specific claim.
  • The question has no answer in the collection, yet the model invents one.

How to evaluate a RAG system

Build a test set with answerable, unanswerable, ambiguous, and permission-sensitive questions. Evaluate retrieval separately from generation: first ask whether the needed evidence appears in the top results, then whether the response uses it faithfully. Review citation correctness, refusal behavior, latency, and behavior after documents change.

A useful first prototype

Choose a small set of documents you know well. Build search with source links before adding conversational complexity. Log the retrieved chunks beside each answer and inspect failures. The retrieval and RAG glossary entries, relevant courses, and AI Developer path provide the next layers.