Embeddings: what they are and what they're for
An embedding turns text into a vector of numbers where proximity means meaning. Learn how it works, cosine similarity, and why it powers semantic search and RAG.
You feed text into an AI model and it "understands" what it's about. But computers don't understand text: they understand numbers. So there's an invisible intermediate step that turns words, sentences, or whole documents into lists of numbers. That step is called an embedding, and it's the piece that makes semantic search, RAG, and recommendation work under the hood. Understanding embeddings demystifies half the AI hype.
This article explains what an embedding is, how you measure the proximity between two of them, and what that's good for in the daily life of anyone building products.
What an embedding is
An embedding is the representation of a piece of content — text, image, or audio — as a vector of numbers in a space of many dimensions. A "vector" here is just a list of numbers. "Many dimensions" means that list is long: 384, 768, 1536 numbers, depending on the model.
The core idea is simple and powerful: the position of each thing in that space carries meaning. Content with similar meaning ends up close together; different content ends up far apart. "Dog" and "hound" land in almost the same spot. "Dog" and "hydraulic gear" sit in opposite corners. The model doesn't store the words — it stores coordinates that encode their meaning.
The classic example that builds intuition is vector arithmetic: take the vector for "king", subtract the one for "man", add the one for "woman", and you land near the vector for "queen".
king - man + woman ≈ queen
This isn't magic: it's the result of the model having learned, from billions of text examples, that the relationship between "king" and "man" is similar to the relationship between "queen" and "woman". That structure ends up encoded in the geometry of the space.
How proximity is measured
If meaning becomes distance, we need a way to measure distance. The most common measure for embeddings is cosine similarity: it looks at the angle between two vectors, not their length. Two vectors pointing in the same direction have a cosine similarity near 1 (very similar); perpendicular ones give 0 (unrelated); opposite ones give -1.
In practice an embedding looks like this:
text: "puppy dog"
vector: [0.12, -0.04, 0.88, 0.31, -0.17, ...] (1531 more numbers)
cosine(a, b) = dot(a, b) / (norm(a) * norm(b))
cosine("dog", "hound") ≈ 0.94 # nearly identical
cosine("dog", "gear") ≈ 0.08 # unrelated
The reason to use cosine instead of straight-line distance is that it ignores the "magnitude" of the vector and focuses only on direction — which is where the meaning lives. A short text and a long text about the same subject point in the same direction, even if they have different magnitudes.
What they're good for in practice
The reason embeddings are everywhere is that, once meaning becomes geometry, several hard problems turn into "find the nearest vectors". The main uses:
Semantic search. Instead of searching for the exact word, you embed the user's question and look for the documents whose vectors are closest. Someone searches "how do I cancel my subscription" and finds an article titled "Ending your plan", even with no words in common. It's search by meaning, not by string.
RAG (retrieval-augmented generation). This is the hottest application today. Before asking the language model for an answer, you use embeddings to retrieve the most relevant snippets from your knowledge base and inject them into the prompt. If you want to understand the full retrieval-and-generation cycle, it's worth reading what RAG is and how it solves the hallucination problem — embeddings are the retrieval gear that makes RAG work.
Recommendation. Similar items have similar vectors. "People who read this also read that" can be implemented as nearest neighbors in the embedding space.
Clustering and deduplication. Grouping thousands of support tickets by theme, or detecting that two texts say the same thing with different words, becomes a matter of measuring distances.
Classification. Embed labeled examples, embed the new item, see which group it lands closest to.
Models, dimensions, and where to store them
Embeddings don't come from nowhere: they come from an embedding model, trained specifically to put similar meaning at nearby points. Different models produce vectors of different dimensions — 384 in a lightweight model, 768 or 1536 in the larger ones. More dimensions usually means more nuance captured, at the cost of more memory and more processing per comparison.
A detail that trips many people up: you cannot mix embeddings from different models. Each model draws its own space; a vector from model A has no relationship to a vector from model B. If you switch models, you have to re-embed everything.
Before embedding a text, it's worth understanding what's actually becoming a vector. Running the document through a term frequency analyzer shows which words dominate the content — useful for noticing, for instance, that half your text is footer boilerplate that will dilute the meaning in the embedding.
To store and search millions of vectors fast, you use a vector database (Pinecone, Qdrant, Weaviate, pgvector in Postgres). These databases are optimized for the operation "find the k nearest vectors to this one" without comparing against all of them one by one.
The limits: embeddings don't "understand"
Here's the part AI marketing leaves out. An embedding doesn't understand anything. It measures proximity in a space learned by statistical correlation. That has concrete consequences.
Quality depends entirely on the model and the domain. A model trained on generic internet text can do poorly on medical, legal, or engineering jargon, because it never saw those terms in enough context. Proximity in the space can also be misleading: "I do not recommend this product" and "I recommend this product" are almost identical in words and can land dangerously close, even though they mean the opposite. Negation is a classic Achilles' heel.
Embeddings also don't reason, don't do math, and don't fact-check. They say "these two texts seem to be about the same subject" — nothing beyond that.
Frequently asked questions
What's the difference between an embedding and a token?
A token is a unit the text is sliced into before entering the model — usually a piece of a word. An embedding is the vector of numbers representing the meaning of a token, a sentence, or a whole document. Tokenization comes first; the embedding is the result of processing those tokens.
Do I need a GPU to generate embeddings?
To generate large volumes quickly, a GPU helps a lot. But small embedding models run fine on CPU for modest volumes, and there are hosted APIs (OpenAI, Cohere, Voyage) that generate embeddings on demand without you maintaining infrastructure. For a prototype, start with an API.
How many dimensions should my embedding have?
It depends on the trade-off between quality and cost. Vectors of 384 dimensions are cheap to store and compare and are enough for many search tasks. Vectors of 1536 capture more nuance, useful in complex domains, but weigh more on the vector database. Start small, measure retrieval quality, and scale up only if you need to.
Do embeddings work in languages other than English?
Yes, as long as the model is multilingual. Good multilingual models put "dog" and "cachorro" close in the same space, which enables cross-lingual search: asking in Portuguese and retrieving documents in English. Models trained only on English do poorly outside it.
What to take away
An embedding is the bridge between text and math. It takes meaning — something computers can't manipulate — and turns it into coordinates computers love: distance, angle, nearest neighbor. That's exactly what makes semantic search and RAG work, and it's why understanding embeddings is worth more than memorizing buzzwords. Start with a ready-made model via API, measure retrieval quality in your real domain, and always remember: the vector measures proximity, not truth.
- 01 CPU Cores vs. Threads: What Actually Changes in Practice Understand the difference between CPU cores and threads and what actually changes for performance, multitasking, gaming, and development.
- 02 MIT, Apache, and GPL Licenses: Practical Differences for Developers MIT, Apache 2.0, and GPL are not the same thing. Understand permissive vs copyleft, patent protection, and compatibility before shipping code to production.