Try Bifrost Enterprise free for 14 days.
Request access
[ Embeddings ]

What are embeddings?

Quick answer

An embedding is a dense numeric vector that a trained model assigns to an input so that inputs with related meaning land close together. Semantic search, retrieval-augmented generation, and semantic caching all depend on that distance carrying meaning.

Updated 2026-09-08

Embeddings are dense numeric vectors that a learned model assigns to inputs so that geometric proximity encodes meaning. Two support tickets about refunds land near each other even when they share no vocabulary, and both land far from a ticket about GPU pricing.

"An embedding is a vector (list) of floating point numbers. The distance between two vectors measures their relatedness."

Source: OpenAI, Vector embeddings

That property makes semantic search, retrieval-augmented generation, semantic caching, clustering, and deduplication possible. Everything downstream (the index, the distance metric, the reranker) assumes that distance carries meaning.

The assumption holds only in a narrow sense. A model is trained until distance over its outputs correlates with one specific notion of relatedness. Knowing which notion separates retrieval that works from retrieval that returns plausible garbage.

Vectors, pooling, and input limits

An embedding is a fixed-length array of floats. OpenAI's embedding models return 1,536 dimensions for text-embedding-3-small and 3,072 for text-embedding-3-large by default. Similarity search reads meaning from how vectors sit relative to each other, not from any single coordinate.

Diagram
[ RENDERING DIAGRAM ]

Encoders cap their input. The e5-large model card says long texts are truncated to 512 tokens, Sentence Transformers truncates anything past a model's max_seq_length, and OpenAI's embedding models accept at most 8,192 tokens per input (API reference). Within the cap, pooling compresses everything into one fixed-size vector, and the Sentence Transformers docs warn that a model trained on short texts may represent long ones poorly. Both limits are why retrieval systems chunk documents, and both are properties of the encoder, not the store.

Contrastive training defines distance

Text embedding models are trained contrastively: the model sees an anchor, a positive that should be close, and negatives that should be far, and the loss pulls toward the positive and pushes from the negatives. Sentence-BERT used siamese and triplet network structures (bi-encoders) to produce sentence embeddings that can be compared with cosine similarity, and later work such as OpenAI's contrastive pre-training and the weakly supervised E5 recipe scaled contrastive training with in-batch negatives to web-scale corpora.

Diagram
[ RENDERING DIAGRAM ]

The pair construction defines what similar means. A model trained on question and answer-passage pairs learns that a question belongs near the passage answering it, which is not the same as learning that two sentences mean the same thing. There is no universal semantic space, only the one an objective produced.

Negatives are the scarce resource. Both of those papers use in-batch negatives, treating every other item in the batch as a negative for free, so batch size sets how many negatives each example sees. OpenAI trained its smallest cpt-text model at a batch size of 12,288 (Neelakantan et al.), and E5 used 32,768, with consistent gains as batch size grew from 1K to 32K (Wang et al.). Mined hard negatives are the alternative. The E5 authors note they allow smaller batches but take non-trivial engineering on datasets above 100M pairs.

Dimensionality, cost, and Matryoshka truncation

Dimensionality is the main quality-versus-cost knob. Storage, memory, index build time, and query latency all scale with it: ten million vectors at 1,536 dimensions in float32 is roughly 61 GB before index overhead.

Matryoshka representation learning reshapes that trade-off. The model is trained so the first k dimensions are themselves a usable embedding, with information ordered coarse to fine. OpenAI's embeddings guide reports that a text-embedding-3-large embedding shortened to 256 dimensions still outperforms an unshortened 1,536-dimension text-embedding-ada-002 embedding, and exposes shortening as a dimensions parameter, so dimension count can be chosen at deployment time rather than at model selection time.

Truncation breaks unit length, so renormalize after slicing. OpenAI's guide gives the same instruction for vectors shortened by hand. A truncated vector left unnormalized misranks under dot product without raising an error.

Choosing an embedding model

Choose on criteria rather than leaderboard position.

CriterionQuestion to askWhy it decides the outcome
DimensionsFixed, or Matryoshka-truncatable?Sets storage and RAM cost for the life of the index
Max input tokensDoes a chunk fit without silent truncation?Sentence Transformers truncates over-length input instead of rejecting it
Open weights or APICan you self-host and pin a version?An API model can be retired on the provider's schedule; local weights stay available
Cost basisPer token, or per GPU hour?Price both for your backfill and your steady-state traffic
Language coverageWhich languages are in the training pairs?Check the model card before relying on cross-lingual retrieval
Query handlingPrefixes, instructions, or an input type parameter?The e5 model card warns of degraded performance without its prefixes
Domain fitAnything resembling your corpus in training?Test on your own domain before trusting general scores

Check max input length and query handling first, because both fail without an error.

Vectors from different models are not comparable

Each model defines its own coordinate system. The vec2vec authors put it plainly: different models encode texts into "completely different and incompatible vector spaces." Their research learns to translate embeddings between spaces through a shared latent representation, but that is a research result, not a production migration path, so reindexing remains the safe option.

Changing models therefore requires a full reindex: every stored vector must be regenerated. You can build the new index alongside the old one and cut over, but you cannot mix models inside one index. Use the provider's asynchronous batch endpoint to make the backfill affordable; OpenAI's Batch API costs 50% less than synchronous calls. The same rule covers model versions. Treat each version as a different model and never mix versions in one collection, because nothing raises an error when you do.

Similarity thresholds do not carry over either. Raw cosine scores are not calibrated across models. The e5 model card notes that its scores cluster between about 0.7 and 1.0 because of its low training temperature, so a 0.82 cutoff tuned on one model means something different on another. Recalibrate whenever the model changes, especially for cache hit decisions.

Version the model name into the collection or namespace. The rename forces the reindex to be explicit instead of accidental.

Using an asymmetric model symmetrically, or the reverse, is a bug that raises no error. The Sentence Transformers docs call this distinction critical to choosing a model.

Symmetric similarityAsymmetric retrieval
ComparesTwo items of the same kind and lengthA short query against a long passage
Typical taskDeduplication, paraphrase detection, cache lookupDocument search, RAG, FAQ matching
Training pairsParaphrase or entailment pairsQuestion and answer-passage pairs
Input handlingOne encoding path for both sidesDistinct query and document treatment
Typical symptom when confusedPassages retrieve passages, not answersNear-duplicates score lower than they should

Cohere's embed API makes the distinction explicit with input_type="search_query" versus input_type="search_document", and open models such as e5 require literal query: and passage: prefixes. Apply the mechanism at index time and query time both. The e5 card warns that leaving the prefixes off degrades performance.

Where embeddings fail

Dense vectors compress meaning, and compression discards exactly what some queries depend on:

  • Negation. "Contracts that do not include an arbitration clause" embeds close to its opposite. On the NevIR benchmark, most retrievers perform the same as or worse than random ranking on negation pairs, and bi-encoders come in last.
  • Precise identifiers. ORD-441902 and ORD-441903 are neighbors in vector space and different things in the world.
  • Rare proper nouns. An unfamiliar product name fragments into subwords and carries little signal.
  • Exact tokens generally. Error codes, SKUs, and API method names need exact matching, which a dense vector does not guarantee.

These failures are the case for hybrid search, since BM25 matches exact terms; vector databases cover the fusion and reranking mechanics. The BEIR benchmark authors found BM25 a robust zero-shot baseline that dense models often underperformed, and pointed to considerable room for improvement in dense models' generalization. E5 later reported being the first model to beat BM25 on BEIR zero-shot without labeled data.

Beyond text

CLIP trained an image encoder and a text encoder jointly on 400 million image and caption pairs, so an image and its description land in one space. The shared space enables text-to-image search and zero-shot classification with no labeled data. It still exists only between encoders trained together.

Running embeddings in production

Normalize once, at write time and query time, after which cosine, dot product, and Euclidean rank identically. Batch requests, since embedding is a single encoder forward pass with no sequential decode. Cache by content hash plus model identity, because the vector is only reusable with the model that produced it. And record dimension and model in metadata, because recovering a mixed collection is far harder than preventing one.

py

Embedding calls sit on the critical path of every retrieval and every cache lookup, so route them through the same gateway as chat traffic. Bifrost's semantic caching works this way. After an exact-match miss, Bifrost embeds the incoming request before it runs the similarity search, and the configured dimension must match the embedding model exactly, because a vector store namespace holds vectors of one dimension only. Enterprise scalability describes that dual-layer cache alongside Bifrost's other production features.

MTEB and what it omits

The Massive Text Embedding Benchmark spans 8 embedding tasks across 58 datasets and 112 languages, with a public leaderboard. MMTEB extends it to over 500 quality-controlled tasks across more than 250 languages.

Treat the scores with caution. The datasets are fixed and public, so a model can be tuned toward them in ways that do not carry over to your data. The average across task types hides the profile you care about. And no benchmark corpus resembles yours, so a small labeled set of real user queries beats any leaderboard.

Key takeaways

  • Matryoshka models let you truncate dimensions for cost, but you must renormalize after truncating.
  • Vectors from different models are not directly comparable, so changing models means a full reindex and recalibrated thresholds.
  • Match symmetric or asymmetric usage to the model, and apply required prefixes at both index and query time.

Sources and further reading