Dev tools

What Are Embeddings? A Developer's Guide

Embeddings turn text into lists of numbers that capture meaning, so code can compare ideas instead of words. Learn how they work, how to use them and pitfalls.

By OmniAI Editorial · Nov 19, 2026 · 8 min read

Embeddings are lists of numbers that represent the meaning of a piece of text. An embedding model reads a word, sentence or document and turns it into a vector, often hundreds or thousands of numbers long. Texts with similar meanings end up with similar vectors, even when they share no words at all. That one property powers semantic search, recommendations, clustering, duplicate detection and most retrieval systems behind AI chatbots.

This guide explains embeddings for developers: what they are, how to create and compare them, where they are used, and the mistakes that cause poor results in practice.

What Are Embeddings?

Computers are good at comparing numbers and bad at comparing meaning. The words "car" and "automobile" share no letters, so a plain keyword search treats them as unrelated. Embeddings solve that by placing text in a space where distance stands for difference in meaning.

Picture a map. Every sentence becomes a point on it. "How do I reset my password?" and "I forgot my login details" land close together. "Best pizza in Naples" lands far away. Real embeddings use hundreds or thousands of dimensions instead of two, but the idea is the same: closeness means similar meaning.

These points are called vector embeddings because each one is a vector, an ordered list of numbers such as [0.021, -0.113, 0.087, …]. A single number on its own means nothing you can read. The meaning lives in the position of the whole vector relative to others.

A grey field of scattered dots in small clusters, with one cluster circled and a single dot inside it in orange.
Texts with similar meanings land near each other, so finding related content becomes finding nearby points.

How an Embedding Model Works

An embedding model is a neural network trained on huge amounts of text to place related content close together. During training it sees pairs of texts that belong together, such as a question and its answer or a title and its article, and learns to pull them closer while pushing unrelated texts apart.

When you send text to an embedding model, you get back one vector of fixed length, no matter whether you sent one word or a full page. The length is called the dimension count. Common sizes range from a few hundred to a few thousand dimensions.

Embeddings vs language models

Embedding models are related to chat models but do a different job. A chat model generates text. An embedding model only reads text and returns numbers. That makes embedding models much smaller, faster and cheaper to run. Many good ones run comfortably on a laptop.

Text embeddings and beyond

Most teams start with text embeddings, but the same idea works for other data. Image embeddings place similar pictures near each other, and multimodal models put text and images in the same space, so the phrase "a red bicycle" lands near photos of red bicycles. Code embeddings help search across repositories by what code does, not just by names.

Comparing Embeddings With Cosine Similarity

Once you have vectors, you need a way to measure how close they are. The standard measure is cosine similarity, which looks at the angle between two vectors and ignores their length.

  • A score near 1 means the texts point the same way: very similar meaning.
  • A score near 0 means they are unrelated.
  • Negative scores are possible but less common with modern text models.

Here is cosine similarity in plain Python, so you can see there's no magic:

import math

def cosine_similarity(a: list[float], b: list[float]) -> float:
    dot = sum(x * y for x, y in zip(a, b))
    norm_a = math.sqrt(sum(x * x for x in a))
    norm_b = math.sqrt(sum(y * y for y in b))
    return dot / (norm_a * norm_b)

Many embedding models return vectors already normalized to length 1. In that case cosine similarity and the simpler dot product give the same ranking, and the dot product is faster.

Other measures exist, such as Euclidean distance, but for text embeddings cosine similarity or dot product is the usual choice. Use whatever your model's documentation recommends.

Don't trust fixed thresholds

Similarity scores aren't comparable across models. One model may score related texts at 0.8, another at 0.5. Instead of picking a magic cutoff like "anything above 0.8 is a match," test on your own data: collect a few dozen examples of good and bad matches and see where the scores fall.

A Simple Embeddings Example

The open-source sentence-transformers library makes it easy to try embeddings locally:

from sentence_transformers import SentenceTransformer, util

model = SentenceTransformer("all-MiniLM-L6-v2")  # small, fast, 384 dimensions

docs = [
    "How do I reset my password?",
    "Our office is closed on public holidays.",
    "Steps to recover a forgotten login.",
]
query = "I can't sign in to my account"

doc_vecs = model.encode(docs)
query_vec = model.encode(query)

scores = util.cos_sim(query_vec, doc_vecs)[0]
for doc, score in sorted(zip(docs, scores), key=lambda p: -p[1]):
    print(f"{score:.2f}  {doc}")

The query shares almost no words with the password and login sentences, yet those two rank at the top. That is semantic search in a few lines. Hosted APIs from the major AI providers work the same way: send text, receive vectors, compare them.

Where Embeddings Are Used

Semantic search

Search by meaning instead of exact words. Embed your documents once, embed each query when it arrives, and return the nearest documents. Many teams combine this with classic keyword search, because keyword search still wins for exact terms like product codes and names.

Retrieval for AI chatbots (RAG)

Retrieval-augmented generation uses embeddings to find the passages that answer a question, then hands them to a language model. Our guide to what RAG is walks through the full pipeline, and our comparison of fine-tuning vs RAG explains when retrieval is the better choice.

Recommendations, clustering and deduplication

  • Recommendations: show articles or products near the ones a user liked.
  • Clustering: group thousands of support tickets or reviews by topic without labeling them first.
  • Deduplication: find near-duplicate entries that are worded differently.
  • Classification: train a simple classifier on embeddings instead of raw text, often with very little labeled data.
A grey question bubble on the left sending an arrow to a column of grey document cards, where the closest card is orange.
Semantic search embeds the question and returns the documents whose vectors are closest to it.

Storing Embeddings at Scale

Comparing a query against a few thousand vectors is easy in memory. With millions of vectors you need an index built for nearest-neighbor search. That is what vector databases do, and many regular databases now support it too, such as PostgreSQL with the pgvector extension. Our guide to vector databases covers the options.

Dimensions and cost

More dimensions can capture more detail, but every extra number costs storage and search time. A collection of 10 million vectors with 1,536 dimensions stored as 4-byte floats takes about 61 GB before any index overhead. Some newer models are trained so you can shorten their vectors with only a small quality loss, which can cut storage a lot. Only do this when the model supports it; chopping the end off a normal embedding breaks it.

Two grey bars of equal height, the left bar made of many thin slices and the right bar made of fewer, thicker slices, with the top slice of the right bar in orange.
More dimensions can hold more detail, but every extra number adds storage and search cost.

Common Mistakes With Embeddings

  • Mixing models. Vectors from different embedding models live in different spaces. Never compare them, and re-embed everything when you switch models.
  • Embedding huge chunks. One vector for a 30-page document blurs its meaning. Split documents into passages of a few paragraphs each.
  • Ignoring the query side. Some models expect a prefix or a separate mode for queries versus documents. Read the model card.
  • Skipping evaluation. Build a small test set of queries with known good results, and measure before and after every change.
  • Forgetting language. If your users write in several languages, choose a multilingual embedding model.

FAQ

What are embeddings in simple terms?

Embeddings are lists of numbers that represent the meaning of text, images or other data. Similar meanings produce similar numbers, so software can find related content by measuring how close the numbers are.

What is the difference between embeddings and vectors?

A vector is any ordered list of numbers. An embedding is a vector produced by a model to represent meaning. All embeddings are vectors, but not all vectors are embeddings.

What is an embedding model?

It is a neural network that converts text, images or other input into a fixed-length vector. It is trained so that related inputs produce vectors close to each other. Embedding models are much smaller and cheaper than chat models.

How many dimensions should embeddings have?

There is no single right number. Small models often use a few hundred dimensions, while large ones use a few thousand. Test a few models on your own data and weigh quality against storage and speed.

Can I use embeddings without a vector database?

Yes. For a few thousand items you can keep vectors in memory or in a regular database and compare them directly. A vector database or an index like pgvector becomes useful when you have hundreds of thousands of vectors or more.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog