Guide

Raw inputs, such as token IDs, pixels and user IDs, are poor for similarity or prediction until you map them into a space where distance reflects meaning. Representation learning is the art of learning that map. Its outputs are embeddings, and they underpin search, recommendations, RAG and multimodal models.

This section is the ML view: how embeddings are trained. For the productized side of vector search, see AI embeddings.

Concepts in this section

Read them in order. Each step builds on the one before.

StepConceptWhat it answers
1Embedding lookup tablesHow does an ID become a learned vector?
2word2vecHow do you learn word vectors from context?
3Contrastive learning and InfoNCEHow do positives and negatives shape the geometry?
4Bi-encoders and cross-encodersHow do you search fast and then rerank accurately?
5CLIP and zero-shot classificationHow do images and text share one space?

Common mistakes

  • Trusting nearest-neighbor demos. A few hand-picked neighbors look right, and measured retrieval can still be poor. Measure recall at k, MRR or nDCG on labeled queries held out by time or product.
  • Mixing vectors from two model versions. An index built from model A and queried with model B returns noise. Version the index with the model.
  • Ignoring freshness. If documents change hourly but you re-embed weekly, recall drops, and it looks like a model problem.
  • Assuming embeddings replace keyword search. Exact tokens such as product codes or names are often better served by lexical search. Hybrid retrieval combines BM25 for exact matches with embeddings for paraphrase, then fuses the scores or uses reciprocal rank fusion before a cross-encoder rerank. Log which source won each candidate, so you know where to invest.
FailureSymptomMitigation
False negatives in batchPopular documents hurtDe-duplicate the batch, use a memory bank, mine negatives carefully
Train and serve tokenizer skewSudden recall dropFreeze the tokenizer and add integration tests
Mixed model versions in one indexGarbage neighborsAlias indexes by model ID
Shortcut learningEmbeddings encode only length or languageHard negatives and balanced data
Polysemy in static vectorsOne vector per wordUse contextual encoders

Key takeaways

  • An embedding layer is a learned lookup. The geometry comes from the loss.
  • word2vec learned vectors from context. Contextual transformer encoders replaced one-vector-per-word.
  • Contrastive training needs positives, negatives and a temperature. InfoNCE is the common loss.
  • Bi-encoders retrieve quickly. Cross-encoders rerank a short list accurately.
  • CLIP aligns images and text, which enables zero-shot classification.
  • Normalize vectors if you use cosine, version the embedding space, and evaluate with recall and nDCG.

Further learning

Efficient Estimation of Word Representations in Vector Space (word2vec)We propose two novel model architectures for computing continuous vector representations of words from very large data sets. The quality of these representations is measured in a word similarity task, and the results …arXiv.org Learning Transferable Visual Models From Natural Language Supervision (CLIP)State-of-the-art computer vision systems are trained to predict a fixed set of predetermined object categories. This restricted form of supervision limits their generality and usability since additional labeled data i…arXiv.org Sentence-BERTBERT (Devlin et al., 2018) and RoBERTa (Liu et al., 2019) has set a new state-of-the-art performance on sentence-pair regression tasks like semantic textual similarity (STS). However, it requires that both sentences a…arXiv.org Matryoshka Representation LearningLearned representations are a central component in modern ML systems, serving a multitude of downstream tasks. When training such representations, it is often the case that computational and statistical constraints fo…arXiv.org