The Maths You Actually NeedLesson 65 of 76

Module 7 · Counting the cost: complexity and the arithmetic of scale

Finding the closest vector among ten million: the arithmetic of approximate search

In this lesson

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

This chapter’s goalCount the FLOPs of a forward pass and a training run from a parameter count, compute the memory a model needs at each precision and in training, say from arithmetic intensity whether a workload is bound by compute or by memory bandwidth, recognise a quadratic cost in a pipeline and name the sub-quadratic replacement, and estimate the time or cost of an ML job to within a factor of three before running it.

This chapter’s media

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

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

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

Step 1 of 8Free · no account needed
Lesson steps

The version: compare with everything

Given a query embedding and a store of n embeddings of dimension d, the exact way to find the nearest is to compute all n similarities. That is n × d multiply-adds per query, and the store occupies n × d × 4 bytes in float32.

Text
n = 100,000, d = 768:   1.5 × 10^8 FLOPs per query, 300 MB
n = 10,000,000:         1.5 × 10^10 FLOPs per query, 30 GB

At a hundred thousand, one query is about a millisecond on a laptop and the store fits in RAM. Brute force is the right answer, and building an index for it is wasted effort that also costs recall. The course machine-learning-foundations builds a working search at this scale with NumPy; nothing more is needed until the numbers change.

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

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘Finding the closest vector among ten million: the arithmetic of approximate search’, in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/nearest-neighbour-search-arithmetic (Accessed: 27 November 2026).