Learn AI Math

Topic 14 of 20 · 29 words

Retrieval-Augmented Generation (RAG)

Connecting LLMs to external documents and databases through parsing, chunking, hybrid retrieval, reranking, and cited grounding.

✎ Napkin Diagram · Topic 14RAG (Retrieval-Augmented Generation): The Open-Book Exam
PNG ↗
RAG (Retrieval-Augmented Generation): The Open-Book Exam Simple cartoon comparing an AI guessing from memory and making things up versus RAG: 1. Search your real documents, 2. Hand the exact page to the AI, 3. Get a factual answer with a page citation. ✗ WITHOUT RAGAI tries to remember from years ago → "Um, I think your refund policy is 90 days?"(Makes up a confident wrong guess — called a "Hallucination"!)✓ WITH RAG = OPEN-BOOK EXAM 1. Search Your DocsFinds the exact paragraphin your real Handbook PDF 2. Clip to the Question"Use ONLY page 4 aboveto answer the customer"3. Fact-Checked Reply"Refunds take 30 days."Source: Page 4 [Link] getaimath.com
Without RAG, AI answers from blurry memory; with RAG, it opens your real documents to the right page before answering.

The 29 words, in learning order

Start at 1. Each word builds on the ones before it.

  1. Retrieval-Augmented Generation (RAG)RAG is a way to make an AI answer using real documents: first it searches for relevant information, then it writes an answer based on what it found.
  2. Retrieval PipelineA retrieval pipeline is the set of steps that finds and prepares information for an AI model to use.
  3. IndexingIndexing is organizing documents ahead of time so they can be searched quickly.
  4. Document ParsingDocument parsing is reading files like PDFs, Word documents or web pages and pulling out their content and structure.
  5. Document LoadingDocument loading is bringing documents from sources like folders, websites, databases or apps into an AI system.
  6. Text ExtractionText extraction is pulling readable text out of files, images or web pages.
  7. ChunkingChunking splits long documents into smaller pieces before turning them into embeddings for search.
  8. Embedding GenerationEmbedding generation is turning chunks of text into embeddings using an embedding model.
  9. Vector IndexA vector index is a special data structure that organizes embeddings so similar ones can be found quickly.
  10. Vector DatabaseA vector database is a database built to store embeddings and quickly find the ones most similar to a query.
  11. RetrieverA retriever is the component that takes a question and returns the most relevant pieces of information.
  12. Query TransformationQuery transformation is rewriting a user's question to make it easier to search for.
  13. Query ExpansionQuery expansion adds related words or alternative phrasings to a search query to find more relevant results.
  14. Hybrid SearchHybrid search combines keyword search and semantic vector search to get better results than either alone.
  15. RerankingReranking reorders search results with a more careful model so the most relevant ones end up on top.
  16. Context InjectionContext injection is placing retrieved information into the model's prompt so it can use it to answer.
  17. GroundingGrounding means making an AI's answer based on real, verifiable sources instead of the model's guesses.
  18. Citation GenerationCitation generation is when an AI shows which sources support each part of its answer.
  19. Knowledge BaseA knowledge base is an organized collection of information, like documents, FAQs and guides, that a system can search.
  20. Knowledge GraphA knowledge graph stores information as a network of things and the relationships between them.
  21. Graph RAGGraph RAG is a version of RAG that uses a knowledge graph to retrieve connected information, not just similar text chunks.
  22. Agentic RAGAgentic RAG lets an AI agent decide when and how to search, possibly searching several times and checking its own results.
  23. Corrective RAGCorrective RAG checks whether the retrieved documents are actually useful and fixes the process if they are not.
  24. Adaptive RAGAdaptive RAG changes its strategy based on the question, using no retrieval, simple retrieval or multi-step retrieval as needed.
  25. Multi-hop RetrievalMulti-hop retrieval answers questions that need several pieces of information found in steps, where each step depends on the last.
  26. Retrieval PrecisionRetrieval precision is the share of retrieved documents that are actually relevant.
  27. Retrieval RecallRetrieval recall is the share of all relevant documents that the system manages to retrieve.
  28. Answer FaithfulnessAnswer faithfulness is how well an AI's answer sticks to the information in its provided sources, without adding made-up claims.
  29. Retrieval EvaluationRetrieval evaluation is measuring how well a system finds the right information, using metrics like precision and recall.

How Retrieval-Augmented Generation (RAG) fits together

Retrieval-Augmented Generation (RAG) solves two classic LLM weaknesses—outdated knowledge cutoffs and made-up facts—by looking up trustworthy documents before answering. Instead of hoping the model memorized your company handbook during training, a RAG pipeline parses documents, splits them into clean chunks, retrieves the best matches, reranks them for relevance, and injects them into the prompt.

Advanced patterns like Hybrid RAG, Graph RAG, Corrective RAG, and Agentic RAG let the system rewrite vague questions, check whether retrieved passages actually answer the query, and attach verifiable citations.