RAG stands for Retrieval-Augmented Generation. In one sentence: before the robot answers, a helper finds the right page in your documents, and the robot answers from that page. Like an open-book exam instead of answering from memory.
Bot read millions of books and played "finish the sentence" billions of times. Now it is amazing at guessing the next word. That's all an LLM does: guess one word, then the next, then the next, until it has written a whole answer.
Move the slider: the bars are recalculated live with the real formula (softmax). The starting scores are made up for the example.
Bot doesn't read words, it reads tokens: small pieces of words. In English, one token is about ¾ of a word on average.
An example split. Each model has its own way of cutting text into tokens.
Bot's short-term memory.
The maximum number of tokens it can read at once (your question + any documents + its answer).
The day Bot stopped reading.
Anything after that date, or private to you, is unknown to it.
Bot guesses even when it doesn't know.
The next-word game always produces a word, so a wrong answer can sound very confident.
RAG fixes the last two: it hands Bot the right facts, right when it needs them.
Every word or sentence gets a home address on a giant map. Things that mean similar things live in the same neighbourhood: "cat" lives next to "kitten", far away from "truck". That address is called an embedding.
Click any word. The lines show its 3 closest neighbours, measured on this map. Real maps have hundreds of directions, not 2.
An embedding is really a list of numbers, one per direction on the map. Small models use 384 numbers per text; big ones use more than 3,000.
"cat" → [0.21, −0.53, 0.88, 0.04, −0.17, 0.66, … , −0.12] (made-up numbers)
king − man + woman ≈ queen
A famous result from word2vec (2013): the step from "man" to "woman" points the same way as "king" to "queen". The map learned the idea of "female" as a direction.
A vector database (Chroma, FAISS, Pinecone, pgvector…) is the map plus a very fast "who lives near this address?" button.
If you ask Bot about your shop, it has never seen your rules. So it guesses, like a student in a closed-book exam. With RAG, Owl brings the right page first. Now it's an open-book exam, and Bot can even say which page it used.
Change the document and the answer changes. No retraining.
PDFs, wiki, emails, tickets, databases: things Bot never saw.
Bot writes from real text instead of from memory.
Answers can cite the exact source, so people can check them.
Three reasons: it may not fit in the context window; you pay for every token on every question; and models tend to miss facts buried in the middle of very long text (researchers called this "lost in the middle"). Owl picks only the few pages that matter.
First, Owl organises the library once: cuts every book into small cards and gives each card a map address. Then, every time you ask something, Owl finds the closest cards and hands them to Bot, who writes the answer.
A whole book is too big to hand to Bot. So we cut it into flashcards. Too small and a card says "is the biggest planet" (which one?). Too big and finding one fact is like finding a sock in a messy room. We also repeat a few words from one card on the next, so no idea gets cut in half.
Drag the sliders: the text is cut again live. Yellow = words repeated from the card before (the overlap).
Real systems count in tokens, not words. A common starting point is a few hundred tokens per chunk with 10–20% overlap, then you test what works for your documents. There is no single best size.
Cut every 20 words.
Simple and fast, but may cut mid-sentence.
Cut at paragraphs first, then sentences.
The common default in toolkits like LangChain.
Cut where the topic changes.
Uses embeddings to notice when the meaning shifts.
Follow the chapters.
Uses headings, tables, slides or code blocks.
Imagine the question and each card are arrows pointing at an idea. If two arrows point almost the same way, they talk about the same thing. Owl measures the angle between arrows and picks the 3 cards that point most like your question.
Click a card to see its arrow. ✓ = the 3 cards Owl hands to Bot (top-k, k = 3).
Real calculation on tiny made-up vectors of 4 numbers: [refund, shipping, account, product]. Real models use hundreds or thousands of numbers, with the same maths.
cos(θ) = (A · B) / (|A| × |B|)
Worked example: A = [3, 4], B = [4, 3].
A · B = 3×4 + 4×3 = 24. |A| = |B| = 5.
cos = 24 / 25 = 0.96 → angle ≈ 16°, very similar.
With C = [4, −3]: A · C = 12 − 12 = 0 → 90°, unrelated.
Owl doesn't knock on every door.
Vector databases use shortcuts called approximate nearest-neighbour indexes (for example HNSW). They hop between neighbourhoods on the map, and are almost always right in milliseconds.
It's a relay race. Your question is the baton. It goes to the map-maker, then to Owl, who adds the best cards, then into a note with instructions, and finally to Bot, who runs to the finish line with the answer.
This is the real "augmented" prompt sent to the LLM for one question. The instructions in it are as important as the search.
Sometimes Owl brings the wrong cards. So we give Owl super-powers: fix the question before searching, use two kinds of search, and ask a careful judge to re-order the cards before they reach Bot.
An LLM rewrites a messy question into a clear one. Clear questions land closer to the right cards on the map.
Question: "Can I return a broken item?" The fast search was fooled by the word "broken". Press the button and watch the judge fix the order.
Ask the same thing 4 ways.
Search with each version, merge the results. Catches cards one wording would miss.
Imagine the answer, then search with it.
The LLM writes a fake ideal answer; its address on the map is often closer to the real card than the question's.
Two detectives.
Keyword search (BM25) catches exact words like "X2-500"; vector search catches meaning. Combine both.
Only look on the right shelf.
Search only cards where year = 2026 or team = HR.
Quick look, then careful judge.
Fetch ~20 cards fast, then a cross-encoder model reads each one with the question and keeps the best 3–5.
A family tree of facts.
Stores people, places and links as a knowledge graph, for "connect the dots" questions.
Owl thinks before searching.
An agent decides if it needs to search, where, and whether to search again.
Highlight, don't photocopy.
Keep only the useful sentences of each card, so Bot isn't distracted.
Bot is a chef. Prompting = giving clear instructions ("less salt, blue plate"). RAG = handing the chef the right recipe book while cooking. Fine-tuning = sending the chef to cooking school for months to learn a new style.
| Prompt engineering | RAG | Fine-tuning | |
|---|---|---|---|
| What it is | Better instructions and examples | Give the model documents at question time | Re-train the model on your examples |
| Adds new knowledge | ●●● | ●●● | ●●● |
| Stays up to date | ●●● | ●●● | ●●● |
| Changes style / format | ●●● | ●●● | ●●● |
| Can cite sources | ●●● | ●●● | ●●● |
| Cost & effort | Lowest | Medium | Highest (data + GPUs) |
| Use it when… | Always start here | Answers depend on your documents | You need a special tone, format or skill at scale |
Dots are a rough rating from common practice (●●● = strong), not a benchmark.
They combine: a good prompt + RAG covers most real projects.
We give the team a report card with two parts. Owl's grades: did it bring the right cards? Bot's grades: did it stick to the cards and actually answer the question? A bad answer can be Owl's fault or Bot's fault, so we grade both.
Example scores (0 to 1) to show how the metrics move. Metric names as used by evaluation tools like RAGAS.
A judge (often another LLM) splits Bot's answer into small claims and checks each one against the cards Owl brought. Score = supported claims ÷ all claims.
[1] Refunds are accepted within 14 days of delivery.
[2] Refunds go back to the original card in 5 business days.
[3] Shipping costs are not refunded.
"You have 14 days to ask for a refund, the money comes back in 5 business days, shipping is refunded too, and you need your receipt."
✓ Clean documents first (remove headers, junk)
✓ Add metadata: title, date, source
✓ Test 2–3 chunk sizes
✓ Make Bot cite sources and say "I don't know"
✓ Keep a test set of 20–50 real questions
✗ Dumping messy PDFs unchanged
✗ Sending too many cards (Bot gets lost)
✗ Judging quality by feeling
✗ Blaming the LLM before checking retrieval
Garbage in, garbage out. Most RAG problems are data and retrieval problems, not LLM problems.