Embeddings explained

Last updated

Embeddings are one of the quiet building blocks behind many AI features. They are how a system can find a document about "refunds" when you search for "getting my money back," group similar customer complaints together, or recommend related articles. You do not need to understand the math to use them well, but knowing what they are and how they behave helps you build better AI systems.

What an embedding is

An embedding is a list of numbers that represents the meaning of a piece of content, such as a word, a sentence, a paragraph, an image, or a whole document. An embedding model reads the content and outputs this list, often hundreds or thousands of numbers long. The list is called a vector.

The key property: content with similar meaning gets similar vectors. "How do I return an item?" and "What is your refund process?" use different words but produce vectors that are close together. "How do I return an item?" and "What time do you open?" produce vectors that are far apart.

You can picture it as a map. Every piece of content gets a location, and related ideas cluster near each other. The real map has hundreds or thousands of dimensions instead of two, but the idea is the same.

How embeddings are created

Embedding models are trained on large amounts of text, and sometimes images, to learn which content is related. They are typically smaller and much cheaper to run than chat models. Many providers offer embedding models through their APIs, and good open-weight embedding models can be run locally.

To embed content, you send text to the embedding model and receive a vector back. You store the vector alongside the original text and any useful details, such as the source document, date, and access permissions.

Measuring similarity

To find related content, a system compares vectors with a similarity measure. A common one is cosine similarity, which measures how closely two vectors point in the same direction. The higher the similarity, the closer the meaning.

Searching through millions of vectors quickly requires specialized indexes, which is one of the main jobs of a vector database.

What embeddings are used for

Semantic search

Traditional keyword search matches exact words. Semantic search matches meaning. A user can describe what they want in their own words and still find the right content. Many systems combine both, because keyword search remains better for exact terms like product codes, names, and error numbers.

Retrieval-augmented generation

Embeddings are the retrieval engine behind most RAG systems: the question is embedded, and the closest chunks of your documents are found and handed to a language model. See Retrieval-augmented generation (RAG) explained.

Grouping and discovering themes

Embedding customer feedback, support tickets, or survey responses and grouping nearby vectors reveals common themes without reading every item first.

Classification

Embeddings can help sort content into categories, such as routing support tickets, by comparing new items to labeled examples.

Recommendations

"Related articles" or "similar products" features can use embeddings to find items close in meaning to what someone is viewing.

Duplicate detection

Near-identical vectors can flag duplicate or near-duplicate content, such as repeated support questions or duplicate records.

Choosing an embedding model

Factors to consider:

  • Quality on your type of content. Public benchmarks give a starting point, but test with your own documents and real queries.
  • Language support, if your content or users span multiple languages.
  • Maximum input length, which affects how large each chunk can be.
  • Vector size. Larger vectors can capture more nuance but use more storage and can be slower to search. Some models let you choose a smaller size.
  • Cost and hosting. Hosted embedding APIs are typically inexpensive per token. Local embedding models avoid sending content to a third party, which matters for sensitive documents.
  • Data terms, just as with any AI provider. See Will an AI provider train on your data?

Important things to know

Vectors from different models are not compatible

Each embedding model creates its own map. You cannot compare a vector from one model with a vector from another. If you switch embedding models, you must re-embed all your content. Plan for this when choosing a model, and store the original text so re-embedding is possible.

Use the same model for content and queries

The question and the documents must be embedded with the same model, and for some models the same settings, so they land on the same map.

Embeddings capture meaning, not truth

Similar meaning does not mean correct or relevant. A passage can be close in meaning to a question without actually answering it. That is why RAG systems often add reranking and instruct the model to say when the answer is not found.

Chunking matters

How you split documents before embedding strongly affects results. A chunk that mixes several topics gets a blurry vector that matches nothing well. See Preparing your documents for AI.

Embeddings are derived from your data

Vectors can reveal information about the original text, and the text is usually stored alongside them anyway. Protect embedding stores with the same care as the source documents.

A simple example

A small online store embeds every product description. A shopper searches for "warm waterproof boots for hiking in snow." The search embeds that phrase, finds the product descriptions with the closest vectors, and returns insulated, waterproof hiking boots, even though no description contains that exact phrase. Adding keyword search ensures that a shopper typing an exact model number also finds the right product.

Key takeaways

  • An embedding is a list of numbers representing the meaning of content.
  • Similar meaning produces similar vectors, enabling search by meaning rather than exact words.
  • Embeddings power semantic search, RAG, theme discovery, classification, recommendations, and duplicate detection.
  • Choose a model by testing on your content, considering language, length, size, cost, and data terms.
  • Vectors from different models are incompatible; switching models means re-embedding everything.