Courses / RAG Systems / Module 4
Module 4: Choosing embedding models: benchmarks, multilingual and Indic, fine-tuning embeddings
10 h · theory 3 · hands-on 4 · project 2 · revision 1
You will be able to
- Read MTEB results critically for your domain
- Compare open and hosted embedding models on your golden set
- Handle Hindi and other Indian languages
- Fine-tune an embedding model on in-domain pairs
Capstone increment: Embedding model chosen by measured recall, with a fine-tuned variant behind a flag.
Job-description skills: Embedding models · Lab tools: sentence-transformers, FlagEmbedding
1. What an embedding model learns
A retrieval embedding model is a bi-encoder: it maps the query and each passage to vectors separately, trained with contrastive learning so that a query lands near the passages that answer it and away from those that don’t. Because passages are encoded independently, you can embed millions in advance and compare with fast vector search.
Details matter in practice. Many models expect prefixes or instructions (E5 uses “query: ” and “passage: ”; some BGE versions use an instruction for queries). Use the similarity the model was trained with, usually cosine on normalised vectors. Check the maximum input length, the dimension and the licence before anything else.
2. Read MTEB critically
The Massive Text Embedding Benchmark (MTEB) and its multilingual extension rank models across many tasks. For RAG, look at the retrieval tasks, not the overall average, and prefer tasks that resemble your domain. Leaderboard positions shift often, some models have seen benchmark-like data in training, and small score gaps rarely survive on your own documents.
Use MTEB to build a shortlist of three to five models that meet your constraints (licence, size, languages, maximum length, hosted or self-hosted), then decide on your golden set. Record recall@10 and nDCG@10 for each, along with latency and cost per million tokens.
3. Hindi and other Indian languages
If your users write in Hindi, Tamil, Bengali or Hinglish, evaluate per language. Multilingual models such as BGE-M3 and multilingual-e5 map many languages into one space so a Hindi question can retrieve an English passage, but quality varies a lot by language and by script. Romanised Hindi (“chutti kitne din milti hai”) and code-mixed text are harder still.
Build a golden set for each language your users actually use, including transliterated queries. Options when one language lags: translate queries to the corpus language (IndicTrans2 from AI4Bharat is a strong open model), index translated copies of key documents, or fine-tune on in-language pairs. Indic scripts also take more tokens per word with many tokenizers, which raises embedding and generation cost.
4. Fine-tune when the gap is real
Fine-tune an embedding model when your domain has vocabulary the base model doesn’t understand (product codes, legal terms, internal acronyms) and the best off-the-shelf model still misses your bar. You need query–passage pairs: mine them from search logs and click data, or generate synthetic questions for each chunk with an LLM and filter them.
Train with in-batch negatives (MultipleNegativesRankingLoss in sentence-transformers) and add hard negatives: passages that look relevant but aren’t, often mined with the base model itself. Evaluate on held-out questions that were never used to generate training pairs. Expect real gains on narrow domains; expect little on general text.
Deep dive
Deep dive: hard negatives and the training loss
When you fine-tune an embedding model on your own (question, passage) pairs, the loss most libraries use is MultipleNegativesRankingLoss: InfoNCE with in-batch negatives, where every other passage in the batch counts as wrong. It is cheap, but random negatives are easy, so the model can reach a low loss and still confuse look-alike passages.
Hard-negative mining fixes this. For each training question, retrieve the top results with the current model, drop the true passage (and anything labelled relevant), and add one or two of the remaining high-ranked passages as explicit negatives. Watch for false negatives: a mined “negative” that actually answers the question teaches the model the wrong thing, so filter mined negatives with a cross-encoder score or a margin.
- Collect 1,000–10,000 real (question, passage) pairs from logs, or generate questions for each chunk with an LLM and spot-check them.
- Hold out 10–20% as a retrieval eval set before you train anything.
- Mine hard negatives with the base model: results ranked 5–30 that aren’t labelled relevant.
- Train on (question, positive, hard negative) triplets with MultipleNegativesRankingLoss, with large batches (more in-batch negatives), for 1–3 epochs.
- Compare recall@10 and nDCG@10 with the base model on the held-out set, and keep the fine-tuned model only if the gain is real.
Loss on training batches 0.001 · loss over all passages 0.549 · questions answered with the right passage 3 / 5
| Question | Top passage | Margin over its look-alike |
|---|---|---|
| refund for my laptop | Laptops can be refunded within 14 days ✓ | 0.05 vs “Clothing refunds: 30 d…” |
| refund for a shirt | Laptops can be refunded within 14 days ✗ | -0.03 vs “Laptops can be refunde…” |
| laptop delivery is late | Clothing orders delayed: what to do ✗ | -0.00 vs “Clothing orders delaye…” |
| shirt hasn’t arrived yet | Clothing orders delayed: what to do ✓ | 0.01 vs “Late laptop deliveries…” |
| reset my password | Reset your account password ✓ | no look-alike |
Similarity grid (rows are questions, columns are passages; darker is more similar):
Guided experiments
- Random negatives, 100 steps. The training loss is almost zero, so training “worked”. How many questions get the right passage, and what are the margins? Why can a model ace its training batches and still confuse laptops with shirts?
- Switch to random + hard negatives and replay from 0 to 100 steps. Which column of the grid separates? This is why embedding fine-tuning recipes mine hard negatives (look-alike passages that are wrong).
- With hard negatives, try τ = 1. The loss stays high: the softmax is too soft to push the look-alikes apart. Compare τ = 0.05 and 0.1. Most models train with τ around 0.01–0.1.
- Your own domain will have look-alikes too (two product variants, two policy versions). How would you find hard negatives for them automatically? (Hint: retrieve with the current model and keep the high-ranked wrong passages.)
5. Dimensions, cost and changing models
Storage is chunks × dimensions × bytes per value, plus index overhead. Two million chunks at 1,024 float32 dimensions is about 8 GB of raw vectors before the HNSW graph. Quantization (Module 5) and Matryoshka truncation reduce this; hosted APIs charge per token embedded.
Changing the embedding model means re-embedding every chunk, because vectors from different models don’t share a space. Store the model name and version with the index, build the new index alongside the old one, compare on the golden set, then switch with an alias (Module 16).
Deep dive
Deep dive: Matryoshka dimensions and quantized vectors
Matryoshka models are trained with the loss applied at several prefix lengths at once, so the first 64, 128, 256 … dimensions are each a usable embedding. You can store shorter vectors and lose a little quality instead of all of it.
Quantizing vectors is a separate choice from truncating them. Int8 (scalar) quantization keeps every dimension at lower precision; binary quantization keeps only the sign of each dimension. Both usually need a re-scoring step with fuller vectors to recover quality.
Worked example: storage for 1 million chunks
1,024 dims × 4 bytes (float32) = 4.1 GB Matryoshka, truncated to 256 dims = 1.0 GB int8, all 1,024 dims (1 byte each) = 1.0 GB binary, 1,024 bits = 128 bytes per vector = 0.13 GB (32× smaller) common recipe: search the binary vectors for the top 100, re-score them with int8 or float32
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 4.1: Model shoot-out
Score three embedding models (for example bge-small-en-v1.5, multilingual-e5-base and one hosted API model) on the capstone golden set, plus a 15-question Hindi or Hinglish set.
Expected: A table of recall@10, nDCG@10, latency and cost per model and language.
Lab 4.2: Fine-tune with hard negatives
Generate 1,000 synthetic question–chunk pairs with an LLM, mine one hard negative per pair with the base model, and fine-tune bge-small with sentence-transformers on a free Colab GPU.
Expected: Held-out recall@10 before and after, and the training time.
Lab 4.3: Model behind a flag (capstone increment)
Make the embedding model a config value stored with the index metadata, index with your chosen model, and add the fine-tuned model behind a flag with its own index.
Expected: Switching the flag queries the other index; docs/adr/0003-embeddings.md records the numbers.
Go deeper
Videos
- Stop Picking Embedding Models Off The MTEB Leaderboard · Hamel Husain · ~22 min. Why leaderboard rank misleads and how to evaluate embedding models on your own data.
- Improving RAG Retrieval by 60% with Fine-Tuned Embeddings · Adam Lucek · ~30 min. A complete fine-tuning run with synthetic data and evaluation, start to finish.
- Fine-tuning an embedding model: sentence transformers getting emotional · Qdrant Vector Search · ~44 min. Fine-tuning with sentence-transformers explained by Qdrant, including how to build training pairs.
- SimCSE: Simple Contrastive Learning of Sentence Embeddings - EMNLP 2021 · Princeton NLP · ~12 min. How contrastive training with hard negatives shapes an embedding space, from the SimCSE authors.
Further reading
- Docs Training overview · Sentence Transformers docs. How to fine-tune an embedding model: datasets, losses (including MultipleNegativesRankingLoss) and evaluators.
- Paper MTEB: Massive Text Embedding Benchmark · Muennighoff et al., 2022. What the leaderboard actually measures, task by task, so you can read it critically.
- Paper MMTEB: Massive Multilingual Text Embedding Benchmark · Enevoldsen et al., 2025. The multilingual extension of MTEB, with Indic languages; read before trusting an English leaderboard.
- Paper Matryoshka Representation Learning · Kusupati et al., NeurIPS 2022. How models are trained so that the first 64, 128 or 256 dimensions are usable on their own.
- Paper L3Cube-IndicSBERT · Deode et al., 2023. Cross-lingual sentence embeddings for 10 Indian languages, and how they were trained.
- Paper SimCSE: Simple Contrastive Learning of Sentence Embeddings · Gao, Yao and Chen, 2021. Contrastive training with in-batch negatives, explained cleanly, with the effect of hard negatives measured.
GitHub repositories
- embeddings-benchmark/mteb: How retrieval tasks are defined; run one MTEB retrieval task on a model you are considering.
- huggingface/sentence-transformers: examples/sentence_transformer/training: MultipleNegativesRankingLoss, hard-negative mining and Matryoshka loss.
- FlagOpen/FlagEmbedding: BGE-M3: dense, sparse and multi-vector outputs from one multilingual model, and its fine-tuning scripts.
- AI4Bharat/IndicTrans2: Translation between English and 22 Indian languages, useful for query translation when a language lags.
Checkpoint quiz
Interview questions
- How do you choose an embedding model for a new RAG system?
- How would you support Hindi and Hinglish queries over English documents?
- When is fine-tuning an embedding model worth it, and how do you build the data?
- How do you migrate a production index to a new embedding model with no downtime?
- What is Matryoshka representation learning and when would you use it?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).