RAG: retrieval-augmented generation

Chunking strategy, embeddings, hybrid search (BM25 + vector), reranking, citation grounding. Retrieval quality, not the LLM, decides most RAG failures.

About 23 min read3-question knowledge check

The mental model

RAG turns a closed-book exam into an open-book one. Instead of hoping the model memorized your content during pretraining (it didn't — your internal wiki, last week's policy update, and your customer's contract were never in the training set), you retrieve the relevant pages at question time and let the model read them before answering. The analogy that holds up under pressure: a brilliant writer paired with a librarian. The writer (the LLM) is fluent and fast but knows nothing about your library. The librarian (retrieval) fetches the pages. Here is the part everyone learns the hard way: when the answer is wrong, it is usually the librarian's fault. The writer faithfully summarizes whatever it was handed — hand it the wrong pages and you get a fluent, confident, wrong answer.

Why RAG exists: fine-tuning cannot keep up with knowledge that changes daily, cannot cite sources, cannot enforce per-user access control on what the model "knows", and hallucinates when asked about facts it half-remembers. RAG makes knowledge a runtime input — updatable by re-indexing a document, auditable through citations, and permission-filterable per query. Without it, an LLM product over private data is either perpetually stale or perpetually lying.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision
RAG: retrieval-augmented generation — AI/ML lesson · PrepAtlas Tech