RAG (Retrieval-Augmented Generation)
π‘ Quick Definition: An AI architecture that retrieves relevant document chunks from external databases and injects them as dynamic context into a Large Language Model prompt.
Detailed Explanation & Workplace Application
Retrieval-Augmented Generation (RAG) grounds LLM outputs in domain-specific or private data without requiring full model retraining. While RAG significantly reduces factual errors by supplying source context, it does not eliminate hallucinations entirely. Common failure modes include retrieval misses (semantic mismatch between query and vector embeddings), chunk fragmentation (splitting critical context across chunk boundaries), and generation hallucination (the model ignoring or misinterpreting retrieved context when ambiguous). Reference: Lewis et al. (2020), "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks", NeurIPS. [Reviewed: January 2025]
Practical Syntax / Framework Formula
// Production RAG Architecture: 1. Ingestion: Document -> Semantic Chunking -> Vector Embeddings -> Indexing 2. Retrieval: User Query -> Query Embedding -> Top-K Vector Search + Hybrid BM25 Keyword Search 3. Re-Ranking: Cross-Encoder scores retrieved chunks for contextual relevance 4. Synthesis: LLM receives Prompt + Top Chunks -> Grounded Answer with Source Attribution