Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 07 · AI · On a real model · about 14 min to read

Watch: Vector databases and RAG, end to end
▶ VideoPlay it as a journeyTutor comes with a plan

Retrieval that finds the right page: advanced RAG

RAG
RAG · Open board

The RAG board draws a question going out to a library before it reaches the model. This lesson works on the part inside that library: how the right page is found.

On 19 September 2024 Anthropic published a short article on a problem every RAG builder meets. Their example chunk, a piece of a company report, reads: “The company’s revenue grew by 3% over the previous quarter.” Read it alone. Which company? Which quarter? The chunk does not say, and the search engine cannot guess. Ask “What was Acme Foods’ revenue growth in Q2 2023?” and this chunk looks the same as the same sentence from any other company’s report.

The page was in the library. The search never brought it back. A better model cannot fix that, because the model only reads what search hands it.

By the end you will be able to find the weak step in a RAG search, fix it with one of five tools, and prove the fix worked with numbers.

Before you start. RAG (Retrieval-Augmented Generation) cut documents into chunks, turned each into a list of numbers, and pasted the nearest chunks into the prompt. RAG Over Your Own Notes built that over real notes, scored words with BM25 (a rare word counts for more), merged two ranked lists by reciprocal rank fusion, and graded retrieval with a golden set (questions whose right note you know). Context Engineering (what goes in the window, and who decides) showed a reranker, a slower model that reads the question and a chunk together, picking the best from twenty finalists. This lesson takes each of those further and adds three new tools.

The history (optional)

Anthropic’s article on this fix is dated 19 September 2024. The late interaction idea comes from Omar Khattab and Matei Zaharia, whose paper “ColBERT” was accepted at SIGIR 2020 (arXiv 2004.12832). The GraphRAG paper, “From Local to Global: A Graph RAG Approach to Query-Focused Summarization” by Darren Edge and colleagues at Microsoft, first appeared on arXiv on 24 April 2024 (2404.16130). Nothing later in this lesson depends on these dates.

Think of a thick file in a government office. Every page has a number, but nobody can read the whole file for each visitor. The office needs a way to pull out the one right page. That is all retrieval is, and each tool below is a better way to pull it.

Lesson 67 of 83 in AI

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • Contextual chunk: tell each page whose file it belongs to
  • Hybrid search and the reranker: cast wide, then read closely
  • Late interaction (MaxSim): keep one vector per word, compare late
  • GraphRAG: a map of who is linked to whom, for questions about the whole library
  • Recall@k and MRR: prove which retriever is better
  • Chunking strategies
  • Late interaction in detail
  • GraphRAG trade-offs
  • Metrics
  • The code

Terms it explains: contextual chunk, reranker, Late interaction, MaxSim, GraphRAG, communities, Recall@k, MRR, Common mistakes, Fixed size, Structure aware, Parent and child, Contextual, chunk, chunking strategy, cosine similarity, embedding, grounding, hybrid search, nearest-neighbour / ANN, pgvector/Pinecone/Chroma, query rewriting, RAG, re-ranking, retrieval hit-rate & faithfulness, top-k, vector database.

Lab

The returns desk cuts its policy into pieces and hands the model the best few. How big should a piece be, and how many should go in?

Drag How many words in each piece from 5 to 200 and watch Answers that arrived whole climb while the tokens grow.

Open The chunk size

Related papers

Review AI