- 1. Searching by Meaning
- The operation
- Where the vectors come from
- The geometry that makes this hard
- What this book measures against
- 2. Choosing a Similarity Metric
- The three candidates
- How far apart they actually are
- The property responsible
- The condition under which the question disappears
- Practical guidance
- 3. Exhaustive Search and What It Costs
- The measurement
- Where it actually breaks
- What the index costs to build
- The measurement problem this book has to solve
- 4. How Many Dimensions
- Designing a fair test
- The measurement
- What dimension costs on the other side
- Practical guidance
- 5. Searching a Graph Instead of a List
- The idea
- What the parameters do
- The measurement
- What it costs to build and to hold
- An honest note on speed
- 6. Making the Vectors Smaller
- Two independent ideas
- The inverted file
- Product quantisation
- Combining them, and why that is not enough
- The step that makes it all work
- What this buys at scale
- 7. Searching With a Filter
- The two strategies
- The measurement
- The crossover, which is not where intuition puts it
- What real systems do about the middle
- 8. Vector Databases in Practice
- What the settings correspond to
- A decision procedure
- Operational concerns the benchmarks hide
- Hybrid search, briefly
- 9. Limits, and Where Each Exam Goes
- The limits, and what causes each
- What vector search does reliably
- What this book did not establish
- The reverse map: your certification to these chapters
- Closing
Embeddings and Vector Search
Every index built from scratch. Every recall figure checked against exact ground truth.
Vector databases give you a similarity metric, an index with four tuning parameters, a
compression option and a way to filter — and almost no guidance on what any of it costs.
This book builds each one from scratch and measures it. The proximity graph, the inverted
file, the product quantiser: implemented in NumPy, included with the text, and checked
against exhaustive search — so every recall figure here is exact rather than estimated.
Minimum price
$16.00
$16.00
You pay
Author earns
About
About the Book
Vector search is the part of this field where the documentation is thickest and the
understanding is thinnest. Every vector database offers a choice of similarity metric, an
index type with three or four tuning parameters, a compression option, and a way to filter by
metadata — and almost none of them tell you what any of it costs, or when a setting that
works quietly stops working.
So the defaults get copied. Cosine similarity because everyone uses it, HNSW because it is
the default, whatever dimension the embedding model happens to produce, and a filter applied
after the search because that is the obvious place to put it. Each of those is right in some
regime and wrong in another, and this book is about knowing which regime you are in.
Books about search benchmark other people's implementations. This one builds them — and that
has a consequence that matters more than any other: **every recall figure in this book is
measured against exhaustive brute-force search over the same vectors.** Not sampled, not
approximated, not taken from a published benchmark. When this book says an index reached
0.9745 recall, that means it returned 9.745 of the true 10 nearest neighbours on average,
where "true" was established by comparing the query against every single vector.
That is possible because vector search is deterministic. There is no training, no random seed
that changes a conclusion, and no behaviour that only appears at scale. This volume needed
cited results less often than any other in the series — three boxes in the whole book.
What gets measured:
- **Why high-dimensional space is strange.** In two dimensions the farthest point in a
collection is 263 times farther away than the nearest. In 1,024 dimensions it is 1.15 times
farther. Every design decision in the rest of the book is a response to that.
- **Why cosine is the default.** Vector norms in a real embedding space span a factor of 15,
and the largest belong to function words — so searching by dot product for *love* returns
*our, my, for, so, thy*, with zero overlap against cosine's results on four of five queries.
After normalisation, cosine, dot product and Euclidean distance rank identically on 300 of
300 queries.
- **What exhaustive search actually costs.** 268 queries per second against 128,000 vectors on
a single core, exactly correct, with nothing to build or tune. It becomes untenable not
because it is slow but because it is unamortisable — which reframes when an index is worth
building at all.
- **What a proximity graph buys.** Recall 0.9745 while examining 590 vectors out of 8,000 —
13.5 times fewer comparisons. And recall 1.0000 while saving only 1.9x, which is the
measurement behind an uncomfortable conclusion: an index tuned for near-perfect recall has
surrendered most of its purpose.
- **What compression costs, and how it is recovered.** Compressing vectors 32-fold dropped
recall to 0.2795. Re-scoring 500 candidates exactly — 2.5% of the collection — brought it
back to 0.9380, with the index unchanged at 8 bytes per vector.
- **When filtering breaks.** Searching first and filtering afterwards held recall 0.9675 at
50% selectivity and collapsed to 0.2000 at 1% — returning fewer results than requested for
**every single query**, silently, with no error raised. At that selectivity, scanning the
matching subset exhaustively is both exact and twenty times cheaper.
What you get:
- 9 chapters covering embeddings, similarity metrics, exhaustive search and its true cost,
dimension, graph indexes, quantisation and re-ranking, filtered search, vector databases in
practice, and a final chapter of limits.
- 48 original practice questions, tagged by certification and by difficulty, where every
option is explained — not just why the right answer is right, but why each wrong answer is
wrong, because on these exams the distractors are where the teaching is.
- A reverse map from each certification to the chapters that serve it, in reading order.
- All the code — every index, every experiment — so each table and figure can be regenerated.
Written to the published objectives of Databricks Certified Generative AI Engineer, NVIDIA
NCA-GENL, NVIDIA NCP-GENL, NVIDIA NCP Agentic AI, and AWS Certified Generative AI Developer –
Professional. Objectives were checked in August 2026; confirm the current blueprint with the
certifying body before you sit.
You need to be able to read Python, and to remember that a dot product multiplies two lists of
numbers pairwise and adds them up. That is the whole prerequisite — and nothing in this volume
assumes you have read any other book.
Every question is original, written from published exam objectives. Nothing is reproduced
from, or based on recollection of, any live examination.
This book was created through a process that combines careful human planning, content direction, and advanced AI technology, followed by thorough refinement and review to ensure a high-quality final work.
Feedback
Author
About the Author
Hatem M. is a programmer and technical author whose work focuses on modern C++, large language models, and AI systems.
His books combine first-principles explanations with complete implementations and reproducible experiments. They include C++ Algorithmic Mastery, an eight-volume series on algorithms and problem solving; Build an LLM Inference Engine in C++, which constructs a GPT-style inference engine from scratch; LLM Quantization: From the Bits Up, which develops the theory and practice of neural network quantization from the bit level upward; and C++ Autopsy, a forensic investigation of ten subtle C++ bugs that compiled successfully, ran correctly, and still produced the wrong answers.
Contents
Table of Contents
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.