Important
This is a personal notes repository, not a verified textbook or a maintained library. It's the written record of working through retrieval-augmented generation end to end — starting from a structured course and continuing well past it into topics the course never covered. Treat it as a study reference and a map of the territory, not as ground truth to cite uncritically. See Scope, Sourcing & Limitations before relying on any single module.
- What is this?
- Why this exists
- How the notes are organized
- Module map
- Repository structure
- The companion project —
local_rag_lab - How to use this repo
- Scope, Sourcing & Limitations
- Contributing
- License
RAG Notes is a 60-file collection of long-form, deep-dive markdown notes covering retrieval-augmented generation from first principles through to enterprise-scale and research-adjacent territory: embeddings and vector search internals, chunking and hybrid retrieval, reranking and query transformation, grounded generation and hallucination control, graph RAG, agentic RAG, evaluation and observability, security and governance, and further into areas most RAG material skips entirely — knowledge drift, belief revision, temporal reasoning, causal experimentation, and confidence calibration.
Each module is written as prose-first explanation, not a slide summary: it motivates the problem, walks through the mechanism (often with diagrams built in plain text), and states the trade-offs plainly rather than presenting one technique as strictly better than another.
Most RAG material stops at "chunk it, embed it, retrieve top-k, stuff the prompt." That gets a demo working and falls apart in production. The gap between a RAG demo and a RAG system that survives contact with real data, real users, and real cost constraints is where most of this repository lives.
The first block of modules (01–14) follows a structured course, one module per practical lesson. From Module 15 onward, the notes go past the original curriculum — evaluation, debugging, security, drift, governance, agentic architectures, and a long tail of production and research topics that a fixed-length course doesn't have room for. The numbering is continuous on purpose: this is meant to read as one progression, not a course plus an appendix.
The 60 files fall into five loose parts. The numbering is sequential across all of them — the grouping below is just a reading aid, not a folder structure.
| Part | Modules | Theme |
|---|---|---|
| 0 — Map | 00 |
How the companion code project is laid out, and how to read a practical lab |
| I — Core Pipeline | 01–14 |
Everything needed to build one working RAG system end to end: embeddings, vector search, ingestion, chunking, hybrid retrieval, reranking, query transformation, context engineering, grounded generation, multi-hop retrieval, graph RAG, and a production capstone |
| II — Production Operations | 15–20 |
Making a working pipeline trustworthy and operable: evaluation and benchmarking, systematic debugging, security and access control, data/knowledge lifecycle, performance engineering, reliability engineering |
| III — Trust & Enterprise Scale | 21–26 |
Knowledge conflict and source trust, drift and freshness, enterprise architecture, governance/provenance/compliance, late-interaction reranking, and a decision framework for choosing what to actually build |
| IV — Advanced & Research Topics | 27–53 |
The long tail: agentic RAG, zero-trust security architecture, GNN-based knowledge graphs, agent memory, judge reliability, causal inference, uncertainty and calibration, temporal reasoning and belief revision, multimodal and code RAG, fine-tuning vs. RAG, economics, multilingual RAG, long-context trade-offs, closed-loop (Self-RAG/CRAG) architectures, RAPTOR, reasoning models, MCP, deep-research agents, and where the field is heading |
| V — Tooling & Deployment | 54–59 |
The operational stack: LangChain/LlamaIndex, containerization and Kubernetes, infrastructure-as-code and cloud deployment, workflow automation (n8n), observability tooling, and the full project lifecycle from PoC to maintenance |
Expand for the full 60-module index
Part 0 — Map
| # | File | Title |
|---|---|---|
| 00 | 00_PROJECT_STRUCTURE.md |
Canonical Project Structure — local_rag_lab/ |
Part I — Core Pipeline (01–14)
| # | File | Title |
|---|---|---|
| 01 | 01_RAG_Fundamentals_DEEP.md |
RAG Fundamentals & the Complete Pipeline |
| 02 | 02_Embeddings_Deep_Dive_DEEP.md |
Embeddings: From Zero to Transformer Internals |
| 03 | 03_Vector_Search_and_Databases_DEEP.md |
Vector Search & Vector Databases (ANN, HNSW, IVF, PQ) |
| 04 | 04_Document_Ingestion_DEEP.md |
Document Ingestion Pipelines |
| 05 | 05_Chunking_Strategies_DEEP.md |
Chunking Strategies Deep Dive |
| 06 | 06_Hybrid_Retrieval_DEEP.md |
Hybrid Retrieval: Sparse + Dense + Rank Fusion |
| 07 | 07_Reranking_DEEP.md |
Reranking: Cross-Encoders & Multi-Stage Retrieval |
| 08 | 08_Query_Transformation_DEEP.md |
Query Understanding & Transformation |
| 09 | 09_Advanced_Retrieval_Patterns_DEEP.md |
Advanced Retrieval Patterns |
| 10 | 10_Context_Engineering_DEEP.md |
Context Engineering & Compression |
| 11 | 11_Grounded_Generation_Hallucination_Control_DEEP.md |
Grounded Generation, Hallucination Control & Answer Verification |
| 12 | 12_MultiHop_Iterative_Retrieval_DEEP.md |
Multi-Hop RAG & Iterative Retrieval |
| 13 | 13_Graph_RAG_Knowledge_Graphs_DEEP.md |
Graph RAG & Knowledge Graphs |
| 14 | 14_Production_Architecture_Capstone_DEEP.md |
Production Architecture Blueprint & Capstone Project |
Part II — Production Operations (15–20)
| # | File | Title |
|---|---|---|
| 15 | 15_Evaluation_and_Benchmarking.md |
RAG Evaluation, Benchmarking & Observability |
| 16 | 16_Systematic_Debugging.md |
RAG Failure Modes & Systematic Debugging |
| 17 | 17_Security_and_Access_Control.md |
RAG Security, Privacy, Access Control & Adversarial Attacks |
| 18 | 18_Data_and_Knowledge_Architecture.md |
Production RAG Data & Knowledge Architecture |
| 19 | 19_Performance_Engineering.md |
RAG Performance Engineering & Scalability |
| 20 | 20_Reliability_Engineering.md |
RAG Reliability Engineering & Fault-Tolerant Architecture |
Part III — Trust & Enterprise Scale (21–26)
| # | File | Title |
|---|---|---|
| 21 | 21_Knowledge_Conflict_and_Trust_DEEP.md |
Knowledge Conflict Resolution, Source Authority & Trust-Aware RAG |
| 22 | 22_Knowledge_Drift_and_Freshness_DEEP.md |
RAG Data & Knowledge Drift, Freshness Engineering & Continuous Adaptation |
| 23 | 23_Enterprise_RAG_Architecture_DEEP.md |
Enterprise RAG Architecture & Production System Design |
| 24 | 24_Governance_Provenance_and_Compliance_DEEP.md |
RAG Data Governance, Knowledge Provenance, Lineage, Versioning & Compliance |
| 25 | 25_Late_Interaction_and_Coverage_Reranking_DEEP.md |
Reranking at Extreme Scale: Late Interaction, ColBERT-Style Scoring & Coverage-Aware Ranking |
| 26 | 26_Architecture_Decision_Framework_DEEP.md |
RAG Architecture Tradeoffs, Design Patterns & the Architecture Decision Framework |
Part IV — Advanced & Research Topics (27–53)
| # | File | Title |
|---|---|---|
| 27 | 27_Vector_Search_Internals_DEEP.md |
Vector Search Internals: ANN, HNSW, IVF, PQ, DiskANN & Billion-Scale Retrieval |
| 28 | 28_Agentic_RAG_Architecture_DEEP.md |
Agentic RAG: Planning, Tool Use, Memory, Safety & Multi-Agent Architecture |
| 29 | 29_Security_Architecture_and_Zero_Trust_DEEP.md |
RAG Security Architecture: Threat Modeling, Prompt Injection, Data Exfiltration & Zero-Trust RAG |
| 30 | 30_Advanced_Knowledge_Graphs_and_GNNs_DEEP.md |
Advanced Knowledge Representation: Ontologies, Entity Resolution at Scale & GNNs for RAG |
| 31 | 31_Agent_Memory_and_Long_Horizon_Planning_DEEP.md |
Agent Memory Architecture & Long-Horizon Planning Stability |
| 32 | 32_Advanced_Evaluation_and_Judge_Reliability_DEEP.md |
Advanced RAG Evaluation: Claim-Level Judging, Inter-Rater Reliability, Judge Hacking & Deployment Gates |
| 33 | 33_Causal_Inference_and_Experimentation_DEEP.md |
RAG Causal Inference & Advanced Experimentation: A/B Testing, Sequential Analysis & Adaptive Traffic Allocation |
| 34 | 34_Uncertainty_and_Probabilistic_Knowledge_DEEP.md |
Uncertainty, Probabilistic Knowledge & Confidence-Aware RAG |
| 35 | 35_The_Knowledge_Compiler_DEEP.md |
The Knowledge Compiler: RAG as a Distributed Query Execution Engine |
| 36 | 36_Self_Discovering_Knowledge_Fabric_DEEP.md |
Self-Discovering Knowledge Fabric: Schema, Entity, Relationship & Capability Intelligence |
| 37 | 37_Formal_Temporal_Reasoning_Allen_Algebra_DEEP.md |
Formal Temporal Reasoning: Allen Interval Algebra, Relation Composition & Path Consistency |
| 38 | 38_Belief_Revision_and_Truth_Maintenance_DEEP.md |
Belief Revision, Multi-World Reasoning & Truth Maintenance Systems |
| 39 | 39_Production_Confidence_Calibration_DEEP.md |
Production Confidence Calibration: Brier Scoring, Drift Detection & Hysteresis-Controlled Reliability |
| 40 | 40_Provenance_as_a_Database_DEEP.md |
Provenance as a Persistent Database: Lineage Storage, Graph Validation & Time-Scoped Queries |
| 41 | 41_Claim_Dependency_Graphs_and_Interval_Evidence_DEEP.md |
Claim Dependency Graphs, Confidence Propagation & Interval-Level Evidence Attribution |
| 42 | 42_Multimodal_RAG_DEEP.md |
Multimodal RAG: Cross-Modal Embeddings, Page-Image Retrieval & Unified Multimodal Indexing |
| 43 | 43_RAG_for_Code_and_Structured_Data_DEEP.md |
RAG for Code & Structured Data: AST-Aware Chunking, Code Retrieval & Text-to-SQL |
| 44 | 44_Fine_Tuning_vs_RAG_DEEP.md |
Fine-Tuning vs. RAG: Embedding Fine-Tuning, LoRA Adapters, RAFT & the Hybrid Decision Framework |
| 45 | 45_RAG_Economics_and_FinOps_DEEP.md |
RAG Economics & FinOps: Unit Economics, Cost Modeling & Build-vs-Buy |
| 46 | 46_Multilingual_and_Cross_Lingual_RAG_DEEP.md |
Multilingual & Cross-Lingual RAG |
| 47 | 47_Long_Context_vs_RAG_DEEP.md |
Long-Context vs. RAG: The Context Window Tradeoff, Rigorously |
| 48 | 48_Closed_Loop_RAG_Self_RAG_CRAG_DEEP.md |
Closed-Loop RAG: Self-RAG, Corrective RAG & Reflection-Token Architectures |
| 49 | 49_RAPTOR_and_Contextual_Retrieval_DEEP.md |
RAPTOR & Contextual Retrieval: Hierarchical Trees and Chunk-Contextualization |
| 50 | 50_Reasoning_Models_TestTime_Compute_and_Reward_Hacking_DEEP.md |
Reasoning Models & Test-Time Compute in RAG, and Reward Hacking in Self-Optimizing Control Loops |
| 51 | 51_MCP_and_Interoperability_DEEP.md |
Interoperability Protocols: MCP and the Standardization of Tool & Retrieval Access |
| 52 | 52_Agentic_Deep_Research_Systems_DEEP.md |
Agentic Deep Research Systems: Multi-Agent Investigation & Report Synthesis |
| 53 | 53_RAG_Trends_and_Future_Trajectory_DEEP.md |
RAG Trends & Future Trajectory: What's Settling, What's Converging, What's Speculative |
Part V — Tooling & Deployment (54–59)
| # | File | Title |
|---|---|---|
| 54 | 54_LangChain_and_LlamaIndex_DEEP.md |
LangChain & LlamaIndex: Framework Integration |
| 55 | 55_Containerization_and_Kubernetes_DEEP.md |
Containerization & Kubernetes for RAG Systems |
| 56 | 56_IaC_and_Cloud_Specific_Deployment_DEEP.md |
Infrastructure as Code & Cloud-Specific RAG Deployment Patterns |
| 57 | 57_n8n_and_Workflow_Automation_DEEP.md |
n8n & Workflow Automation for RAG Systems |
| 58 | 58_Observability_Tooling_DEEP.md |
Observability Tooling: LangSmith, Langfuse, Arize Phoenix & Prometheus/Grafana |
| 59 | 59_RAG_Project_Lifecycle_and_Maintenance_DEEP.md |
RAG Project Lifecycle: Planning, the PoC-to-Production Gap & Maintenance Runbooks |
RAG_Notes/
├── 00_PROJECT_STRUCTURE.md # Map for the companion code project, local_rag_lab/
│
├── 01–14 (Core Pipeline) # Deep Modules 1–14: build one RAG system end to end
├── 15–20 (Production Operations) # Eval, debugging, security, data lifecycle, perf, reliability
├── 21–26 (Trust & Enterprise) # Conflict/trust, drift, enterprise design, governance, decision framework
├── 27–53 (Advanced & Research) # Agentic RAG, GraphRAG/GNNs, calibration, temporal & causal reasoning, and more
└── 54–59 (Tooling & Deployment) # Frameworks, containers, IaC, workflow automation, observability, lifecycle
Every file is self-contained: it can be read on its own, but later modules regularly assume the vocabulary and diagrams introduced earlier, so reading roughly in numeric order is the intended path (see How to use this repo).
00_PROJECT_STRUCTURE.md is different from the rest of the repository: it isn't a topic module, it's the map for a single, continuously-growing hands-on project referenced throughout Modules 1–14 (and beyond). The convention it describes:
- One feature = one file in
src/(chunker.py,reranker.py,hybrid_retriever.py, …), each with a matchingtests/test_X.pyto validate it in isolation before it's wired into the full pipeline. - Learning-oriented scripts you're meant to run and read the output of are named
inspect_X.py(e.g.inspect_reranking.pyprints before/after rankings) — these are not automated tests. - All configuration — model names, thresholds, budgets — lives in one growing file,
src/config.py, never hard-coded elsewhere.
Every practical lab referenced across the modules tells you exactly which file(s) it creates or edits against that structure, so by the later modules you have one coherent system rather than a dozen disconnected scripts. See 00_PROJECT_STRUCTURE.md for the full annotated file tree and config.py growth history.
This repository ships the notes, not the lab's source code. The structure file is included because several modules reference it directly.
- Learning RAG from scratch: start at
01and read in order through at least14— that block is a complete, self-contained pipeline. Continue into15–26for anything you intend to put in front of real users. - Already building a RAG system and stuck on one piece: jump straight to the relevant module using the module map — each file is written to stand on its own with enough context to be useful in isolation.
- Deciding what to build at all: read
26_Architecture_Decision_Framework_DEEP.mdfirst. It's written as the closing module on purpose — the most common real failure isn't missing a technique, it's turning on every technique for every query. - Chasing a specific advanced topic (temporal reasoning, belief revision, causal experimentation, judge reliability, and similar): Part IV (
27–53) is organized as a reference set, not a strict sequence — pick the module that matches your question.
Stated plainly, for anyone deciding how much weight to put on these notes:
- These are study notes, not a peer-reviewed reference. The earlier modules (01–14) track a structured course closely; later modules extend past that course into territory the notes author researched and wrote up independently. Treat claims about specific numbers, algorithm names, or product behavior as a starting point for your own verification, not a citation.
- No accompanying source code is included in this repository. Modules reference a hands-on project (
local_rag_lab) and its file layout, but the implementation itself lives outside this repo. - Coverage is uneven by design. Some modules are broad surveys (e.g.
54on framework integration); others are narrow and formal (e.g.37on Allen interval algebra). Depth reflects where the notes author went deep, not a judgment about what matters most in every context. - Some later modules describe patterns and systems that are more exploratory or speculative than the earlier production-focused ones (e.g.
35–41on knowledge compilation, belief revision, and provenance-as-a-database) — read those as design thinking to stress-test, not established best practice.
If you spot something factually wrong, outdated, or unclear in any module, an issue or pull request is welcome — corrections and alternate perspectives are especially useful for the more speculative later modules.
Licensed under the MIT License.