Skip to content
AI Explained

What Are Embeddings? How AI Turns Meaning Into Numbers

How embeddings capture meaning as vectors, how similarity is measured, where they power search and RAG, how to pick a model, the prompts that help and the limits to know.

Illustration of embeddings: three white arrows rising from the origin of two axes, two close together pointing at one cluster of dots and a third at another cluster, on a purple-to-teal gradient

Ask an AI search tool for "ways to cut my heating bill" and it can surface a page titled "Reducing home energy costs in winter", even though the two share almost no words. The trick behind that is an embedding. This guide explains what embeddings are, how they're made and compared, what they're used for (including RAG), how to choose a model, which prompts help and where the limits lie.

What embeddings are, in plain English

An embedding is a list of numbers that represents the meaning of a piece of content: a word, a sentence, a paragraph, an image or a product. Each list, called a vector, has a fixed length, and each position in it is a dimension. Content with similar meaning gets similar numbers, so it sits close together in that space.

Think of a map: two coordinates place every town, and nearby towns have similar coordinates. An embedding does the same for meaning, with hundreds or thousands of coordinates instead of two. "Puppy" lands near "dog", "invoice overdue" lands near "late payment", and "quarterly revenue" lands a long way from "banana bread recipe".

The idea became famous in 2013, when Google researchers led by Tomas Mikolov published word2vec. Their paper notes that taking the vector for "King", subtracting "Man" and adding "Woman" gives a vector closest to "Queen". The space had picked up relationships nobody had programmed in.

Embeddings are not the same as AI tokens, though the two are linked. Tokens are the chunks of text a model reads, each with an ID number that carries no meaning; inside the model, every token ID is turned into an embedding first. The embeddings people usually talk about, and the subject of this guide, go a step further: one vector for a whole sentence, paragraph or document.

How an embedding model turns text into numbers

Text embeddings come from an embedding model: a neural network built on the same transformer architecture as the chatbots described in our guide to what an LLM is, but trained for a different job. A chat model generates text; an embedding model reads text and outputs a single vector.

Training usually works by comparison. The model sees huge numbers of pairs that belong together, such as a question and its answer, a headline and its article, or a sentence and its paraphrase, plus pairs that don't. It's adjusted until matching pairs produce vectors that are close and unrelated pairs produce vectors that are far apart. This is called contrastive learning.

A few practical facts follow from that:

  • Fixed length: a three-word query and a three-page report produce vectors of exactly the same size. OpenAI's text-embedding-3-small, for example, returns 1,536 numbers by default and text-embedding-3-large returns 3,072.
  • Context counts: modern models read the whole passage, so "bank" in "river bank" and in "bank account" pushes the vector in different directions.
  • Input limits: every model has a maximum input length, measured in tokens. Longer text is cut off or rejected, which is one reason documents are split into chunks first.
  • One model, one space: vectors only make sense next to vectors from the same model. Numbers from two different models can't be compared, even when the lists are the same length.
  • Not just text: OpenAI's CLIP (2021) learned a shared space for images and captions from 400 million image-text pairs, which is how you can search a photo library by typing "dog on a beach".

You don't need to train anything yourself: the main AI providers offer embedding models through their APIs, and free open-weight models run on your own machine.

How similarity is measured

Once everything is a vector, "how related are these two texts?" becomes a geometry question. The usual answer is cosine similarity, which measures the angle between two vectors and ignores their length. Arrows pointing the same way score close to 1; unrelated ones score near 0. Many providers normalise their vectors to a length of 1, and then cosine similarity, the dot product and ordinary distance all rank results in the same order.

A simplified example, with illustrative scores to show the pattern:

  • "How do I reset my password?" vs "I forgot my login details": high (around 0.8)
  • "How do I reset my password?" vs "Change the email address on my account": medium (around 0.5)
  • "How do I reset my password?" vs "Our office is closed on bank holidays": low (around 0.1)

Don't read the scores as percentages or compare them across models: each model has its own typical range. What matters is the ranking.

Finding the closest vectors to a query is called nearest-neighbour search. Checking every stored vector works for a few thousand items; for millions, systems use approximate methods that trade the occasional miss for speed. That's the main job of a vector database: storing embeddings with the original text and metadata, and finding the nearest ones in milliseconds. Many ordinary databases and search engines now offer vector search too.

What embeddings are used for

Wherever software has to judge whether two things mean roughly the same, embeddings are likely involved:

  • Semantic search: results that match meaning rather than exact words, so "cheap flights to Lisbon" finds "budget airfares to Portugal".
  • RAG: finding the passages an AI assistant should read before it answers. More on this below.
  • Recommendations: suggestions based on what items are about, not only on clicks.
  • Clustering: grouping 5,000 survey comments or support tickets into themes without reading them all first.
  • Classification: labelling new items by comparing them with a handful of labelled examples.
  • Duplicate detection: spotting near-identical FAQs, tickets or product listings written in different words.
  • Cross-language matching: multilingual models place "invoice", "factura" and "Rechnung" close together, so a question in one language can find a document written in another.

Embeddings in RAG, step by step

The most common place people meet embeddings today is retrieval-augmented generation (RAG): tools that answer questions from your own documents. Embeddings handle the retrieval half. A typical pipeline looks like this:

  1. Split each document into chunks, often a few hundred words each, ideally along headings or paragraphs.
  2. Embed every chunk with the embedding model and store the vectors with the text and its metadata (title, date, source).
  3. Embed the question with the same model when a user asks something.
  4. Retrieve the nearest chunks, typically somewhere between 5 and 20.
  5. Generate: put those chunks into the prompt and ask the chat model to answer from them, citing its sources.

Most RAG failures happen at step 4, not step 5: if the right chunk isn't retrieved, the best model in the world can't use it. Three improvements have become standard:

  • Hybrid search: combine embedding search with keyword search, which is better at exact terms such as product codes, names and error messages.
  • Re-ranking: retrieve generously, then let a second, more precise model reorder the candidates before the top few go into the prompt.
  • Context for each chunk: a chunk saying "revenue rose 3%" is useless without knowing which company and which quarter. Anthropic reported in September 2024 that adding a short generated context to each chunk before embedding cut failed retrievals by 35% in its tests; combined with keyword search the reduction was 49%, and 67% with re-ranking added.
Tip: Build a small test set before tuning anything: 20 to 30 real questions, each paired with the chunk that should answer it. Check how often that chunk appears in the top five results. That number tells you whether a change of chunk size, model or search method really helped, far more reliably than judging answers by eye.

How to choose an embedding model

There's no single best model. The public MTEB leaderboard on Hugging Face grew out of a 2022 benchmark covering 8 task types, 58 datasets and 112 languages, whose authors found that no method led on every task. Use it as a shortlist, then judge on what matters to you:

  • Language: if your content isn't all in English, choose a model sold as multilingual and test it in your own languages.
  • Domain: legal, medical or code-heavy text can trip up general models. Test with your own documents, not the leaderboard average.
  • Input length: check the maximum tokens per input against your chunk size. Our token counter gives a quick estimate.
  • Dimensions and cost: bigger vectors can capture more nuance but cost more storage and slow search down. Some newer models let you shorten their vectors with little loss in quality.
  • Hosted or local: an API is simplest; an open model on your own server keeps confidential text in-house.
  • Switching cost: change the model and you must re-embed every document, because old and new vectors can't be mixed.

Embedding models can also be trained further on pairs from your own field, but as with fine-tuning a chat model, try the cheaper fixes first: better chunks, hybrid search and re-ranking.

Tip: Store the name and version of the embedding model next to every vector, along with the date it was created. When a model is retired or replaced, you'll know exactly which records need re-embedding, rather than finding mixed vectors through strangely bad results.

Prompts that make embedding projects work better

You don't prompt an embedding model: it turns whatever you give it into numbers. Chat models, though, are very useful around it. These four prompts cover the commonest jobs.

First, the test set. Writing evaluation questions by hand is tedious, so have a chat model draft them from your chunks, then check every one:

Below is a passage from our [TYPE OF DOCUMENT, E.G. HR POLICY HANDBOOK]. Write [5] questions that a real [AUDIENCE, E.G. NEW EMPLOYEE] might ask and that this passage answers. Rules: - Use everyday wording, not the passage's own phrases, so the questions test meaning rather than word overlap. - Include one vague question and one with a typo. - Don't write questions the passage only partly answers. Passage: [PASTE CHUNK]

Second, context for each chunk, along the lines of Anthropic's method. Run it once per chunk and put the result in front of the chunk text when you embed it:

Here is a full document: [PASTE DOCUMENT] Here is one chunk from it: [PASTE CHUNK] Write one or two sentences (under 60 words) that situate this chunk within the document: name the document, the section and the company, period or product it refers to. Output only those sentences.

Third, rewriting the query. Short questions such as "refund rules?" embed poorly. One published approach, HyDE (Gao et al., 2022), has a chat model write a hypothetical answer and embeds that instead, because a plausible answer often sits closer to the real passage than the bare question does. The invented details only steer the search; users never see them:

Write a short passage (80–120 words) that would plausibly answer this question in our [KNOWLEDGE BASE / INTRANET / PRODUCT DOCS], using the vocabulary such a document would use. It's for search only and won't be shown to anyone, so don't hedge or add disclaimers. Question: [USER QUESTION]

Fourth, naming clusters. Grouping thousands of comments by embedding gives you numbered clusters, not themes. Paste a sample from each one:

These [20] customer comments were grouped together automatically because their meaning is similar. 1. Give the group a label of 2–5 words. 2. Describe the shared theme in one sentence. 3. List any comments that don't fit the theme. Base everything only on the comments below; if there's no clear theme, say "Mixed" rather than inventing one. Comments: [PASTE NUMBERED SAMPLE]

Limits worth knowing

  • Similar isn't the same as correct: retrieval finds text that resembles the question, not text that's true, current or authoritative. Feed a chat model an outdated policy and it will answer wrongly with confidence, a common source of AI hallucinations in RAG tools.
  • Weak on negation and exact details: "flights with a stopover" and "flights without a stopover" can look almost identical to an embedding, and serial numbers, dates or prices barely move a vector. Keyword search and metadata filters cover that gap.
  • They absorb bias: a 2016 study titled "Man is to Computer Programmer as Woman is to Homemaker?" showed that word embeddings trained on Google News articles reflected gender stereotypes. Modern models inherit patterns from their data too.
  • They aren't anonymous: a vector looks like meaningless numbers, but a 2023 study recovered 92% of 32-token texts exactly from their embeddings and pulled full names out of clinical notes. Protect a vector store as carefully as the documents it came from.
  • Chunking can break meaning: split a table from its heading, or squeeze 20 pages into one vector, and the specifics get lost. No embedding model fixes bad chunks.
  • They lock you in: every change of model means re-embedding the whole collection.

Embeddings are a quiet workhorse of modern AI: they're how a search box understands what you meant and how an assistant finds the right page among thousands. They measure resemblance, not truth, so pair them with keyword search, sensible chunks, a test set and a chat model that cites its sources. For what goes into the prompt after retrieval, see our guide to context engineering.

References

Put this into practice. Apply what you just read with our free tool: Token Counter & Cost Estimator →
By AI enthusiast & advanced user

Jordi Benitez has been using AI tools day to day for years. No researcher, no academic title — just an advanced user who has spent enough hours prompting ChatGPT, Claude, Gemini and image models to know what actually works, and built GetEasyPrompt to share it in plain language.

FAQ

Frequently asked questions

Embeddings are lists of numbers, called vectors, that represent the meaning of a word, sentence, document or image. Content with similar meaning gets similar numbers, so software can find related items by measuring how close their vectors are. They power semantic search, recommendations, clustering and the retrieval step of RAG tools.
Tokens are the chunks of text a model reads, each identified by an ID number that carries no meaning on its own. Embeddings are vectors that do carry meaning: inside a model every token is converted into one, and embedding models produce a single vector for a whole sentence or passage so it can be compared with others.
A vector database stores embeddings together with the original text and metadata, and finds the vectors closest to a query very quickly, usually with approximate nearest-neighbour search. It's the storage and search layer behind most RAG tools. Many ordinary databases and search engines now offer vector search as a feature too.
There's no single best one. Shortlist models from the public MTEB leaderboard, then test two or three on 20 to 30 real questions from your own documents. Check language support, maximum input length, vector size and cost, and whether you need to run the model locally. Remember that switching models later means re-embedding everything.

Write your next prompt in seconds

Turn a rough idea into a clear, structured prompt any AI can follow. Free, private, and no account needed.

Open the Prompt OptimizerSee all tools