Retrieval-Augmented Generation

Grounding LLM answers in retrieved, real source content instead of memory alone.

CurrentintermediateFull course available

Overview

RAG (retrieval-augmented generation) retrieves relevant source content (via keyword or vector search) and includes it in the model's prompt before generating an answer, grounding the response in real, citable text rather than the model's training-time memory alone -- reducing hallucination and enabling citations.

What it is
An architecture that retrieves relevant content and feeds it to an LLM as context before it generates an answer.
Why it's used
It grounds answers in real, current, citable source material and reduces confident-but-wrong answers (hallucination).
Where it fits
This platform's own optional AI tutor is a real, working RAG implementation over this platform's own lesson content -- not a hypothetical example.

Core concepts

  • Chunking documents
  • Retrieval (keyword, vector, or hybrid)
  • Grounding the prompt with retrieved context
  • Citations
  • Evaluating groundedness

Example

A relevance threshold that gates generation -- refusing to answer when retrieval found nothing relevant -- is one of the highest-leverage defenses against hallucination, and is exactly how this platform's own AI tutor behaves.

const relevant = searchLessonContent(question);
if (relevant.score < MIN_RELEVANCE_THRESHOLD) {
  return "Not enough evidence in the course content to answer that.";
}
// Otherwise, include 'relevant' in the prompt and generate, with citations.

Common use cases

  • Question-answering over private/internal documents
  • Grounded chat assistants with citations
  • This platform's own optional AI tutor

Project ideas

  • Build a small retrieval function over a handful of text documents and generate an answer that cites which document it came from

Official references