Embeddings in LLMs: Types, Storage and What They Do
Embeddings turn text into numbers so a language model can search by meaning, not keywords. Learn the types, how they are stored, and where they matter.
On this page
Short answer
Embeddings are lists of numbers that place text, images or other items as points in a space, so items with similar meaning sit close together. In LLM applications they power semantic search and retrieval, letting a model find the right documents by meaning and ground its answers in them.
What are embeddings?
Embeddings are lists of numbers that represent a piece of text, an image or another item as a point in a multi-dimensional space, so that items with similar meaning sit close together. A word, a sentence or a whole document can each be turned into one embedding.
The key idea is distance. Two embeddings that sit close together represent items that mean similar things, while embeddings far apart represent items that mean different things. That distance can be measured with simple arithmetic, which is what makes embeddings useful: a computer can compare meaning without understanding language the way a person does.
Embeddings are not the same as the text itself. They are a compressed summary of what the text means, produced by a model trained on large amounts of text. The same sentence can produce different embeddings from different models, because each model learns its own way of measuring meaning.
What types of embeddings are there?
Embeddings come in several types, and the type you use depends on what you want to compare. The main split is by the size of the item being embedded, from single words up to whole documents, plus specialised types for code and other media.
| Type | What it represents | Typical use |
|---|---|---|
| Word embeddings | One word | Word similarity and analogy |
| Sentence embeddings | One sentence | Matching questions to answers |
| Document embeddings | A paragraph or page | Search over a knowledge base |
| Code embeddings | A function or file | Code search and duplication |
| Multimodal embeddings | Text plus image or audio | Cross-media search |
Most LLM applications use sentence or document embeddings, because the job is usually to find the right passage, not the right word. Multimodal embeddings matter when the search has to cross media, such as finding a photo from a text description.
How are embeddings made?
Embeddings are made by an embedding model, which takes a piece of text and returns a list of numbers. The model is trained on large amounts of text, so it learns which words and phrases appear in similar contexts, and it places items that appear together close to each other in the space.
Different models produce embeddings with different dimensions, commonly from a few hundred to a few thousand numbers per item. More dimensions can capture finer distinctions, but they also cost more to store and to search, so the choice of model is a trade-off between quality and cost.
The model choice matters more than most teams expect. A model trained on general web text works well for everyday language but may miss the meaning of domain terms, such as medical or legal language. For those cases, a model trained on the domain, or a general model with good coverage, will retrieve better results.
How are embeddings stored?
Embeddings are stored in a vector database, which is built to search by distance rather than by exact match. When a query arrives, the database compares the query embedding with the stored embeddings and returns the closest ones, using an index that makes the search fast even with millions of items.
The index is the part that makes large-scale search practical. A brute-force comparison of every stored embedding would be too slow, so vector databases use approximate nearest neighbour indexes that find the closest items without checking all of them. The approximation is a trade-off: a faster index may miss the single closest item, but it returns the closest few reliably.
Metadata is stored alongside each embedding, such as the source document, the date and the section it came from. That metadata matters because retrieval usually filters first, by source or date, and ranks second, by distance. Storing the source text next to its embedding also lets the application show the retrieved passage to the model and to the user.
What do embeddings do inside an LLM application?
Inside an LLM application, embeddings let the model find the right documents by meaning and ground its answers in them. The usual pattern is retrieval-augmented generation: the question is turned into an embedding, the closest passages are retrieved, and those passages are given to the model alongside the question.
That pattern matters because a language model on its own can only answer from what it learned in training. Retrieval gives it fresh, specific information from your own documents, so the answer is grounded in sources you control rather than in the model's memory.
Embeddings also decide what the model sees. If retrieval returns the wrong passages, the answer will be wrong even if the model is strong, so retrieval quality is usually the first thing to fix when answers go wrong. RAG development covers how retrieval and generation fit together in a working system.
Where else are embeddings used?
Embeddings are used wherever items need to be compared by meaning rather than by exact words. Search and retrieval are the best-known uses, but the same idea powers recommendations, clustering, classification and duplicate detection.
Recommendations work by finding items close to one a user already liked: a product, an article or a song whose embedding sits near the one the user chose. Clustering groups similar items together, which is useful for organising a large set of documents or support tickets into themes.
Classification and duplicate detection use embeddings as input to a simple model. A classifier can learn which region of the space belongs to which category, and a duplicate check can flag two items whose embeddings are nearly identical. In each case the embedding does the hard work of turning meaning into numbers, and a small model does the rest.
Example (hypothetical): a support team finds the right article
Example (hypothetical): a support team has 400 help articles and turns each one into embeddings, splitting long articles into chunks. The 400 articles become 1,200 chunks, each with its own embedding and a link back to its source article.
When a customer asks a question, the team turns the question into an embedding and retrieves the 5 closest chunks. A support agent reads those 5 chunks, which takes about 2 minutes, and writes an answer grounded in them. Without embeddings, the agent would search by keywords and read about 20 articles to find the right one, which takes about 60 minutes at 3 minutes per article.
The saving is 58 minutes per question, and the answer is better because it is grounded in the retrieved passages. The team also finds that 3 of the 5 retrieved chunks are usually relevant, so the agent can answer from the first 3 and ignore the other 2.
What are the common mistakes?
The most common mistakes are embedding the wrong chunk size, skipping metadata, and judging the model before testing retrieval.
- Chunks that are too large. A whole page in one embedding blurs distinct topics together, so split at natural boundaries such as headings and paragraphs.
- No metadata stored. Without source, date and section, you cannot filter results or show the user where an answer came from.
- Wrong model for the domain. A general model may miss specialist terms, so test retrieval on your own documents before committing.
- Judging the model first. When answers are wrong, the cause is usually retrieval, not the language model, so check what was retrieved before changing models.
- Ignoring cost. Every chunk costs money to embed and store, so clean and deduplicate documents before embedding them.
For the practical side, embeddings best practices covers chunking, model choice and testing in more depth.
LLM development covers how retrieval fits into a production application.
Key takeaways
- Embeddings turn meaning into numbers, so similarity becomes distance
- Sentence and document embeddings suit most LLM applications
- Vector databases store embeddings with metadata for filtering
- Retrieval quality decides answer quality in RAG systems
- Test retrieval on real questions before judging the model
Frequently asked questions
What is an embedding in simple terms?
An embedding is a list of numbers that represents a piece of text, an image or another item as a point in a space. Items with similar meaning sit close together in that space, so a computer can compare meaning by measuring distance between the numbers.
What is the difference between embeddings and keywords?
Keywords match exact words, so a search for car misses a document that only says automobile. Embeddings match meaning, so the same search finds the automobile document because the two words sit close together in the embedding space.
How many numbers are in an embedding?
It depends on the model, commonly from a few hundred to a few thousand numbers per item. More dimensions can capture finer distinctions, but they cost more to store and to search, so the choice is a trade-off between quality and cost.
Do I need a vector database for embeddings?
For a small set, a simple list and a distance calculation are enough. Once the set grows past a few thousand items, a vector database with an approximate nearest neighbour index makes search fast enough to use in a live application.
Can embeddings be used for images and audio?
Yes. Multimodal embedding models turn images, audio and text into the same space, so a text query can find a photo or a clip. The same idea applies: items that mean similar things sit close together, whatever kind of media they are.
Why do embeddings matter for LLMs?
Because they let a language model find the right documents by meaning and ground its answers in them. Without retrieval, a model can only answer from its training data, which may be outdated or missing your own information.