Skip to content

Building RAG Systems

Introduction

RAG (Retrieval-Augmented Generation) is currently the most mainstream LLM application technique. The core idea is simple: don't stuff all knowledge into the prompt — instead, "retrieve" relevant knowledge snippets when needed, then let the model generate based on that knowledge.

This addresses several fundamental LLM problems: - Hallucinations: Let the model answer based on retrieved real documents, not fabrication - Knowledge freshness: Training data has a cutoff date; RAG can connect to the latest external data - Domain knowledge: No fine-tuning needed to make the model "understand" your domain - Traceability: Answers can cite sources for user verification

Many "knowledge base Q&A" products you use today — customer service bots, document assistants, enterprise search — are essentially RAG under the hood. In Andrew Ng's Buildathon demo, RAG was the most frequently appearing building block.

Course Resources

Resource Summary

Beginner (understanding the full RAG pipeline):

Advanced (engineering-grade RAG):

Deep dive into retrieval quality (RAG bottlenecks are usually in retrieval, not generation):

Hands-on project:

Build a "personal knowledge base Q&A system" from scratch: 1. Pick a domain you're familiar with (course notes, technical docs, novel setting bibles) 2. Use LangChain or LlamaIndex for document loading and chunking 3. Choose an Embedding model (recommend text-embedding-ada-002 or open-source bge-large-zh) 4. Store in a vector database (recommend Qdrant or Chroma) 5. Connect to an LLM for Q&A 6. Evaluate results, iterate on retrieval strategy

Notes

The hard part of RAG isn't "stuffing documents in" — it's retrieval quality. 90% of RAG effectiveness problems come from chunking strategy, Embedding selection, or retrieval algorithms. Start by building the simplest possible RAG pipeline (can be done in ~50 lines of code), then spend time evaluating and improving retrieval quality. Both LangChain and LlamaIndex are great for learning, but production environments usually require custom components.