What are embeddings in AI?
An embedding is a list of numbers, a vector, that represents the meaning of a piece of text, an image or other data. Texts with similar meanings get vectors that are close together, which lets software search by meaning, group similar items and find the right documents for retrieval-augmented generation.
Embeddings turn "these two things mean something similar" into a number you can compute. That is what lets a search for "how do I reset my password" find a help article titled "Recovering account access" even though they share no words.
How do embeddings work?
An embedding model reads a piece of text and outputs a fixed-length vector, for example 768 or 1,536 numbers. The model is trained so that texts with similar meanings end up with vectors pointing in similar directions, and unrelated texts end up far apart. Each individual number has no human-readable meaning; the meaning is in the position of the whole vector relative to others.
The idea is older than LLMs. Word2vec, published by Google researchers in 2013, learned a vector for each word from how words appear together, and became famous for arithmetic like "king" minus "man" plus "woman" landing near "queen". Modern embedding models produce one vector for a whole sentence or passage, which is what search and retrieval need. Sentence-BERT, from 2019, was an influential early example.
How do you measure similarity between embeddings?
The standard measure is cosine similarity, which compares the angle between two vectors and ignores their length. A score near 1 means very similar meaning, near 0 means unrelated. Many embedding models output normalised vectors, in which case the dot product gives the same ranking and is cheaper to compute.
| Pair of texts | Likely similarity |
|---|---|
| "How do I reset my password?" / "Steps to recover account access" | High |
| "How do I reset my password?" / "Change your login credentials" | High |
| "How do I reset my password?" / "Our office hours are 9 to 5" | Low |
| "Python list comprehension" / "Python snake habitat" | Low to moderate, despite sharing a word |
What are embeddings used for?
Embeddings are used wherever software needs to compare meaning rather than exact words:
- Do: Semantic search: find documents that answer a query even when the wording differs
- Do: Retrieval for RAG: pick the passages to put in the model's context
- Do: Clustering: group support tickets, reviews or feedback by topic
- Do: Classification: label text by comparing it to example embeddings for each class
- Do: Deduplication: find near-duplicate records or questions
- Do: Recommendations: suggest items similar to what someone viewed
For search at scale, the vectors are stored in a vector database or a vector index in an existing database, which can find the nearest neighbours of a query vector among millions of stored vectors in milliseconds.
Are embeddings the same as what happens inside an LLM?
They are related but used differently. Inside every LLM, each token is first turned into a vector, and the model's layers keep transforming those vectors. A separate embedding model is trained specifically so that one output vector summarises a whole passage for comparison. You normally call a dedicated embedding model for search, rather than pulling vectors out of a chat model.
How do you choose an embedding model?
Choose on retrieval quality for your own data, then on cost, speed and vector size. Public leaderboards such as MTEB give a starting point, but the ranking on your documents and queries is what matters, so test two or three models on a small labelled set of real questions.
- Dimension
- The length of the vector; more dimensions can hold more nuance but cost more to store and search
- Cosine similarity
- A score from the angle between two vectors, the usual measure of semantic closeness
- Normalised vector
- A vector scaled to length 1, so dot product and cosine similarity agree
- Multilingual model
- An embedding model that places the same meaning in different languages close together
- Matryoshka embeddings
- Vectors trained so a shorter prefix still works, letting you trade accuracy for storage
Two rules prevent most embedding bugs. Always embed queries and documents with the same model, since vectors from different models are not comparable. And re-embed everything when you change models; there is no way to convert old vectors.
What are the limits of embeddings?
Embeddings capture general meaning but can miss exact details. Product codes, error numbers, names and negation ("flights that are not delayed") are common failure cases, because two passages can be about the same topic yet differ in the one detail the user cares about. This is why production systems often combine vector search with keyword search, an approach called hybrid search, and why how you chunk documents before embedding them matters so much.
Frequently asked questions
What is an embedding in simple terms?
An embedding is a list of numbers that represents what a piece of text means. Texts that mean similar things get similar lists of numbers, so a computer can measure how related two texts are.
What is the difference between a token and an embedding?
A token is a piece of text identified by an integer ID. An embedding is a vector of many numbers that represents meaning. Models convert tokens into embeddings before doing any computation on them.
How many dimensions should an embedding have?
Common sizes range from a few hundred to a few thousand dimensions. Larger vectors can capture more nuance but cost more to store and search. Test retrieval quality on your own data before choosing.
Can I mix embeddings from different models?
No. Each model places meanings in its own vector space, so vectors from different models cannot be compared. If you switch models, re-embed your entire collection.
Do embeddings work for images and audio?
Yes. Multimodal embedding models place images, text and sometimes audio in the same vector space, so a text query can find a matching image. The same similarity search techniques apply.
Last checked for accuracy on . Written by the solidcoder team.