Embeddings
An embedding turns any piece of content (a word, sentence, document, image) into a list of numbers positioned so that similar meanings land close together, making meaning something software can measure with a ruler.
Learning Objectives
- Explain what an embedding is: meaning as coordinates.
- Understand why "similar meaning = nearby points" is so useful.
- Compute similarity intuition with a tiny worked example.
- Identify the applications embeddings power: search, recommendations, RAG.
- Know how embeddings are made and the main practical choices.
Why This Matters
Embeddings are the quiet workhorse of applied AI. Semantic search, recommendations, deduplication, clustering, classification, and the entire retrieval half of RAG (AI-016) are embeddings underneath. If LLMs are the celebrity, embeddings are the plumbing every real system runs on. And they're cheap, fast, and available to any developer today.
Everyday Analogy
A map of meaning. On a city map, nearby dots are physically close. An embedding space is a map where nearby dots are close in meaning: "puppy" sits beside "dog," a stone's throw from "kitten," across town from "carburetor." Every new sentence gets GPS coordinates on this map. Once meaning has coordinates, "find similar things" becomes "find nearby dots," a problem computers solve brilliantly.
From Text to Numbers: A Tiny Worked Example
Real embeddings have hundreds to thousands of dimensions; here is a cartoon with 3, scoring each word on [animal-ness, size, domesticity]:
| Word | Animal | Size | Domestic |
|---|---|---|---|
| dog | 0.9 | 0.4 | 0.9 |
| puppy | 0.9 | 0.2 | 0.9 |
| wolf | 0.9 | 0.5 | 0.1 |
| car | 0.0 | 0.6 | 0.5 |
Distances now mean something: dogβpuppy are nearly touching; dogβwolf differ mainly on one axis (domesticity); dogβcar are far apart. Real models learn ~1,536 such axes automatically from data. They're unlabeled and uninterpretable individually, but collectively capture tone, topic, syntax, and subtle shades no human would think to enumerate. Similarity is computed with a dot product or cosine: one multiplication per axis, summed, giving measurable meaning.
The Famous Party Trick β and What It Reveals
In good embedding spaces, directions carry meaning: the vector from "man" to "woman" is roughly parallel to the one from "king" to "queen," so king β man + woman β queen. Paris β France + Japan β Tokyo. Meaning has geometry: relationships are arrows, categories are neighborhoods. This is not a gimmick. It's the property that makes everything downstream work, and it's also where bias hides: directions learned from human text carry human stereotypes along for the ride (AI-062).
Where Embeddings Run Your Life
- Semantic search. Query and documents both become vectors; results are nearest neighbors. Finds "reset my password" when you typed "can't log in" β no shared keywords needed.
- Recommendations. "Users who liked X" = "vectors near X." Spotify, Netflix, and e-commerce run on neighborhood lookups.
- RAG retrieval (AI-016). The "R" is an embedding search over your knowledge base.
- Deduplication & clustering. Near-identical support tickets, duplicate listings, topic groupings β all distance thresholds.
- Classification on a budget. Embed, then run a tiny classifier on top β often 95% of the quality at 1% of the cost of an LLM call.
Practical Choices
Getting embeddings is one API call (OpenAI, Cohere, Voyage) or a free local model (sentence-transformers). The decisions that matter:
- Model choice β leaderboards (MTEB) rank retrieval quality; domain-specific models exist for code, law, medicine.
- What to embed β whole documents blur; embed chunks (paragraphs) for retrieval precision (chunking strategy returns in AI-016).
- Dimension trade-off β more dimensions = finer meaning but more storage and slower search (AI-015 picks this up).
- Same model both sides β queries and documents must share one embedding space; mixing models breaks similarity entirely.
Real-World Showcase
- Google Search has used embedding-based understanding (BERT and successors) since 2019, and billions of queries a day ride on meaning-vectors.
- Spotify's Discover Weekly embeds songs and listeners into a shared space; your Monday playlist is a neighborhood tour.
- Notion, Slack, and GitHub all shipped semantic search by embedding your workspace: the feature that finds the doc you described rather than the words you remembered.
Try It Yourself
- Rank by meaning, yourself: order these by similarity to "The chef cooked a wonderful meal" β (a) "A delicious dinner was prepared," (b) "The chef was arrested," (c) "Rain is expected today." Your instant ranking (a, b, c) is what cosine similarity computes β you are an embedding model.
- Trip up keyword search: search a shopping site for "footwear for running" vs "running shoes" and note any difference; semantic search would treat them identically.
- Guess the axes: for songs instead of words, what might learned dimensions capture? (Tempo, mood, era, acousticness β Spotify's embeddings learn exactly such axes without being told.)
Common Mistakes
- Treating embeddings as keyword search. They match meaning; exact part-numbers and names sometimes need hybrid keyword+vector search (AI-015).
- Comparing vectors from different models β different maps, meaningless distances.
- Embedding whole books as one vector β meaning blurs; chunk first.
- Reading individual dimensions β axes are learned and distributed; only distances and directions are meaningful.
- Forgetting bias β embedding geometry inherits the prejudices of training text (AI-062).
Key Takeaways
- Embedding = content β coordinates on a learned map of meaning.
- Similar meaning = nearby vectors; similarity is a cheap arithmetic operation.
- Directions encode relationships (king β man + woman β queen), and encode biases too.
- Search, recommendations, clustering, and RAG retrieval are all nearest-neighbor lookups.
- Chunk your content, pick one model for both sides, and you're production-ready.
Glossary
- Embedding
- A list of numbers, typically ~1,536 learned axes, positioning any content on a map of meaning where similar things land close together. "Puppy" sits beside "dog," across town from "carburetor," and finding similar things becomes finding nearby dots.
- Cosine Similarity
- The cheap arithmetic (one multiplication per axis, summed) that measures how close two vectors are in meaning. Your instant ranking of "a delicious dinner was prepared" as closest to "the chef cooked a wonderful meal" is what cosine similarity computes.
- Semantic Search
- Search where query and documents both become vectors and results are nearest neighbors, finding "reset my password" when you typed "can't log in," no shared keywords needed. It still misses exact identifiers, which is why production systems add hybrid keyword search. (see AI-015)
- Vector Arithmetic
- The party trick that directions carry meaning: king β man + woman β queen, Paris β France + Japan β Tokyo. Relationships are arrows and categories are neighborhoods, and stereotype directions ride along too. (see AI-062)
- Chunking
- Splitting documents into paragraph-sized pieces before embedding, because whole documents blur into mushy vectors. Chunk strategy is a core retrieval-quality lever. (see AI-016)
- Embedding Model
- The model that converts content into vectors: one API call (OpenAI, Cohere, Voyage) or a free local sentence-transformers model. Queries and documents must use the same model; mixing models breaks similarity entirely.
- Dimension
- One learned axis of the embedding space, uninterpretable individually but collectively capturing topic, tone, syntax, and subtler shades. More dimensions mean finer meaning but more storage and slower search. (see AI-015)
References
Diagram
Knowledge Check
6 questions