← All lessons
0150

RAG

A model only knows what it saw in training, so it cannot answer about your private or recent documents and may confidently guess. Retrieval-augmented generation fixes this by fetching real text first.

Your documents are split into chunks and turned into embeddings stored in a vector database. At query time the question is embedded too, and nearest-neighbour search pulls the most similar chunks. Those chunks are pasted into the prompt, so the model answers from retrieved evidence instead of memory. Turn retrieval off and it falls back to a vague guess.

query: What is the refund window?

Refunds allowed within 30 days of purchase.
Office hours are 9am to 6pm IST.
Shipping takes 3 to 5 business days.

You can request a refund within 30 days of purchase.

off = guessing from memory

Check yourself

The model never saw your refund policy in training. With retrieval on, how does it state the exact 30-day window?

Go deeper (free): Hugging Face — RAG explained

Next: Embedding Search