# RAG Fundamentals

> Retrieve relevant chunks for a question, put them in the prompt, and have the model answer from them instead of from memory. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/rag-basics
Last updated: 2026-11-28

Retrieve relevant chunks for a question, put them in the prompt, and have the model answer from them instead of from memory.

Intermediate · about 6 hours · difficulty 3/5

Learn first: [Chunking Strategies](https://www.internhack.in/roadmaps/tracks/ai-engineer/chunking), [Structured Prompts and Long Context](https://www.internhack.in/roadmaps/tracks/ai-engineer/structured-prompts)

**Retrieval-augmented generation (RAG)** is the most common production LLM pattern. The model's built-in knowledge is frozen and generic; RAG injects fresh, private, relevant information at question time.

### The pipeline

1. **Ingest (offline)**: load documents, clean them, chunk, embed, store with metadata.
2. **Retrieve (online)**: embed the user question, fetch the top-k most similar chunks (optionally filtered).
3. **Augment**: build a prompt with the chunks in clearly tagged blocks plus instructions.
4. **Generate**: the model answers using only the provided context, and says so when the context is insufficient.

### Why RAG over alternatives

- Updating knowledge means re-indexing documents, not retraining a model.
- You can show **sources**, which builds trust and allows verification.
- Access control is enforced at retrieval time.
- Even with huge context windows, sending your entire knowledge base every request is slow and expensive; retrieval selects what matters. For small, stable corpora, simply putting everything in context (with caching) can be a valid alternative.

### Typical failure modes

- **Retrieval miss**: the answer exists but was not retrieved. The model then guesses or declines.
- **Wrong context**: similar-looking but irrelevant chunks lead to confident wrong answers.
- **Ignoring context**: the model answers from memory. Tighten instructions.

Most RAG quality problems are **retrieval** problems, not generation problems. Always inspect what was retrieved.

### Good enough to move on

You have a working question-answering app over a real document set that retrieves chunks, answers from them and admits when it does not know.

## Key concepts

- **Ingest, retrieve, augment, generate**
- **Top-k selection**
- **Grounding instructions**
- **RAG vs long context vs fine-tuning**
- **Inspecting retrieved context**: Debug retrieval first
- **Conversational RAG (follow-up questions)**

## Mini project

Build a question-answering app over your college or company handbook (or any public PDF set): ingestion script, retrieval endpoint, and a chat page that shows which chunks were used.

## Check yourself

The model gave a wrong answer in your RAG app. What is the first thing you check, and why?

## Free resources

- [LlamaIndex: RAG concepts](https://docs.llamaindex.ai/en/stable/understanding/rag/) (LlamaIndex)
- [Retrieval-Augmented Generation paper](https://arxiv.org/abs/2005.11401) (arXiv)
- [DeepLearning.AI short courses](https://www.deeplearning.ai/short-courses/) (DeepLearning.AI)

Previous: [Dedicated Vector Databases](https://www.internhack.in/roadmaps/tracks/ai-engineer/dedicated-vector-dbs) · Next: [Document Ingestion and Parsing](https://www.internhack.in/roadmaps/tracks/ai-engineer/document-ingestion)

## More in Retrieval-Augmented Generation

- [RAG Fundamentals](https://www.internhack.in/roadmaps/tracks/ai-engineer/rag-basics)
- [Document Ingestion and Parsing](https://www.internhack.in/roadmaps/tracks/ai-engineer/document-ingestion)
- [Hybrid Search: Keywords Plus Vectors](https://www.internhack.in/roadmaps/tracks/ai-engineer/hybrid-search)
- [Reranking Retrieved Results](https://www.internhack.in/roadmaps/tracks/ai-engineer/reranking)
- [Citations and Grounded Answers](https://www.internhack.in/roadmaps/tracks/ai-engineer/citations-grounding)
- [Evaluating Retrieval Quality](https://www.internhack.in/roadmaps/tracks/ai-engineer/retrieval-evaluation)
- [Advanced RAG Patterns](https://www.internhack.in/roadmaps/tracks/ai-engineer/advanced-rag)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
