Book a 30-min callBook a call

Text embeddings explained: vectors, similarity, dimensions and quantization

How text embeddings work: contrastive training, cosine vs dot product, Matryoshka dimensions, token limits, int8 and binary quantization, and model choice.

Three text cards flowing through a model box into a field of dots, where two dots sit close together and a third sits far away.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
14 min read

Questions people ask

What is a good cosine similarity threshold?

There is no universal value. The spread of scores depends on the model, and one model's "unrelated" score can be another's "related". Label query and passage pairs from your own data, look at the scores of relevant and irrelevant pairs, and set the cutoff between them. A reranker's score is often a better place for a cutoff than raw cosine similarity.

Can I compare embeddings from two different models?

No. Each model defines its own vector space, so the similarity between a vector from one model and a vector from another means nothing, even when the dimensions match. Embed queries and documents with the same model and version.

How many dimensions do I need?

Start with the model's default and measure. If memory or speed matters, try shorter vectors from a Matryoshka-trained model, or int8 or binary storage with rescoring, and keep the smallest setting whose recall on your evaluation set stays close to the full vector.

Should I normalize embeddings before storing them?

Usually, yes, when the model is meant to be compared with cosine similarity: normalized vectors let the index use the cheaper dot product with the same ranking. Some providers already return unit-length vectors, as OpenAI says its embeddings are. Normalize again after shortening a vector yourself.

Building something like this?