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 app — healthy
- Vector database — healthy — 2,000,000 articles
- True closest article found?
- not shown yet
- Meanings stored. The database holds 2,000,000 help articles, each stored as an embedding of its meaning.
- Check every one. Comparing the question with every article finds the true closest one, but takes 2,000,000 checks.
- Sort into groups. Ahead of time, one common kind of index sorts the articles into 1,000 groups of similar meaning.
- Check nearby groups. It finds the 2 nearest groups, then checks their articles: 5,000 checks in all, 400 times fewer.
- Now and then, a miss. Checking only the single nearest group is faster still, but here the closest article sat in the next one.
- 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
- Each stored item is an embedding: a list of numbers for its meaning.
- Checking every item is exact, but slow with millions of them.
- An index checks only a few nearby groups, far faster.
- Now and then the closest item sits in a group it skipped.
A (A database that stores vectors and finds the ones closest to a given vector, so you can search by meaning.) stores (A list of numbers that stands for the meaning of a piece of text. Texts with similar meanings get similar lists.), 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 (A list of numbers. An embedding is a vector.). 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 (Finding the stored vectors closest to a question's vector. The approximate kind checks only part of the data. It is much faster, but now and then it misses a close match.) instead: it checks only part of the data, so it runs much faster. Now and then, it misses a match that was truly closest.
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.