AI Hints
Home›RAG Tutorial›What Is RAG
RAG · Lesson 3 of 120

How RAG Works

Retrieve, then generate.

⏱ 2 min read▶ Video at 2:14🎓 Free
Watch this lesson in the RAG courseWatch on YouTube ↗Full RAG course

A RAG system has two parts. First, we prepare our documents once, so they're easy to search. Then, every time a question arrives, we search, and generate an answer. Let's look at each part.

How RAG Works
From the video: How RAG Works
  • Prepare once
  • Search every time
  • Then generate

Part one: indexing

Indexing happens ahead of time. We load our documents. We split them into small chunks. We turn each chunk into a list of numbers, called an embedding, that captures its meaning. And we store those, in an index, ready to search.

  1. Load
  2. Split
  3. Embed
  4. Store
Part one: indexing
From the video: Part one: indexing

Part two: answering

When a question comes in, we embed the question the same way. We search the index for the chunks closest in meaning. We put those chunks into a prompt, with the question. And the model writes the answer.

  1. Question
  2. Embed
  3. Search
  4. Prompt
  5. Answer

Summary

RAG has an indexing part, load, split, embed, and store, and an answering part, search, prompt, and generate. Next, setting up.

Key takeaways
  • Index ahead of time
  • Search per question
  • Generate from the chunks
Next up: Setting Up — packages and a key