Back to Curriculum
IntermediateModern AI

RAG

Retrieval Augmented Generation for grounding AI.

Interactive Playground

Initializing Interactive Playground...

Research-Level Deep Dive & Equations

Retrieval-Augmented Generation (Lewis et al., 2020) shifts the LLM paradigm from relying exclusively on **parametric knowledge** (factual associations stored in model weights) to **non-parametric knowledge** (retrieved documents from an external corpus).
RAG treats the retrieved document as a latent variable. Given an input query , we formulate the probability of generating target response by marginalizing over the set of retrieved documents found by a retriever model :
### 1. RAG-Sequence Model: The model retrieves a set of top documents for the query, and uses each document to generate the entire response sequence. We sum the probabilities across all documents:
### 2. RAG-Token Model: The model retrieves a set of top documents, but dynamically shifts which document it focuses on at each individual token step. This allows the generator to synthesize details from multiple distinct documents into a single sentence:
This probabilistic framework allows the generator to ground its outputs in external, verifiable sources. By passing retrieved contexts directly into the input context window, we bypass the LLM's **knowledge cutoff** and provide domain-specific, up-to-date details without requiring parameter updates.

Key Equations

Test Your Knowledge

Check whether you have mastered this concept with a quick quiz.

Was this lesson helpful?

Your feedback helps us continuously improve the curriculum and interactive visualizations.