How embeddings and vector search work
Embeddings turn meaning into numbers. Once text is a vector, finding related content becomes a question of distance.
- 1
Meaning becomes coordinates
An embedding model maps words, sentences or images to vectors. Related things end up near each other.
- 2
Close means similar
Similarity is usually the angle between two vectors, called cosine similarity. A small angle means similar meaning.
- 3
Search by meaning
Embed the query and return the closest vectors. “puppy” finds “dog” and “kitten” without sharing a letter.
- 4
Search fast at scale
With millions of vectors, comparing against every one is slow. Indexes like HNSW hop through a graph of neighbors and get close in a few steps.
Meaning becomes coordinates
An embedding model maps words, sentences or images to vectors. Related things end up near each other.
Close means similar
Similarity is usually the angle between two vectors, called cosine similarity. A small angle means similar meaning.
Search by meaning
Embed the query and return the closest vectors. “puppy” finds “dog” and “kitten” without sharing a letter.
Search fast at scale
With millions of vectors, comparing against every one is slow. Indexes like HNSW hop through a graph of neighbors and get close in a few steps.
In short
- Real embeddings have hundreds or thousands of dimensions. The 2D picture is a simplification.
- Use the same embedding model for documents and queries, or the distances mean nothing.
- Approximate indexes like HNSW trade a little accuracy for a lot of speed, and the balance is tunable.