Books Deep-Read · ML System Design Interview · Ch 2

Visual Search: Turning “Does It Look Alike” Into “Is It Close By”

Machine Learning System Design Interview · Ch 2 · Ali Aminian & Alex Xu · 2023

中文 →

What is this chapter about?

You spot a pair of shoes on the street. You can't name the brand and you can't describe the style, so you snap a photo, drop it into a shopping app, and it hands you a dozen pairs that look almost identical. That's search by image. This chapter walks through building that whole system from nothing — not one model, the entire thing.

A strange thing first

You probably assume the machine understood the picture: ah, a white sneaker. It does no such thing. What it does is squash every picture into a string of numbers — think of it as giving each picture a set of map coordinates. And then the fuzzy question “find me similar pictures” becomes a grade-school geometry question: who is standing nearest?

Why the old world struggled

Search used to run entirely on words. But the picture in your hand has no words attached. “Pale grey, three diagonal stripes near the toe, wavy sole” — could you even type that? And if you did, would the search box know what to do with it? Visual likeness doesn't translate into words. Then there's the volume: a serious image library holds hundreds of millions, even billions of pictures. Even if comparing one takes the blink of an eye, going through them one at a time takes you into next year.

How it actually pulls this off

Three moves, each more important than the last.

What this costs

Speed is bought by giving up the guarantee of finding the single closest picture — it only digs through a few districts, and every so often the truly closest one is sitting in a district nobody opened.

Remember this one line

The secret of search-by-image isn't teaching a machine to understand pictures. It's turning every picture into a point on a map so that “alike” becomes “nearby” — and everything after that is the engineering of finding the nearest few points among billions, fast and cheap.

Want the mechanisms, the notation and the diagrams? → Switch to the deep read