Retrieval Augmented Generation

Architecture, vector search, hybrid retrieval, and agentic RAG.

Companion learning site

RAG Tutorial

Step-by-step retrieval-augmented generation tutorials with enterprise patterns and implementations.

Continue on the dedicated site below—this portal keeps enterprise reference content alongside that curriculum.

Open RAG Tutorial →

00Introduction

Overview

Retrieval-Augmented Generation augments LLM prompts with externally retrieved evidence, grounding answers in enterprise or fresh data instead of parametric memory alone.

Technical Deep Dive

Formal flow: q → Retriever(D) → {d₁…dₖ} → Prompt(q, docs) → LLM → a. Reduces factual hallucination when retrieval recall is high. Bottleneck is usually retrieval quality, not generation.

Architectures: naive RAG, advanced (rerank, hybrid), modular (query router), agentic (iterative retrieve).

Practical Use Case

Support bot indexes 8k Confluence pages; answers include doc links; escalations drop 30% when retrieval MRR@5 > 0.85.

01Why RAG

Overview

RAG solves knowledge staleness, proprietary data access, and attribution requirements that pure fine-tuning cannot address cost-effectively.

Technical Deep Dive

Fine-tuning embeds knowledge in weights (expensive to update, opaque citations). RAG updates by re-indexing documents. Hybrid: RAG + light fine-tuning for tone/format.

When NOT to use RAG: tasks needing pure reasoning without external facts, ultra-low latency (<200ms), or when all knowledge fits reliably in context.

Practical Use Case

Pharma company uses RAG over clinical trial PDFs (updated weekly); fine-tuning only for regulatory writing style—avoids retraining 70B model per study release.

Query Embed Vector DB Retrieve LLM + Context

Chunking Strategies

Overview

Chunking splits documents into retrieval units; strategy directly impacts recall—too large dilutes relevance signals, too small loses coherence.

Technical Deep Dive

Fixed-size: 512 tokens, 10–20% overlap. Semantic: split at embedding discontinuities. Structure-aware: by heading, paragraph, table row. Parent-child: retrieve small, return large parent for context.

Tables need special handling (markdown/HTML preservation). Code: chunk by function/class.

Practical Use Case

API documentation chunked by endpoint (child) with section overview (parent)—developers get full endpoint page when any child matches query.

Vector Databases

Overview

Vector databases optimize approximate nearest neighbor (ANN) search over high-dimensional embeddings at million-to-billion scale with metadata filtering.

Technical Deep Dive

Algorithms: HNSW (graph-based, low latency), IVF (inverted files, memory efficient). Metrics: cosine, dot product, L2—match your embedding model training.

Compare: FAISS (library), Chroma (embedded), Qdrant/Weaviate/Milvus (distributed, filtering). Evaluate recall@k, QPS, filtering on tenant_id at 99th percentile latency.

Practical Use Case

Multi-tenant SaaS uses Qdrant with payload index on org_id; 50M vectors, p99 search 45ms, hybrid with Elasticsearch for SKU exact match.

Agentic RAG

Overview

Agentic RAG lets an LLM controller decide when to retrieve, rewrite queries, choose indexes, or iterate—handling multi-hop questions single-shot RAG misses.

Technical Deep Dive

Patterns: Self-RAG (reflect on relevance), corrective RAG (retry if low confidence), multi-index router. State tracks prior retrieval results to avoid duplicate search.

Costs more LLM calls—justify for analyst/research tiers not high-volume FAQ.

Practical Use Case

Competitive intelligence agent runs 3 retrieval rounds: broad industry scan → competitor filter → financial filing deep dive—synthesizes board-ready brief.