← writing
7 December 2020

Searching by resemblance

In 2020, comparing documents by their vectors meant assembling the chain yourself. The state of the art then, and what vector databases actually changed since.

Keyword search finds what you can name. Search by resemblance finds what you can only recognise, and the operation is different: the word is replaced by a vector, and the question “which one contains this term” by “which one is nearest”. Everything that followed sits inside that substitution, including what is now called a vector database.

01The state of the art in 2020

The chain came in three pieces, and all three were needed. First the vectors: you took a network trained for classification, removed its last layer and kept what was left, a few hundred numbers per document. Then an approximate index (Annoy, published by Spotify, or FAISS, published by Facebook) because a million vectors compared one by one is out of reach for an interactive query. Finally storage, and that was the improvised piece: usually a conventional database sitting beside the index, with the burden of keeping the two consistent.

02The trade accepted

The word approximate is not a hedge, it is the heart of the matter. These indexes accept missing the nearest neighbour sometimes in exchange for an answer a hundred times faster. You set a dial between exactness and speed, you measure what is lost on a sample whose answer you know, and you decide. That trade has not changed; it is the only thing from 2020 I would rewrite word for word.

03What vector databases changed

Not the mathematics: the same families of index, and often the same libraries underneath. What they changed is operation. Index and data live in one system, a write becomes visible in both, you filter by metadata at the same time as you search by distance, and the backup covers the whole. It is engineering progress rather than scientific progress, which is to say exactly the piece that was missing.

04The real shift is elsewhere

What made the subject central is not the database, it is the vector. The embeddings of 2020 were specialised: one model for images, one per language for text, and bringing two languages together needed a model built for it. Since then a single space holds text in several languages and sometimes other media, and their quality is such that search by resemblance now feeds a language model rather than answering by itself. The piece that improved most is therefore the one least discussed.

05What I leave out

I am not comparing the products of the moment: they move too fast for a dated piece to serve them. And I would not advise a vector database to anyone holding fewer than a few tens of thousands of vectors: an exhaustive comparison held in memory answers faster than a service to administer, and takes an afternoon to write. The threshold matters more than the choice, and it is the question asked least often.