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 · with code: Python · about 22 min to read

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

RAG Over Your Own Notes

RAG
RAG · Open board

The RAG board draws a question going out to a library before it reaches the model. This lesson builds it over your own notes and measures whether it works.

Before you start. A language model, the AI that writes the answer, only knows what is in the text you hand it. So you cut your notes into chunks of a few paragraphs each. You find the chunks that match the question. You paste them in with “answer only from these”. That recipe is retrieval-augmented generation, RAG, from RAG (Retrieval-Augmented Generation). That lesson found matches by embeddings, lists of numbers where texts about the same thing sit close together. This one uses a simpler word-matching score instead. The first search engines matched words too, as Context Engineering (what goes in the window, and who decides) told. An eval set is a list of questions with the right answer written beside each. A second model call can grade each reply against a written rule, as Evals for Apps (the test suite for a program that is a string) showed.

Lesson 66 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

  • July 1945: the memex, a desk that holds everything you have read
  • Cutting at headings: chunks where you already cut
  • BM25: a score where a rare word counts for more
  • Citations: the trail back to the note
  • The golden set: fifteen questions you already know the answers to
  • hit@k: did the right note come back at all
  • Faithfulness: did the answer say only what the notes say
  • The fix: quote first, then answer
  • Query rewriting: asking for the words your notes use
  • Cutting the folder, then scoring one piece by hand
  • Handing the five pieces to the model
  • Grading the build, twice
  • The fix, and asking in the notes’ own words

Terms it explains: RAG, BM25, golden set, hit@k, faithfulness, query rewriting, idf, reciprocal rank fusion, chunk, chunking strategy, cosine similarity, embedding, grounding, hybrid search, nearest-neighbour / ANN, pgvector/Pinecone/Chroma, 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