LearnQuestion bank

How are text-embedding models trained, and which decisions matter when you use them for search — similarity metric, normalisation, dimensionality, domain shift and multilingual content?

Applied LLMTechnicalEasy

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Contrastive training on query–passage pairs with in-batch and hard negatives (InfoNCE-style loss); pooled encoder or LLM-based embedders
  • Use the metric the model was trained with; cosine = dot product for normalised vectors; apply required query/document prefixes or instructions
  • Dimensionality vs storage and latency; Matryoshka truncation; int8/binary quantisation with full-precision rescoring
  • Domain shift: measure recall@k on real queries, not leaderboards; fine-tune with synthetic queries if needed
  • Multilingual: multilingual model, per-language and cross-lingual recall, consistent normalisation, language-aware keyword analysers
  • Changing the model means re-indexing everything; never mix model versions in one index; version vectors with the index

In full

Most text-embedding models are trained contrastively: a query is paired with its relevant passage and the two are pulled together, while the other passages in the batch (in-batch negatives) and mined hard negatives are pushed apart, using an InfoNCE-style loss that treats the positive as the correct match among the candidates. The encoder can be a pooled transformer (mean or CLS pooling over a BERT-like backbone) or an LLM-based embedder; either way the objective is the same contrastive one.

When using a model for search, I follow the similarity metric it was trained with. Cosine and dot product give the same ranking once vectors are L2-normalised, so for a model trained with cosine I normalise at write and query time; a model trained with an unnormalised dot product should not be silently normalised. I also apply any required query/document prefixes or task instructions exactly as the model card specifies, because omitting them measurably lowers recall.

Dimensionality trades quality against storage and latency. Matryoshka-trained models can be truncated to fewer dimensions with modest loss, and int8 or binary quantisation shrinks the index further, with a rescoring pass over a shortlist using the full-precision vectors to recover most of the accuracy.

Domain shift is the biggest practical risk, so I measure recall@k on real production queries before rollout rather than choosing from a public leaderboard, and fine-tune with synthetic queries generated from our own documents if the gap is large. For multilingual content I use a model trained on multilingual and cross-lingual pairs, evaluate recall per language and for cross-lingual queries (a question in one language, the answer in another), and keep text normalisation consistent across languages; a keyword index alongside it needs language-specific analysers.

Finally, vectors from different models or versions are not comparable, so changing the embedding model means re-indexing everything. I version the vectors and the index together and keep the old index serving until the new one is validated.

Corrected by an independent AI reviewer.

What a strong answer covers

  • Contrastive training on query–passage pairs with in-batch and hard negatives (InfoNCE-style loss); pooled encoder or LLM-based embedders
  • Cosine and dot product coincide for normalised vectors; follow what the model was trained with; some models need query/document prefixes or instructions
  • Dimensionality vs storage and latency; Matryoshka truncation; int8/binary quantisation with rescoring
  • Domain shift: evaluate recall@k on real queries; fine-tune with synthetic queries if needed
  • Changing the embedding model means re-indexing everything; version the vectors

Common mistakes

  • Mixing vectors from different models/versions in one index
  • choosing a model purely from a public leaderboard