Retrieval-augmented generation (RAG)
Definition
Retrieving relevant documents and adding them to the prompt before the model generates an answer from them.
In more detail
A RAG system has an indexing side (parse, chunk, embed, store) and a query side (search, optionally rerank, then generate with the retrieved passages). It lets a model answer from private or recent information without retraining.
When RAG answers are wrong, check retrieval first: most failures come from the right passage not being found.
Related terms
Chunking
Splitting documents into pieces sized for embedding and retrieval, ideally along natural boundaries such as sections or paragraphs.
Embedding
A vector representation of text or other data that places items with similar meaning close together, so they can be searched by similarity.
Grounding
Tying a model's answers to specific provided sources or retrieved data, so that each claim can be traced back to a source and checked.
Hybrid search
Combining keyword search, such as BM25, with vector search and merging the results into one ranking, often with reciprocal rank fusion.
Agent memory
Information an agent keeps beyond a single context window, such as user preferences, past decisions or task notes, and retrieves when needed.
Agentic RAG
Retrieval-augmented generation in which an agent decides when and how to search, often running several searches and refining queries.
Read more about Retrieval-augmented generation (RAG)
- RAG fundamentals: retrieval before generation
What RAG is and how retrieval-augmented generation works, when it beats long context or fine-tuning, and a minimal working pipeline in about 80 lines of Python.
- RAG pipeline in a day with Postgres and pgvector
Ingest your documents, answer with citations and measure retrieval against 20 questions written first.
- RAG troubleshooting cheat sheet
Why a RAG system gives wrong answers, and what to check first: wrong document, right document but wrong answer, missing recent data, slow queries, with fixes.
- Retrieval-augmented generation
Fetching relevant documents and adding them to a prompt to ground answers.