Stage 6: Retrieval-augmented generation
The RAG pipeline in build order: ingest, parse, chunk, embed, index, query, retrieve, rerank, generate and ground.
Summary, rules and context: AI Engineering Guide, Stage 6.
Learn
Curriculum lessons, in reading order.
Apply
Field-manual scenarios: implementation steps, an example, trade-offs, production notes, a checklist and metrics.
1-ingestion-parsing/
- Source ingestion → Connectors
- Source ingestion → Change detection (the size/mtime → SHA-256 ladder)
- Source ingestion → Deduplication (exact + near-duplicate)
- Source ingestion → Document versioning
- Source ingestion → Tenant / ACL capture at ingest
- OCR / digitization → Per-page classification and routing
- OCR / digitization → Digital document (native text layer → Docling)
- OCR / digitization → Scanned page (PaddleOCR)
- OCR / digitization → Complex layout (multi-column, forms → layout model)
- OCR / digitization → Formula-heavy page (MinerU / LaTeX extraction)
- OCR / digitization → Charts, images, diagrams (VLM captioning)
- Structure extraction → Reading order
- Structure extraction → Tables (emit as HTML/Markdown, never flattened)
- Structure extraction → Headings hierarchy (breadcrumbs)
- Structure extraction → Page numbers + bounding boxes (verifiable citations)
- Structure extraction → Headers / footers / boilerplate stripping
- Validation → Test-time validation against a golden sample
- Validation → Production per-page heuristics (no ground truth)
- Retry ladder → Bounded escalation with visible failure
2-chunking/
- Chunking → Fixed-size + overlap
- Chunking → Recursive character splitting
- Chunking → Layout / structure-aware
- Chunking → Semantic chunking
- Chunking → Parent–child (small-to-big)
- Chunking → Contextual retrieval (LLM-generated chunk context)
- Chunking → Late chunking
- Chunking → Metadata on every chunk
3-embeddings/
- Embeddings → Model choice (domain, language, dimensions, Matryoshka)
- Embeddings → Symmetric vs asymmetric (query/passage prefixes)
- Embeddings → Fine-tuning embeddings on your own logs
- Embeddings → Versioning & migration (dual-index cutover)
4-indexing/
- Indexing → Index types: Flat, HNSW, IVF-PQ (and tuning the recall/latency curve)
- Indexing → Vector store choice
- Indexing → Filtered search (pre-filter vs post-filter)
5-query-understanding/
- Query understanding → Query rewriting (coreference over chat history)
- Query understanding → Multi-query + Reciprocal Rank Fusion
- Query understanding → HyDE (Hypothetical Document Embeddings)
- Query understanding → Decomposition (multi-hop into sub-questions)
- Query understanding → Self-query (natural language → metadata filters)
- Query understanding → Routing (vector, SQL, graph, web, or no retrieval)
6-retrieval-ranking/
- Retrieval & ranking → Hybrid search (BM25 + dense, fused)
- Retrieval & ranking → Reranking (cross-encoder / late interaction)
- Retrieval & ranking → MMR / diversity
- Retrieval & ranking → Score thresholding & abstention
- Retrieval & ranking → Recursive / agentic retrieval (bounded follow-up searches)
7-advanced-rag/
- Advanced RAG → Agentic RAG (retrieval as a tool)
- Advanced RAG → Corrective RAG (CRAG): grade, then rewrite or fall back
- Advanced RAG → Self-RAG (reflection tokens: retrieve? supported? useful?)
- Advanced RAG → GraphRAG / knowledge graph
- Advanced RAG → Multimodal RAG (page images, ColPali, VLM descriptions)
- Advanced RAG → Structured + unstructured hybrid (SQL for numbers, vectors for narrative)
8-generation-grounding/
- Generation & grounding → Grounded prompting
- Generation & grounding → Citations (span-level, validated)
- Generation & grounding → Faithfulness check (is each claim entailed?)
- Generation & grounding → Conflict handling (when sources disagree)
- Generation & grounding → Refusal / no-answer path
Previous: Stage 5: Prompt and context engineering · Next: Stage 7: Tools, agents and memory