Skip to content
Lesson Ten

Vectors
and RAG

How a machine finds text by meaning instead of keywords, and why that is the trick behind AI that answers from your documents.

Scroll, click, or use the arrow keys to move through.Scroll, or use the arrows and dots to move through.

Meaning as numbers

A vector turns meaning into a position.

An embedding model reads a piece of text and produces a long list of numbers, called a vector. The numbers represent the meaning of the text in multi-dimensional space: text with similar meaning lands at nearby points, and unrelated text lands far away. The tool can then use that distance to find the most related text.

No shared words required

Similar meanings land near each other.

The phrases share no words, and the vectors do not care. Meaning is what got measured, so a search for one finds the other. That is the whole trick, and everything else in this lesson is built on it.

Three phrases, embedded
“the invoice is overdue”
near ↓
“the bill has not been paid”
far ↓
“team lunch on Friday”
Vector databases

A vector database finds the nearest neighbors.

Store every chunk of text together with its vector, and the database gains one special skill: given a new vector, it returns the stored chunks closest to it, in milliseconds, even across millions of entries. Ask it anything, and what comes back is the text most related in meaning to what you asked.

Stores: text plus vectors · Answers: what is closest in meaning
Retrieval augmented generation

RAG is a pattern, not a product.

Retrieval augmented generation is two moves in order: fetch the text that bears on the question, then hand it to the model along with the question. Ahead of time you chunk your documents and put them somewhere searchable. At question time you search, take what comes back, and pass it along. The model answers from what it was handed.

The name describes the shape and nothing else. Notice what is missing from it: any statement about how the fetching happens.

Fetch, then answer. That is the entire pattern.

Retrieval is the flow, not the tool

Vectors are one tool in the belt.

RAG describes a flow: fetch, then answer. It says nothing about what does the fetching. Vector search is one option, and a strong one for prose, but a retrieval step can reach for whatever suits the question. Some of what it might reach for:

Some ways to fetch
Keyword search
Exact terms: names, IDs, error codes, quoted phrases.
SQL query
Structured facts held in tables: orders, balances, dates.
Vector search
Meaning in prose: policies, contracts, notes.
API call
Live state from the system that owns it.
Read the file
When the document is small enough, hand over the whole thing.
Web search
The open internet, when the answer is not yours to hold.

There are others, and most working systems use several at once, combining what comes back. The method follows the shape of the data.

Keywords or meaning

Two kinds of search.

Keyword search

Finds the exact words you typed. Fast and precise, and it misses everything phrased differently: search for overdue invoices and the note that says the bill has not been paid stays hidden.

Vector search

Finds the meaning you asked for, whatever the words. It catches the rephrase, the synonym, and the description that circles the point without naming it.

What retrieval does not do

Nearest is not the same as right.

Retrieval measures similarity, not truth. It returns the closest text it holds, so if the answer is not in the store, it returns the nearest miss instead, with full confidence. The quality of the answers is set by what got stored, how it was chunked, and whether it is kept up to date. A retrieval system is a library, and a library is only as good as its collection.

The lesson in one line

Meaning becomes position, and position becomes retrieval.

Embed the text, store it with its vectors, fetch the nearest chunks, and answer from what was fetched. Four steps, and an AI that speaks from your documents instead of guessing.