Leanpub Header

Skip to main content

Vector Search Inside Out

Vector Search Inside Out
This book is 100% completeLast updated on 2026-10-13

HNSW powers almost every vector database, and few of the engineers who rely on it have seen inside it. Vector Search Inside Out builds it from first principles in 92 step-by-step figures, then tunes it on 1.18 million real vectors. You'll know exactly what M, efConstruction and ef do, and how to set them for your own data.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
About

About

About the Book

Every "find similar" feature, from semantic search to the retrieval step in a chatbot, ends in the same question: which of my millions of stored vectors are closest to this one? HNSW is the algorithm almost every vector database uses to answer it in a fraction of a millisecond. Most of the engineers who depend on it have never seen inside it.

This book opens it up. You follow Asha, a forward deployed engineer, as she builds "find similar" products and chatbot retrieval for a retailer with 1.2 million product embeddings. Each idea arrives at the moment she needs it, explained in plain English and shown in 92 step-by-step figures drawn from animated explorables.

Part One builds HNSW from nothing:

- what "nearest" means, what recall measures, and when exact search is simply the better tool

- how a search walks a graph, why a greedy walk gets stuck, and how a beam of width ef rescues it

- why the index has layers, how a query descends them, and how each point chooses its links

- how the index builds itself, one search per point

Part Two turns every knob on real data, 60,000 Fashion-MNIST images and 1.18 million GloVe word vectors:

- M, efConstruction and ef: what each controls, and what each costs in recall, latency and memory

- why fixed settings lose recall as the collection grows, and a five-step tuning recipe for your own data

- memory, quantisation and re-ranking: a PQ index 13× smaller, with recall pulled back from 0.82 to 0.997

- filters, deletes and updates, which distance to use, what nine databases call each knob, and when HNSW is the wrong tool

You need basic Python and a rough idea of what an embedding is. No maths beyond distances, no prior knowledge of graphs. Every number was measured with hnswlib and faiss, and every chapter builds on the one before.

Author

About the Author

Ritesh Modi

Ritesh Modi is Head of AI at MarketOnce and a former Forward Deployed Engineer at Microsoft. He has spent more than a decade building and shipping production systems across cloud, distributed computing, and applied machine learning, working with organizations ranging from global enterprises to fast-moving startups. His recent work focuses on applied large language models, designing systems that turn pretrained models into reliable, task-specific tools.

Ritesh has authored multiple technology books and speaks regularly at industry conferences on AI, cloud architecture, and software engineering. His writing philosophy rests on a simple belief: the best technical books are written by practitioners who still remember what it felt like to not understand something, not by experts who have forgotten. Every explanation in this book was tested against that standard, if it would not have made sense to him when he was first learning this material, it was rewritten until it did.

He writes, shares ideas, and connects with readers at www.riteshmodi.com. When he is not writing or building AI systems, he can be found mentoring engineers, exploring new architectures, or debugging a training run that should have converged three hours ago.

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.)

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.

Learn more about writing on Leanpub