Part 1 of 6 · 1 min read
Overview
In this module you will
- Explain what an embedding is and what cosine similarity measures.
- Run exact nearest-neighbour search and say when it stops being affordable.
- Describe how IVF (clusters) and HNSW-style graphs trade accuracy for speed, and tune their main knobs.
- Measure an approximate index with recall at k against exact search.
- Write the SQL shape of a pgvector table and query .
Keyword search matches words. A user who writes "automobile money-back" will not match a page that says "car refund". Embeddings turn text into points in space so that similar meaning means nearby points, and a vector index finds the nearest points quickly. Most agent memory and RAG systems rest on this. When retrieval misbehaves, you need to know whether the cause is the embedding model, the chunks, or the index; this module lets you separate the third from the others.
About the examples
embed.py is an imitation: it hashes words into 64 numbers, and a small hand-made table maps a few related words (car, vehicle, automobile) to the same coordinates. A real embedding model is a trained neural network with hundreds or thousands of dimensions and far richer behaviour. The index benchmark uses synthetic random clusters, not text. The numbers show how the algorithms behave, not how a real system performs. No real model, database or service was called.