How Embeddings Work and Why They Matter for Search
An embedding turns text into a list of numbers that captures meaning. That single idea powers semantic search, deduplication and recommendation.
An embedding is a list of numbers — usually hundreds or thousands long — that represents the meaning of a piece of text. Two pieces of text with similar meaning get similar embeddings. That single property is the engine behind semantic search, recommendations, clustering and much of modern RAG.
From words to directions
Think of a word like "bank". It appears in contexts about rivers and contexts about money. An embedding model learns to position "bank" somewhere between both meanings, and to push "riverbank" toward the water and "banking" toward finance. Meaning becomes geometry.
Embeddings work at the level of whole sentences and paragraphs too. A model like all-MiniLM-L6-v2 returns a 384-dimensional vector for any text up to a few hundred tokens. Frontier embedding models return even richer vectors.
Similarity is a dot product
The standard measure is cosine similarity: the cosine of the angle between two vectors. Identical direction means similarity 1.0; opposite means -1.0.
def cosine(a, b):
return sum(x*y for x, y in zip(a, b)) / (norm(a) * norm(b))
In practice you usually batch this as a matrix multiplication, which is why vector search is fast even for large collections.
Semantic search in five lines
import numpy as np
vectors = np.array([embed(chunk) for chunk in chunks])
q = np.array([embed(question)])[0]
top = np.argsort(vectors @ q)[::-1][:5]
results = [chunks[i] for i in top]
No SQL trick, no keyword matching — just geometry. Search by meaning finds "how do I reset my password" a document titled "Changing your credentials".
Where embeddings are used
- Semantic search and RAG retrieval.
- Deduplication: near-duplicate articles land close together.
- Recommendation: embed items and users, find nearest neighbours.
- Classification: compare text to class embeddings and take the nearest.
- Anomaly detection: outliers are simply far from everything else.
Practical caveats
Embeddings are not a silver bullet. Keyword-heavy queries (model names, SKUs, dates) often defeat pure semantic search — combine with BM25 in a hybrid index. Language and domain matter: a general embedding model works poorly on niche legal text without fine-tuning. And the embedding model you use must be the same for indexing and querying; mixing models produces meaningless similarities.
Finally, "similar meaning" is not "true". Embeddings capture statistical relatedness, not facts. Two sentences about different things can be similar because they share a topic. Use them for retrieval and ranking, not for judgement.
Embeddings let machines search by meaning instead of by spelling. That is why they became the foundation of modern retrieval.
Written by
Priya Sharma
Priya previously built ML systems at a cloud provider. She writes hands-on tutorials covering embeddings, RAG and model deployment.
More articles by Priya Sharma →Frequently asked questions
How long does it take to read this article?
Most readers finish in under ten minutes. Use the table of contents to jump to the section you need.
Do I need previous experience to follow along?
No. We explain every concept as it appears, and the code examples are self-contained.