RAG: retrieval as a callback to similarity
Embed the query, find the nearest chunks by dot product, paste into context.
When and where is the team offsite?
You've reached the end of the free preview. The next lesson needs your pass:
But answering is passive: what about acting?
5.3 Tools & agents: the loop around a frozen modelCommon questions
What is "RAG: retrieval as a callback to similarity" about?
What question does this lesson answer?
What will I be able to do after this lesson?
What comes next?
What this lesson shows
Embed the query, find the nearest chunks by dot product, paste into context.
The question it opens with
How does it answer about things it never trained on?
The walkthrough, in the lesson's own words
- Good instinct. Tap any other snippet to compare, then watch it run.
- A frozen model, four private docs it never read. Tap the snippet that answers you.
- One annotated run: question in, grounded answer out.
- To make it answer about your private docs, you have to retrain or fine-tune the model on them.
- The weights never change. Retrieval just finds the right snippet by similarity and pastes it into the context window, so the same frozen model reads the answer instead of guessing it.
- The model faithfully reads whatever wins retrieval. A plausible but outdated snippet wins, and the answer is confidently wrong: retrieval quality decides answer quality. Lesson E.15, next, is about engineering retrieval so this doesn't happen.
- The model's weights never change. Retrieval just hands the right snippet to the context window, the same frozen model from 5.1 now reads the answer instead of guessing it.
- This one-shot embed-and-paste is the classic RAG pipeline, and it still powers plenty of doc search. But modern assistants often search agentically instead: the model writes keyword and multi-query searches, reads the results, and searches again until it has enough (lesson 6.9). The principle is the same: find the right text and put it in the window.
- A support bot can't answer questions about your product, but all the answers live in your help-center articles. What's the simplest fix?
- Embed each article and the user's question, then retrieve the closest one by similarity and drop it into the context window, that's RAG. No retraining: you just hand the frozen model the right text to read, so add new docs and it answers the next day.
- The gathering snippet is the one that answers you, it never says the word offsite. Next, watch HOW the system finds it without reading every line.
- You spotted it by meaning, not keywords. Meaning lives as direction in the coordinate space, so the same dot product from 1.3 scores every snippet against your question.
- Tap another snippet to see why it loses, or continue to watch the run.
- Toy demo: whole docs and a single winner. Real systems split docs into chunks first, retrieve the top few instead of one, and often rerank them; E.15 shows why the cut matters.
Key takeaway
RAG = the similarity trick + paste into context.
What you can do after this lesson
You can explain RAG: similarity-search your docs, paste the best into context.
Check yourself: What is RAG, in essence?
- Find relevant docs by similarity, paste them into context(correct)
- Re-train the model on your docs
- A bigger context window
- A faster decoder
RAG retrieves relevant chunks by similarity and pastes them into the prompt. The model stays frozen; you are feeding it fresh context, not retraining.
Prefer reading first? This lesson has a companion explainer: RAGVector databasesRAG vs fine-tuning
Where it leads: But answering is passive: what about acting?
This is the written summary. The lesson itself is interactive: you predict, drag and operate the mechanism above, and the reveal answers you.