Skip to content

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.

P Priya Sharma Updated 4 min read
How Embeddings Work and Why They Matter for Search

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.

A quick recap

Put simply, this guide is organised around the core ideas below, and each one matters for a different reason.

  • From words to directions — Think of a word like "bank".
  • Similarity is a dot product — The standard measure is cosine similarity: the cosine of the angle between two vectors.
  • 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.ar…
  • Where embeddings are used — explained in full above
  • Practical caveats — Embeddings are not a silver bullet.

Questions worth asking yourself

Use these prompts to turn the article into decisions about your own setup.

  • How does from words to directions apply to the way you approach embeddings explained today?
  • How does similarity is a dot product apply to the way you approach embeddings explained today?
  • How does semantic search in five lines apply to the way you approach embeddings explained today?
  • How does where embeddings are used apply to the way you approach embeddings explained today?

Putting it into practice

Applying embeddings explained is less about memorising every feature and more about building a repeatable routine. Start with the single task that costs you the most time each week, run it through the workflow described above, and keep a short note of what changed. Your own results are a better guide than any generic benchmark. The same principles show up wherever you work with RAG, Embeddings, Python.

The AI for Developers landscape moves quickly, so treat what you have read as a starting point rather than a fixed rulebook. Revisit the tools and techniques you rely on every few months, retire anything that no longer earns its place, and fold in only the additions that solve a problem you actually have.

Further reading

If this AI for Developers topic was useful, these related guides go deeper on the areas you are most likely to need next.

P

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.

Report an issue with this page

Comments

Leave a comment

Comments are moderated and will appear once approved.