Black Friday50% off your first month on any monthly plan with EARLY50 See plans
All 29 lessons
  1. Foundations: what RAG is and a working pipeline

    1. 1. Getting started: what RAG is and when to use it
    2. 2. Types of RAG: a map from naive to agentic
    3. 3. Lab: build the smallest RAG pipeline end to end
    4. 4. How embeddings and vector search find meaning
    5. 5. Document types: what each one breaks, and how to prepare it
  2. Better retrieval: chunking and search

    1. 6. Chunking documents so answers survive
    2. 7. Chunking strategies compared: which to use when
    3. 8. Keyword search vs vector search, and fusing both
    4. 9. Retrieval algorithms compared: which to use when
    5. 10. Reranking the top results before the model reads them
    6. 11. Rewriting the question before you search
  3. Answers you can trust, measure and debug

    1. 12. Lab: grounded answers with citations and refusals
    2. 13. Measuring a RAG system with an evaluation set
    3. 14. Lab: evaluation methods and frameworks: Ragas and DeepEval
    4. 15. Troubleshooting a RAG system, symptom by symptom
  4. Production in a company

    1. 16. Access control: only retrieve what the user may see
    2. 17. Defending against prompt injection in retrieved text
    3. 18. Running RAG in production: freshness, cost and monitoring
    4. 19. Real-world RAG: what worked, what failed, and why
  5. Agentic RAG

    1. 20. Lab: from a fixed pipeline to an agent with a search tool
    2. 21. Self-correcting retrieval: grade, retry, fall back
    3. 22. GraphRAG and routing across many sources
    4. 23. Lab: numbers, tables and financial documents
  6. Frameworks: LangChain, LangGraph and LangSmith

    1. 24. The RAG toolbox: what each library does and why you import it
    2. 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
    3. 26. Lab: Ask Brightline in LangChain
    4. 27. Lab: agentic RAG as a LangGraph graph
    5. 28. Lab: tracing, evaluating and monitoring with LangSmith
    6. 29. Wrap-up: your production agentic RAG checklist
See the leaderboard

15 min

How embeddings and vector search find meaning

Rebuild vector search from its parts and explain why similar meaning lands near in vector space.

By the end of this lesson you can

  • Compute cosine similarity on small vectors by hand
  • Explain what an approximate nearest neighbour index trades for speed
  • Say what a vector database adds over a NumPy array

From earlier lessons · 1 of 2

In the lab, why did k=1 miss the alcohol rule?

Pick one answer.

From earlier lessons · 2 of 2

What should you print before reading an answer?

Pick one answer.

An employee types "PTO rollover". The policy never uses the word PTO; it says "paid time off" and "carry over". Vector search still ranks it first. Keyword search would return nothing.

The one line that does it all

In lab 1, one call did all the searching: retrieve("PTO rollover"). It returned hr-pto first. Let's take that call apart and look at each piece's output.

Part 1: an embedding is a position

An embedding model turns text into a fixed-length list of numbers, a vector. It was trained so that texts with similar meaning get vectors that point in similar directions. The space those vectors live in is called vector space.

Our model, all-MiniLM-L6-v2, outputs 384 numbers. Nobody can read them, but you can measure the angle between two of them.

python
from rag import embed
v = embed(["paid time off carries over"])[0]
print(len(v), v[:4].round(3))
Expected output: 384 and four small numbers such as [-0.051 0.033 0.032 0.01 ]. The values mean nothing alone; only comparisons do.

Part 2: cosine similarity, by hand

Cosine similarity measures the angle between two vectors: 1 means the same direction, 0 means unrelated. Here it is on 3-number toy vectors so you can follow every step.

  • "paid time off" is [0.9, 0.1, 0.2].
  • "PTO" is [0.85, 0.15, 0.25].
  • "laptop" is [0.1, 0.9, 0.3].

The dot product of the first two is 0.9×0.85 + 0.1×0.15 + 0.2×0.25 = 0.83. Their lengths are 0.93 and 0.90, so the cosine is 0.83 ÷ (0.93 × 0.90) ≈ 0.99. For "paid time off" against "laptop", the dot product is 0.24 and the cosine is about 0.27. Same idea, far apart in meaning.

Nearest neighbour search finds the vectors closest to the question's vector. The simplest way scores every one, as the trace shows.

Step through

Brute-force search for the best match

  1. hotel0i
  2. meals1
  3. vpn2
  4. pto3
  5. remote4
  6. device5

Question: a hotel in Chicago. Score every snippet. Start at hotel: 0.66, the best so far.

Step 1 of 4

Brute force is exact, and fine for tens of thousands of chunks. At 10 million chunks of 384 numbers, each question costs about 4 billion multiplications.

An approximate nearest neighbour (ANN) index avoids reading everything. The most common one, HNSW, links each vector to a few close neighbours in layers. A query starts at the top layer and hops greedily toward closer vectors, usually reaching the answer in milliseconds. The trade-off is recall: it can occasionally miss a true nearest neighbour. Most indexes let you raise a search-effort setting to miss less, at some cost in speed.

Part 4: what a vector database adds

A vector database is an ANN index plus the things a company needs around it:

  • Persistence and updates. Add, change and delete chunks without rebuilding everything.
  • Metadata and filters. Store the source, date and allowed groups on each chunk, and filter by them during search. Lesson 16 depends on this.
  • Scale and operations. Replication, backups and access control.

Many teams start with a vector index inside a database they already run, such as Postgres with a vector extension, or with a managed search service.

Match

Match each part to what it does

Pick an item on the left, then its match on the right.

Predict, then reveal

What was the one-line retrieve() hiding? Name one rule you'd break by accident without knowing these parts.

Worth keeping

  1. An embedding places text by meaning; only comparisons between vectors mean anything.
  2. Cosine similarity is the angle between vectors; on normalised vectors it's a dot product.
  3. Brute force is exact; ANN indexes like HNSW trade a little recall for a lot of speed.
  4. Same model for queries and documents, and re-embed everything when you change it.

Embeddings work on clean text. Real company documents arrive as two-column PDFs, scanned contracts, spreadsheets and slide decks. Next lesson shows what each one breaks, before a single chunk is cut.

Leaderboard

Loading…

50 XP for each lesson you finish, 10 for each right answer. Names show only for learners who turn on Show me on leaderboards.