Embeddings Explained: How Text Becomes Numbers for Search and RAG
What are embeddings? Lists of numbers that capture the meaning of text, so similar ideas sit close together. Here is how they work and how to pick a model.
By Galactic News Editorial · Published 2026-11-20T01:42:20+00:00 · Updated 2026-11-20T01:42:20+00:00
Embeddings Explained: How Text Becomes Numbers for Search and RAG
What are embeddings? They are lists of numbers that represent the meaning of a piece of text. A model reads a sentence and returns a vector, which is a long list of decimal numbers. Sentences with similar meanings get similar vectors. Sentences about different topics get vectors that sit far apart. That simple idea powers semantic search, recommendations and retrieval-augmented generation, known as RAG. This guide explains how text becomes numbers, how the numbers are compared, and how to pick a model.
What are embeddings, in plain terms
An embedding is a numerical representation of a concept. The numbers capture meaning, not spelling. The sentences "the dog chased the ball" and "a puppy ran after a toy" share few words, but their embeddings land close together. The sentence "the stock market fell today" lands far away from both. The distance between two vectors measures how similar their meanings are.
Each embedding has a fixed length, called its dimension. A model that outputs 1,536 numbers per text produces 1,536-dimensional embeddings. Every text you send through the same model comes back with the same number of dimensions. That consistency is what makes comparison possible. Two vectors of different lengths cannot be compared directly.
Embeddings are not human-readable. No single number in the list means "dog" or "happy". The meaning lives in the pattern of all the numbers together. That is why you never read an embedding directly. You store it, compare it with others, and let the geometry do the work.
How text becomes a vector
An embedding model is a neural network trained on huge amounts of text. During training it learns which words and phrases appear in similar contexts. Words that appear together often end up with similar representations. The model compresses that knowledge into a vector for any input you give it.
OpenAI's current models are text-embedding-3-small and text-embedding-3-large. You send text to the embeddings API and get a vector back. A small request looks like this in Python: create a client, call client.embeddings.create with the model name and the input text, and read the embedding from the response. The small model returns 1,536 numbers by default. The large model returns 3,072.
Both models were trained with a technique called Matryoshka representation learning. That lets you ask for a shorter vector without losing much quality. You pass a dimensions parameter, for example dimensions=512, and the API returns a shorter vector. OpenAI reports that a 256-dimensional vector from the large model still beat the older ada-002 model at its full 1,536 dimensions on the MTEB benchmark. Shorter vectors mean smaller indexes, faster search and lower storage costs.
How similarity is measured
The standard comparison is cosine similarity. It measures the angle between two vectors and returns a number from -1 to 1. A score near 1 means the texts are very similar. A score near 0 means they are unrelated. A score near -1 means they are opposite in meaning. Cosine similarity ignores the length of the vectors and looks only at their direction. That matters because a short document and a long document on the same topic should score as similar.
OpenAI embeddings are normalised to a length of 1. That means cosine similarity, dot product and Euclidean distance give the same ranking. You can use whichever is fastest in your database. For most projects, cosine similarity is the default choice and the easiest to explain.
Similarity is relative, not absolute. A score of 0.8 is high for one dataset and ordinary for another. Set your threshold by testing on your own data. Take pairs of texts you know are related and pairs you know are unrelated. Look at the scores. Pick a cut-off that separates them cleanly. Re-check it when your content changes.
What are embeddings used for in search and RAG
Semantic search is the most common use. A user types a question in plain language. You embed the question, compare it with the embeddings of your documents, and return the closest matches. This finds answers that share no keywords with the question. Keyword search misses those. Embedding search finds them.
RAG builds on the same idea. Retrieval-augmented generation works in four steps. First, split your documents into chunks, usually a few hundred words each. Second, embed every chunk and store the vectors in a vector database. Third, embed the user's question and retrieve the most similar chunks. Fourth, pass those chunks to a language model with the question and ask it to answer from them. The embeddings handle the finding. The language model handles the answering. If the retrieval is wrong, the answer will be wrong too, so retrieval quality decides the whole system.
Embeddings also power clustering, classification and recommendations. You can group support tickets by topic, sort reviews by sentiment, or suggest articles similar to the one a reader just finished. Any task that starts with "find things like this" is a job for embeddings.
Choosing an embedding model
| Model | Dimensions | Max input tokens | Price per 1M tokens | MTEB retrieval score |
|---|---|---|---|---|
| text-embedding-3-small | 1,536 | 8,191 | 0.02 dollars | 62.3 |
| text-embedding-3-large | 3,072 | 8,191 | 0.13 dollars | 64.6 |
| text-embedding-ada-002 | 1,536 | 8,191 | 0.10 dollars | 61.0 |
Start with text-embedding-3-small. It is the cheapest option and the right default for most search and RAG work. Its MTEB retrieval score of 62.3 is close to the large model's 64.6 at roughly a sixth of the price. Move to the large model only when you have measured that retrieval quality is the bottleneck. The older ada-002 model is still callable, but you should not start a new project on it. It costs more than the small model and scores lower.
Open-source models are a real alternative when you need to run locally. BGE-M3, for example, produces 1,024-dimensional vectors, supports more than 100 languages and costs nothing to run beyond your own hardware. Self-hosting adds work: you manage the model, the updates and the scaling. A managed API removes that work for a small per-token fee. Choose based on your privacy needs and your team's appetite for running infrastructure.
Common mistakes with embeddings
The first mistake is mixing models or dimensions in one index. Vectors from different models are not comparable. Neither are vectors of different lengths. Pick one model and one dimension value per index and keep it fixed. If you change either, re-embed the whole corpus.
The second mistake is chunking badly. A chunk that is too long mixes several topics into one vector and matches nothing well. A chunk that is too short loses context and matches everything weakly. Aim for chunks that cover one idea, usually a paragraph or two. Keep headings and key context in the chunk so the embedding has something to hold on to.
The third mistake is skipping evaluation. Embedding quality varies by language and domain. A model that scores well on a general benchmark may struggle with your industry's terminology. Build a small test set of questions with known good answers. Measure how often the right chunk lands in the top results. That number tells you more than any benchmark.
The fourth mistake is embedding everything the same way. Queries and documents are different kinds of text. Some systems add a short prefix to queries, such as "search for:", to mark the difference. Test whether that helps on your data. Small changes in how you phrase the input can shift retrieval quality more than switching models.
Bottom line
Embeddings turn text into numbers that capture meaning. Similar meanings sit close together. That geometry powers semantic search and RAG. Start with text-embedding-3-small, chunk your documents by idea, store the vectors in one index with one model and one dimension, and measure retrieval on your own questions. The model choice matters less than the chunking, the index discipline and the evaluation. Get those right and the search will follow.