Module 0 · Lesson 9 of 10

Vector databases: search by meaning

Search by meaning, fast

A vector database skips most of the work: one common kind of index sorts meanings into groups, then checks only nearby groups.

Scene 1 of 5 · Meanings stored

The database holds 2,000,000 help articles, each stored as an embedding of its meaning.

Help appHelp appVector databaseVector database2,000,000 articles
  • Help app — healthy
  • Vector database — healthy — 2,000,000 articles
Items checked for one question
  • Check every article?
  • Check nearby groups?
True closest article found?
not shown yet
  1. Meanings stored. The database holds 2,000,000 help articles, each stored as an embedding of its meaning.
  2. Check every one. Comparing the question with every article finds the true closest one, but takes 2,000,000 checks.
  3. Sort into groups. Ahead of time, one common kind of index sorts the articles into 1,000 groups of similar meaning.
  4. Check nearby groups. It finds the 2 nearest groups, then checks their articles: 5,000 checks in all, 400 times fewer.
  5. Now and then, a miss. Checking only the single nearest group is faster still, but here the closest article sat in the next one.
  6. Now you try. Choose how much to check, and see the work and whether the closest article is found. For example: 17,000 checks; the true closest article was found. That is 118 times less work than checking everything, and it still finds the closest one here.

Scene 1 of 5: Meanings stored. The database holds 2,000,000 help articles, each stored as an embedding of its meaning.

Key points

  1. Each stored item is an embedding: a list of numbers for its meaning.
  2. Checking every item is exact, but slow with millions of them.
  3. An index checks only a few nearby groups, far faster.
  4. Now and then the closest item sits in a group it skipped.

A stores , the lists of numbers that stand for meaning, and finds the ones closest to a given embedding. A list like this is also called a . This lets an app search by meaning instead of by exact words.

Comparing a question's embedding against every stored item works, but it turns slow once there are millions of them. Checking each one, one at a time, does not scale.

Most vector databases use instead: it checks only part of the data, so it runs much faster. Now and then, it misses a match that was truly closest.

Example. Finding the 3 help articles closest in meaning to a question, among 2 million stored articles, would take too long to check one by one. So the database searches approximately instead.

In system design: A vector database sits beside your normal database. Your backend embeds the question, asks the vector database for the closest matches, then fetches the full text for each one.

Check yourself

Why do most vector databases search approximately?