Foundation Lab

Retrieval-Augmented Generation (RAG)

RAG is the dominant paradigm for grounding LLMs in external/updated knowledge

Concept 43 of 100RepresentationsPhase 9
#43RAGRepresentations
key equation
p(y∣x)=∑dp(d∣x)⋅p(y∣x,d)p(y|x) = \sum_{d} p(d|x) \cdot p(y|x, d)
Reading map and next steps

Selected Foundation Object

Keep the equation fixed; move through the evidence.

Concept 43 of 100RAGRepresentations / Phase 9: Advanced architectures & generation
Current question

RAG trades model capacity for external memory: smaller models + good retrieval can match larger models

p(y∣x)=∑dp(d∣x)⋅p(y∣x,d)p(y|x) = \sum_{d} p(d|x) \cdot p(y|x, d)
PredictionCommit before tracing the equation.

Ask what should change under a concrete input, then trace that expectation through the equation.

EvidenceCompare the equation and source.

Use the key equation and canonical papers as the available witnesses, without implying that a runnable panel exists.

InvariantName what survives notation changes.

The useful learning product is the reusable mechanism you can carry into another model, paper, or engineering tradeoff.

Next moveContinue through the atlas.

Use prerequisites, dependents, and semantic links to repair the next gap without leaving the object behind.

Why It Matters for Modern Models

  • RAG is the dominant paradigm for grounding LLMs in external/updated knowledge
  • Explains why vector databases and embedding search became critical infrastructure
  • Separates "what the model knows" from "what the model can access"—enables knowledge updates without retraining

What Tutorials Skip

What is still poorly explained in textbooks and papers:

  • RAG trades model capacity for external memory: smaller models + good retrieval can match larger models
  • Retrieval quality is bottleneck: irrelevant docs hurt more than no docs (noise injection)
  • The "lost in the middle" problem: LLMs struggle to use information from middle of long contexts—retrieval ranking matters

Visualization Status

Core Math (Optional Deep Dive)

If you want intuition first, start with the key equation and cited sources. Come back here for the full walkthrough.

Key Equation
p(y∣x)=∑dp(d∣x)⋅p(y∣x,d)p(y|x) = \sum_{d} p(d|x) \cdot p(y|x, d)

RAG augments generation with retrieved documents:

p(y∣x)=∑d∈top-kp(d∣x)⋅p(y∣x,d)p(y|x) = \sum_{d \in \text{top-}k} p(d|x) \cdot p(y|x, d)

Retrieval uses embedding similarity:

p(d∣x)∝exp⁡(sim(Eq(x),Ed(d))/τ)p(d|x) \propto \exp(\text{sim}(E_q(x), E_d(d)) / \tau)

where EqE_q, EdE_d are query/document encoders (often shared, e.g., BERT, Contriever).

Generation conditions on retrieved context:

p(y∣x,d1,…,dk)=∏tp(yt∣y<t,x,d1,…,dk)p(y|x, d_1, \ldots, d_k) = \prod_t p(y_t | y_{<t}, x, d_1, \ldots, d_k)

Canonical Papers

Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

Lewis et al.2020NeurIPS
Read paper →

Connections

Next Moves

Choose the next question to carry this object forward.