Embeddings Explained: How AI Turns Text into Vectors
Embeddings turn meaning into numbers that a system can compare.
Key takeaways
- An embedding is a fixed-length vector that places similar meaning close together in space — it is a comparison tool, not a compressed copy of the text.
- Cosine similarity ranks candidates; it does not certify correctness. The ranking is only as good as the chunking and metadata beneath it.
- A bigger vector dimension is not a better vector. Benchmark
recall@kon your own questions before picking a model. - Most retrieval failures are chunking failures, not embedding failures. Fix chunk boundaries before switching models.
What an embedding actually is
An embedding is a vector of floating-point numbers — typically somewhere between 384 and 3072 of them — produced by a model that has learned to place semantically similar inputs near each other in that space and dissimilar inputs far apart. The model is not storing the sentence. It is projecting the sentence into a coordinate system built specifically so that distance in that system corresponds to something useful: topical closeness, intent similarity, or shared context, depending on how the embedding model was trained.
This is the part people skip past too quickly. Two embeddings being close does not mean the two texts say the same thing. It means the model's training pushed texts like these close together for whatever objective it optimized. That objective is usually retrieval-shaped (does this passage answer this query?) rather than truth-shaped (are these two facts identical?). Treating embeddings as a similarity oracle instead of a trained approximation is the root of most confused debugging sessions.
Similarity is the operation, ranking is the point
Once two pieces of text are embedded, you compare their vectors with a distance or similarity function. Cosine similarity is the default choice because it measures the angle between vectors rather than their magnitude, which makes it robust to differences in text length.
| Metric | What it measures | When to prefer it |
|---|---|---|
| Cosine similarity | Angle between vectors, ignores magnitude | Default for text embeddings; most models are trained/normalized for this |
| Dot product | Angle and magnitude combined | When the embedding model was explicitly trained for dot-product retrieval (check the model card) |
| Euclidean (L2) | Straight-line distance | Rare for text; more common in image or audio embeddings |
Watch out: mixing metrics with a model trained for a different one silently degrades ranking quality. If your vector database defaults to dot product and your embedding model assumes cosine, normalize your vectors before indexing or switch the index metric — don't leave it to chance.
The absolute similarity score rarely matters on its own. A score of 0.71 means nothing in isolation; what matters is whether it is higher than the scores of the other candidates, because the operation you actually care about is ranking: given a query, which of your stored chunks are most likely to be relevant, in order?
Why chunking decides more than the model does
Embedding an entire twenty-page document as a single vector creates a weak retrieval unit — it blends dozens of topics into one point in space, so it will never rank highly for any specific question buried inside it. Splitting too aggressively causes the opposite failure: chunks that are grammatically complete but stripped of the surrounding context that gave them meaning.
| Chunk size | Typical failure mode | Fix |
|---|---|---|
| Whole document | Vector is an average of everything; nothing ranks well | Split by section or heading first |
| 1–2 sentences | Correct sentence retrieved, but missing context to answer the question | Add a sliding overlap of 1–2 sentences, or attach parent-section context |
| 200–500 tokens, boundary-aware | Usually the sweet spot for technical and prose content | Split on headings/paragraphs, not fixed character counts |
| Tables and code blocks | Split mid-row or mid-function, destroying meaning | Treat as atomic units; never split inside them |
A practical starting point: split by semantic boundaries — headings, paragraphs, list items — rather than a fixed character count, and only add overlap between chunks when a concept genuinely spans the boundary. Overlap by default just duplicates noise across your index and inflates storage without improving recall. For a fuller comparison of fixed, recursive, semantic and structure-aware splitting — including when each one is worth its extra cost — see RAG chunking strategies compared.
Keep tables, code blocks and FAQ pairs as atomic chunks. Splitting a table mid-row or a function mid-body destroys the one property — local coherence — that made it embeddable in the first place.
Dimensions are not quality
A larger vector does not automatically retrieve better results. Retrieval quality depends on the embedding model's training data and objective, language and domain coverage, and how well the model's notion of "similar" matches your users' notion of "relevant" — not on how many floats the vector contains.
Higher dimensions do cost you something concrete: more storage per vector, slower approximate-nearest-neighbour search at scale, and higher indexing memory. If a 768-dimension model retrieves as well as a 3072-dimension one on your own question set, the smaller model is the correct production choice.
Embeddings inside a RAG pipeline
A common retrieval-augmented generation pipeline looks like this: query → query embedding → vector search → top-k chunks → prompt assembly → model response. The embedding stage is one component among several, and it is rarely the one that fails first.
- Query embedding — the user's question is embedded with the same model used to index the corpus. Using a different model here is a common, silent bug: the two vector spaces are not comparable.
- Vector search — an approximate nearest-neighbour index returns the top-k closest chunks by the chosen similarity metric.
- Metadata filtering — results are narrowed by date, source, permission or category before or after the vector search, depending on the index.
- Reranking (optional) — a cross-encoder re-scores the top candidates with a slower but more accurate model, correcting ordering mistakes the embedding-only pass made.
- Prompt assembly — the surviving chunks are inserted into the model's context, ideally with enough surrounding metadata that the model knows what it's reading.
Poor chunking, missing metadata filters, or a skipped reranking step will ruin a good embedding model's output. Diagnose the whole pipeline before you blame the vectors.
See how vector databases turn this search step into a production system for the index-level trade-offs that sit underneath step two.
How to evaluate an embedding choice properly
Benchmark leaderboards measure average performance across generic tasks. Your corpus is not generic. The only evaluation that predicts production behaviour is one built from your own data.
| Step | What to do |
|---|---|
| 1. Build a question set | Collect 30–100 real user questions, each with the chunk(s) that should answer it |
| 2. Pick a metric | recall@k — is the correct chunk in the top k results? |
| 3. Run the baseline | Measure recall@5 and recall@10 with your current model and chunking |
| 4. Change one variable | Swap the model, or the chunk size, or the overlap — never more than one at a time |
| 5. Compare | Keep the change only if recall improves on your question set, not on a public leaderboard |
Don't tune the prompt to compensate for weak retrieval. If the correct chunk is never in the top k, prompt engineering cannot recover information that was never handed to the model.
Measure recall before you change the model. If the correct chunk is never retrieved, the retrieval layer has to improve first — no amount of prompt tuning fixes a missing document.
Where embeddings go wrong in practice
- Query/document mismatch — embedding a short keyword-style query with a model trained on full sentences produces a poor match to full-sentence documents. Some models expose separate query and document embedding modes; use them.
- Stale indexes — content updates without re-embedding leave the vector index pointing at outdated text while the source of truth has moved on.
- No metadata filtering — semantically similar but permission-restricted or outdated documents surface anyway because nothing narrowed the candidate set before ranking.
- Ignoring outliers — a handful of consistently poor-recall queries usually points at one chunking problem, not seventeen unrelated ones. Group failures before fixing them individually.
Embeddings are the mechanism that makes semantic search and RAG possible, but they are one layer in a pipeline where chunking, metadata and evaluation decide whether that mechanism actually helps a reader find the right answer.
Frequently asked questions
What is an embedding in simple terms?
An embedding is a list of numbers that represents the meaning of a piece of text, positioned so that similar meanings end up close together in that numerical space.
Is cosine similarity always the right metric?
It is the right default for most text embedding models, but check the model card — some models are trained specifically for dot-product retrieval instead.
Do more dimensions mean a better embedding model?
No. Retrieval quality depends on training data and objective, not vector size. Benchmark recall on your own questions rather than choosing by dimension count.