Retrieval-augmented generation
Fetching relevant documents and adding them to a prompt to ground answers.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
Overview
Retrieval-augmented generation (RAG) answers questions from your own documents. Documents are parsed and split into chunks, the chunks are indexed (usually with embeddings, often with keyword search as well), and at question time the most relevant chunks are retrieved and placed in the prompt with an instruction to answer from them and cite them.
Most RAG problems are retrieval problems: bad parsing of PDFs and tables, chunks that cut ideas in half, or a search that misses the right passage. Building RAG well means inspecting what was retrieved, adding hybrid search and reranking when needed, and measuring retrieval and answer quality separately with a golden set of questions.
What you will practise
- Parse and chunk documents while keeping headings and source locations
- Inspect retrieved passages before blaming the model
- Add hybrid search and reranking when plain vector search misses
- Measure retrieval and answer quality separately with a golden set
Learning paths
- AI foundations
A free AI foundations course: the working vocabulary of modern AI, from prompting and structured output to retrieval, MCP, Agent Skills and prompt injection.
- Local models and fine-tuning
Run open-weight models on your own hardware, use them on private documents, decide when fine-tuning beats RAG or long context, and try a small LoRA fine-tune.
- RAG engineer
A RAG course for engineers who want results they can measure: embeddings, pgvector, a pipeline built in a day, golden datasets, LLM judges and tracing.
Tutorials
- Chunking strategies for RAG, tested
Compare fixed-size, heading-based and semantic chunking on the same documents and questions, measure retrieval hit rate, and pick a strategy with evidence.
- Hybrid search and reranking in Postgres
Combine Postgres full-text search and pgvector with reciprocal rank fusion in one SQL query, rerank the top results with a cross-encoder, and measure the gain.
- Embeddings and vector search, hands on
Embed documents, store them in Postgres with pgvector, index them and run similarity and hybrid search.
- 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.
Workflow recipes
- Chat with private documents on a local model
Chat with PDFs locally: ask questions about contracts, notes and PDFs with Ollama and Open WebUI or LM Studio on your own computer, and check nothing leaves it.
- Evaluate RAG answers with a golden dataset
Set up RAG evaluation with a golden dataset and promptfoo: score retrieval, correctness and grounding for every question, and fail CI when answer quality drops.
- RAG pipeline in a day with Postgres and pgvector
Ingest your documents, answer with citations and measure retrieval against 20 questions written first.
Articles
- Context rot: why long contexts fail and what to do
Why models get worse as their context fills up, from lost-in-the-middle to distractors and poisoned context, and the practical fixes for agents and RAG.
- pgvector vs Pinecone, Qdrant and Weaviate
When storing embeddings in Postgres with pgvector is enough, and when a dedicated vector database such as Pinecone, Qdrant or Weaviate earns its extra cost.
- RAG vs long context vs fine-tuning: how to choose
What each approach changes, what it costs, where it fails, and a practical order to try them in before you commit to one.
Tools for this skill
9 of 27 tools tagged with this skill.
Amazon Bedrock
AWS service for foundation models, RAG and agents.
Chroma
Open-source embedding database that is quick to start locally, plus a hosted cloud.
Crawl4AI
Open-source crawler that turns web pages into clean Markdown or JSON for RAG and agents.
Dify
Visual platform for building and running LLM apps and agents, self-hosted or cloud.
Docling
Converts PDFs and office documents into structured output for LLM pipelines.
Faiss
Meta's library for vector similarity search and clustering.
Firecrawl
Crawls and scrapes websites into LLM-ready Markdown or structured data.
Flowise
Drag-and-drop agent and RAG builder, archived in August 2026.
Haystack
deepset's Python framework for RAG pipelines and agents built from components.
Key terms
Words you will meet while learning this, defined in the glossary.
- Agentic RAG
Retrieval-augmented generation in which an agent decides when and how to search, often running several searches and refining queries.
- Context precision and recall
RAG retrieval metrics: precision is the share of retrieved chunks that are relevant, recall the share of needed facts found.
- Contextual retrieval
Adding a short, model-written note on where each chunk sits in its source document before embedding and indexing the chunk.
- GraphRAG
Retrieval-augmented generation that uses a knowledge graph of entities and relationships to connect related facts across many documents.
- 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.
- HyDE
Hypothetical Document Embeddings: a model writes a fake answer to the query, and that answer's embedding is used to search for real documents.
- Knowledge graph
A structured representation of entities and the relationships between them, sometimes used alongside vector search to improve retrieval.
- Query rewriting
Using a model to turn a user's question into one or more better search queries before retrieval, to find more relevant results.
- Reranking
Re-scoring an initial set of retrieved results with a slower, more accurate model before passing only the best few on to the LLM.
- Retrieval-augmented generation (RAG)
Retrieving relevant documents and adding them to the prompt before the model generates an answer from them.