Python, from Zero, for AILesson 84 of 89

Module 9 · Building the thing: a small AI program, end to end

Search over your own notes: chunks, embeddings, cosine, and sixty lines

In this lesson

  • 10 min read
  • 8 reading sections
  • Knowledge check
  • Lesson 5 of 10 in this chapter

This chapter’s goalAssemble a complete tool from the course’s parts (a chat loop with bounded history, injection-resistant prompt templates, a sqlite response cache, a document chunker, a local embedding search over your own notes, a free local model as the fallback provider) expose it through a Gradio interface and a FastAPI endpoint, run it on a schedule without double-processing, and gate every change behind a GitHub Actions job that runs the tests.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:39Not available
Full audiobookNot availableNot available
Index once, then query as often as you likeChunk the notesParagraphsfirst, measuredin tokens, withoverlapEmbed eachchunk onceA free localmodel on the CPUNormalise rows,save two filesnp.save thematrix, JSON thetext and itssourceEmbed thequestionWith the samemodel, or thescores meannothingM @ q, take thetop fiveOnematrix-vectorproduct, thenhand thepassages overEverything to the left of the question happens once and takes a minute or two for five thousand chunkson a laptop CPU. Everything to the right happens per query and takes milliseconds. The one rule thatmust not be broken is the same model on both sides: two models put their vectors in unrelated spaces,and the scores still look plausible.
Everything to the left of the question happens once and takes a minute or two for five thousand chunks on a laptop CPU. Everything to the right happens per query and takes milliseconds. The one rule that must not be broken is the same model on both sides: two models put their vectors in unrelated spaces, and the scores still look plausible.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 10Free · no account needed
Lesson steps

What you are building

A box you type a question into that finds the passages in your own notes most likely to answer it, and optionally hands those passages to a model to write the answer. It is the pattern under most “chat with your documents” products, and every piece of it is something this course has already built: file walking from module 5, chunking from the previous lesson, a vector matrix and cosine similarity from module 8, a provider from module 7, a cache from two lessons ago.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘Search over your own notes: chunks, embeddings, cosine, and sixty lines’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/search-over-your-own-notes (Accessed: 21 November 2026).