Module 7 · AI infrastructureLesson 80 of 887 minIntermediate
Embeddings
An embedding turns text (or an image) into a list of numbers, a point in space, so that similar meanings end up close together.
Pick each search phrase and see which points are nearest and how similar they are, even when the exact word never appears.
Computers compare numbers easily and meanings poorly. An embedding model bridges the gap: it reads a piece of text and outputs a vector, a list of a few hundred or thousand numbers.
Trained on huge amounts of text, these models learn to place things with similar meaning near each other:
- "kitten" lands near "cat",
- "a small cat" lands near both, even though "kitten" never appears in it,
- "spaghetti" lands near "pasta", far from "truck".
Real embeddings have hundreds of dimensions; the demo squashes the idea into two so you can see it.
Measuring closeness
The usual measure is cosine similarity: the angle between two vectors, from -1 (opposite) to 1 (same direction). Dot product and Euclidean distance are also used. Values near 1 mean very similar.
What you can build
- Semantic search: find documents by meaning, not exact words.
- RAG: find the passages to give an LLM (coming up).
- Recommendations: "more like this".
- Clustering and deduplication: group similar support tickets, find near-duplicate products.
- Classification: compare a text to example embeddings of each category.
Practical notes
- Use the same model to embed documents and queries; vectors from different models aren't comparable.
- Changing the embedding model means re-embedding everything.
- Embeddings are only as good as the model's understanding of your domain; test with real queries.
- Storing and searching millions of vectors needs a vector database, next.