Core Concepts Entry

Embeddings, explained

Reviewed August 2026

TL;DR: An embedding is a list of numbers - a vector - that represents what a piece of content means. Texts with similar meaning get vectors that sit close together, so "how similar are these two things?" becomes a distance calculation. That one trick powers semantic search, recommendations, clustering, and the retrieval half of RAG.

How it works

An embedding model is a neural network trained so that content with similar meaning produces nearby vectors. Feed it "How do I reset my password?" and "I forgot my login credentials" and you get two points that sit close together in a space with hundreds or thousands of dimensions - even though the sentences share almost no words. Feed it "best pizza in Chicago" and you get a point far from both. Keyword search would miss the first pair entirely; embedding distance catches it, because the comparison happens in meaning-space rather than letter-space.

The practical recipe is simple. Take your documents, run each chunk through an embedding model once, and store the vectors in a vector database. At query time, embed the user's question with the same model and ask the database for the nearest stored vectors - typically by cosine similarity, which measures the angle between them. Those nearest neighbors are your most relevant chunks. This is the engine inside semantic search and the retrieval step of RAG.

Two details matter in production. First, the query and the documents must be embedded by the same model - vectors from different models live in unrelated spaces, and swapping your embedding model means re-embedding the whole corpus. Second, an embedding compresses a chunk into a fixed-size vector, so chunk size is a real decision: embed a whole chapter and the vector is a blurry average of many topics; embed a sentence and it may lack context. Getting retrieval right is usually more about chunking than about the model.

Embeddings are not limited to text. Image, audio, and code embeddings work the same way, and multimodal embedding models place a photo of a beach and the sentence "a sunny beach" near each other in one shared space - which is how text-to-image search works.

Where it sits in the AI stack

Embeddings are the translation step between raw content and everything that searches over meaning:

Key tools and implementations

  • Provider embedding APIs

    Hosted endpoints from OpenAI, Google, Cohere, and Voyage that turn text into vectors per request.

  • Sentence Transformers

    The open-source library for running and fine-tuning embedding models on your own hardware.

  • pgvector

    A Postgres extension that stores vectors and answers nearest-neighbor queries with SQL.

  • MTEB leaderboard

    The standard public benchmark for comparing embedding model quality across tasks.