What is RAG (retrieval-augmented generation)?

Retrieval-augmented generation (RAG) is a pattern where an application first retrieves relevant passages from your own data, then gives them to a large language model so it answers from those sources and can cite them.

Also called RAG, RAG pipeline, retrieval augmented generationUpdated

A large language model only knows what was in its training data. That data stops at a cut-off date and never included your contracts, policies or product catalogue. Retrieval-augmented generation (RAG) fixes this at question time. Before the model answers, your application searches your own content, picks the few passages most likely to hold the answer and adds them to the prompt. The model then writes its answer from those passages instead of from memory.

The name comes from a 2020 research paper by Lewis and colleagues at Facebook AI Research, which paired a text generator with a searchable index of Wikipedia. Today "RAG" usually means the general pattern, whatever model or search engine you use.

How a RAG pipeline works

A RAG system has two halves.

Indexing, done ahead of time:

  1. Split documents into passages (chunks) of a few hundred words, keeping the title and section heading with each one.
  2. Turn each chunk into an embedding, a list of numbers that captures its meaning.
  3. Store the embeddings, the text and metadata such as owner, date and access rights in a vector database or search engine.

Answering, done for every question:

  1. Embed the user's question with the same model.
  2. Retrieve the closest chunks, usually combining semantic search with keyword search, and filter by what this user is allowed to see.
  3. Optionally re-rank the top results with a second model.
  4. Send the best few chunks to the LLM with an instruction to answer only from them and cite which one it used.

Example: an HR policy assistant

An employee asks: "How many days of paternity leave do I get?" The retriever returns three chunks. The top one is section 4.2 of the company's leave policy:

[doc: leave-policy-2026.pdf, section 4.2]
Employees are entitled to 10 working days of paid paternity leave,
to be taken within 3 months of the child's birth or adoption.

The prompt sent to the model looks like this:

Answer using only the sources below and cite the source. If the
answer is not in the sources, say you don't know.
Sources: [1] leave-policy-2026.pdf §4.2 ... [2] ... [3] ...
Question: How many days of paternity leave do I get?

The answer: "You get 10 working days of paid paternity leave, to be taken within 3 months of the birth or adoption [1]." If HR changes the policy, the next answer changes as soon as the new document is re-indexed. Nothing is retrained.

RAG vs fine-tuning

RAG changes what the model can see for each request. Fine-tuning changes the model's weights so it behaves differently. Use RAG for knowledge that changes, needs citations or must respect per-user permissions. Use fine-tuning for a consistent format, tone or narrow task. Many production systems use both. Our article on RAG vs fine-tuning vs prompt engineering compares them in detail.

Where RAG goes wrong

  • The right chunk isn't retrieved. Most wrong answers trace back to retrieval, not the model. Measure retrieval on its own (did the correct passage appear in the top five?) as part of LLM evaluation.
  • Chunks lose their context. A paragraph that says "this limit" is useless once it's separated from its heading.
  • Permissions are applied after retrieval. Filter by user access inside the search query, before anything reaches the model.
  • Too much context. Stuffing twenty chunks into the context window costs more and can bury the one that matters.
  • Treating grounding as a cure for hallucination. RAG reduces it, but the model can still misread a source, so check the citations.

We build RAG systems over policies, regulations and product data through our data and AI team.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call