T
TRKFLY AI
← All guides
RAG7 min read · Updated 2026-05
📚

What is RAG (Retrieval-Augmented Generation)?

Retrieval-Augmented Generation (RAG) is the dominant pattern for grounding LLMs in private or up-to-date data. Instead of storing all knowledge in the model's weights, you store it in a search index, retrieve the relevant pieces at query time, and let the LLM read them before answering.

The core idea, in one sentence

Retrieve relevant passages from an external corpus → put them in the LLM's context → generate the answer. That's it. The 'augmentation' is the retrieved context; the 'generation' is the LLM's response conditioned on it.

Why RAG instead of fine-tuning?

Fine-tuning teaches a model new behavior. RAG teaches it new facts. If your knowledge changes weekly, RAG wins — re-index, no retrain.

The 5-step RAG pipeline

Every production RAG system, no matter how fancy, fits this pipeline:

  • Ingest — chunk documents and store each chunk in a vector database with its embedding
  • Embed — convert the user query to an embedding using the same model
  • Retrieve — fetch the top-k most similar chunks via approximate nearest-neighbor search
  • Rerank (optional but recommended) — use a smaller, smarter model to re-order the top-k
  • Generate — pass query + top passages into the LLM with a 'use only the context' instruction

Why classic RAG is not enough anymore

Classic RAG retrieves once and hopes. In practice that fails when the query is multi-hop ('compare X and Y'), ambiguous, or when retrieval surfaces irrelevant passages. 2024–2025 saw four important upgrades:

  • CRAG (Corrective RAG) — a critic decides if retrieval was good; if not, falls back to web search
  • GraphRAG — builds a knowledge graph from documents; retrieves by graph traversal; great for multi-hop
  • Adaptive RAG — router decides: no retrieval, single-hop, or multi-hop based on query complexity
  • Multimodal RAG — retrieves text, images, tables together; essential for PDFs with charts

What you actually need in production

A working RAG system needs more than the 5 steps. Real systems have:

  • A good chunking strategy (chunk size silently destroys quality if it's wrong)
  • Hybrid retrieval (vector + keyword + reranker)
  • Evaluation with RAGAs, golden sets, and LLM-as-judge
  • Observability — trace every retrieve + rerank + generate call
  • Citation grounding — show which chunks the answer came from

Frequently asked questions

Is RAG the same as a vector database?

No. A vector database is one component (the retrieval store). RAG is the full pipeline of embedding + retrieve + augment + generate. Most RAG systems use a vector DB, but newer variants like GraphRAG add knowledge graphs.

Is RAG dead now that LLMs have long context windows?

No. Long context is expensive (quadratic attention cost) and slow. RAG narrows what the model has to attend to, which is cheaper and often more accurate than dumping a million tokens in.

RAG vs fine-tuning — which should I use?

Use RAG for facts that change or are too many to fit in weights. Use fine-tuning for behavior (tone, format, domain reasoning). Most production systems use both: fine-tune the small style/format, RAG the facts.

Keep learning — roadmaps
Read the papers
More guides