Skip to content

RAG — Retrieval-Augmented Generation

Intermediate · 8 topics

RAG is the most-asked GenAI interview topic, and the most common thing companies actually ship: a chatbot or assistant that answers from your documents instead of the model's memory. It ties together everything earlier in the notes: NLP for cleaning and chunking text, embeddings and vector databases for search, and LLMs for writing the answer. This series takes you from a 60-line pipeline to a system you could defend in a design review.

# Nothing to install. Every example on these pages uses only the Python standard library and runs offline.
# Code that needs an API key is marked "no-run".
# Topic Sub-topics
1 The RAG pipeline end to end Why RAG · indexing vs query pipeline · a complete mini RAG · the grounded prompt · where each stage fails · RAG vs fine-tuning vs long context
2 Loading & parsing documents The document record · loaders per format · PDFs, headers and footers · tables · scans and layout-aware parsers · metadata
3 Chunking for RAG Recap from NLP · choosing size and overlap · semantic chunking · contextual chunk headers · code, tables and FAQs
4 Better retrieval Query rewriting · multi-query + RRF · HyDE · reranking with cross-encoders · MMR for diversity · filters and routing
5 Parent–child retrieval & GraphRAG Small-to-big retrieval · sentence windows · multi-hop questions · knowledge graphs · GraphRAG local and global search
6 Citations Source IDs in the prompt · inline markers · rendering sources · validating citations · quote-level grounding
7 Evaluation with RAGAS Retrieval vs generation metrics · faithfulness, answer relevancy, context precision and recall · running RAGAS · debugging · evals in CI
8 RAG production checklist Ingestion · retrieval · generation · security · evaluation · observability · cost and latency · common mistakes
flowchart LR
    subgraph Indexing [Indexing — offline]
        D[Documents] --> P[Load & parse] --> C[Chunk] --> E[Embed] --> V[(Vector DB)]
    end
    subgraph Query [Query — per question]
        Q[Question] --> R[Rewrite] --> S[Retrieve + rerank]
        V --> S --> B[Prompt with sources] --> L[LLM] --> A[Answer + citations]
    end

Before you start

These pages build on chunking, BM25 and hybrid search, vector search and indexes, prompt engineering and evaluation & guardrails. To see the whole thing working with a real LLM, follow the RAG chatbot template. For the system-design view, read Production RAG architecture.

Back to: Notes overview