LLMs as Embedding Models

A 7-billion-parameter decoder, fine-tuned for under 1,000 steps, beat every English embedder in early 2024: 66.6 on MTEB against 64.2. On Indic languages, a model 12.5 times smaller beats it by 10 points.

Pick where you test, from English to Indic. Watch the gap between the decoder and the best encoder change sign. Then we build, piece by piece, last-token pooling, instructions, synthetic data, the InfoNCE loss, LoRA, and the benchmark that found the flip.

You need a little Python and what a probability is. We build the rest from zero.

Session 2 of Georgia Tech CS 8803, LLM seminar. It rests on two papers: Wang, Yang, Huang, Yang, Majumder and Wei, Improving Text Embeddings with Large Language Models (ACL 2024, "E5-Mistral"), and Enevoldsen, Chung, Kerboua, Kardos and many co-authors, MMTEB: Massive Multilingual Text Embedding Benchmark (ICLR 2025). Every idea is re-taught here in our own words and devices.

Move the test away from English

The papers' numbers. English: E5-Mistral (7B) against BGE-large-en-v1.5 (335M), E5-Mistral Table 1. MIRACL: E5-Mistral against multilingual-e5-large, nDCG@10 averaged over en, fr, es, ru or te, hi, bn, sw, E5-Mistral Table 2. Europe, Multilingual, Indic: e5-mistral-7b-instruct against multilingual-e5-large-instruct (560M), average across all tasks, MMTEB Table 2.

Chapter 0

One Model, Two Jobs?

See why a retrieval system needs good vectors, and why the old way to make them ran out of data

You build a support assistant over 10,000 pages of documentation. A customer asks a question. First the system must find the three paragraphs that answer it. Then it must write a reply from them. This is retrieval-augmented generation (RAG).

The finding step uses text embeddings. An embedding is a fixed-length vector for a piece of text, made so that texts with close meanings get vectors that point the same way. You embed every paragraph once. At query time you embed the question and return the paragraphs with the highest cosine similarity, the cosine of the angle between two vectors. If cosine is new to you, Vector Embeddings and Similarity Metrics build it from zero.

How big is the index? Call the number of paragraph chunks N, the length of each vector d, and the bytes per number b.

Say it aloud

The index bytes equal N times d times b.

index bytes
index bytes the memory that holds every stored vector.
N
N the number of chunks: about 40,000 for 10,000 pages cut into paragraphs.
d
d numbers in one vector: 1,024 for BGE-large, 4,096 for E5-Mistral.
b
b bytes per number: 2 for a 16-bit float.
In plain words

Multiply the number of chunks N by the numbers per vector d. Multiply by the bytes b for each number.

With numbers

With made-up corpus numbers: N = 40,000, d = 4,096, b = 2 gives 327,680,000 bytes, about 328 MB. With d = 1,024 it is 82 MB. Both fit in a laptop's memory.

Size the index

Drag the corpus size and pick a vector length. The bar is the index; the grey mark is the 14 GB that a 7B model's weights take at 16 bits.

40,000

Arithmetic only. The 4,096 dimensions are from the E5-Mistral paper's Limitations; 7 billion parameters at 2 bytes is 14 GB.

Storing vectors is cheap. Making good ones is the hard part. Before 2024 the best embedders were small bidirectional encoders (BERT-style models where every token sees every other token). They trained in two stages: contrastive pretraining on billions of weakly related web pairs, then fine-tuning on labeled datasets.

The limit was data, not the model. Instructor trained on 330 datasets, all English. BGE focused on English and Chinese. Each new task or language needed someone to collect a labeled set first.

Failure. Your assistant works in English and returns poor paragraphs in Swahili. Measure: score retrieval separately per language. Fix: a model whose training data and pretraining cover that language. Chapters 7 to 9 show how large this gap gets.

  1. Pooling: read one vector out of a decoder. Why the last token.
  2. Instructions: tell the model the task, on the query side only.
  3. Synthetic data: let GPT-4 write the training pairs, in 93 languages.
  4. InfoNCE: the loss that pulls the right document close.
  5. LoRA: train 42 million of the 7 billion weights.
  6. No pretraining stage: why the decoder does not need it.
  7. English wins, then loses: the hero's first two stops and its fifth.
  8. MMTEB: build a benchmark for 250+ languages that people can afford to run.
  9. The leaderboard flip: the hero's last stops, with all 12 models.
  10. Field guide: numbers, code, limits, links and the credit.
What limited the pre-2024 encoder recipe for text embeddings?

Chapter 1

Causal Attention Meets Pooling

Collapse one vector per token into one vector per text, and see why a decoder must read the last token

A transformer gives one hidden vector per token. A retriever needs one vector per text. The step that collapses N token vectors into one is pooling.

For a bidirectional encoder, the usual choice is mean pooling: average the N vectors. That is fair there, because every position has read the whole text.

A decoder is different. It uses causal attention: the token at position i may look only at positions 0 to i. Its coverage, the share of the text it has read, is (i + 1) / N. Only the last position has read everything.

Count what each position has read

Left: the causal mask. A lit cell means the row's token may read the column's token. Right: each position's coverage. Drag the length, then switch the pooling.

8

Counting only, inside one attention layer. Deeper layers pass information forward, which is why the measured gap is small.

What does mean pooling average over, on the whole? Call the number of tokens N, and a position i, from 0 to N − 1.

Say it aloud

The average coverage equals one over N times the sum over i of i plus one over N, which equals N plus one, over two N.

average coverage
average coverage the mean share of the text that the averaged vectors have read.
(1/N) Σi
one over N times the sum over i add one term per position, i = 0 to N − 1, and divide by N.
(i + 1)/N
i plus one over N the coverage of position i: it has read i + 1 of the N tokens.
(N + 1)/(2N)
N plus one, over two N the closed form, because 1 + 2 + … + N = N(N + 1)/2.
In plain words

Give each position i its coverage (i + 1)/N. Average them over the N positions. The result is (N + 1)/(2N), which falls toward one half as N grows.

With numbers

N = 8: (8 + 1)/16 = 0.5625, so the mean averages vectors that saw 56% of the text. N = 32: 33/64 = 0.516. Last-token pooling reads one vector with coverage 1 at any N.

E5-Mistral appends an end-of-sequence token, [EOS], and takes its last-layer vector. This is last-token pooling. During pretraining this position summed up everything before it to predict the next token, so the skill is already there.

The paper tested the choice with everything else fixed (Table 5, MTEB average over 56 English datasets): last token 64.5, mean 64.1, weighted mean 64.0. The gap is small, because deep layers carry early tokens forward.

Failure. You pad a batch on the right, and the code takes hidden[:, -1]. Every short text gets the vector of a padding token. Training still runs, so nothing looks wrong. Measure: print the index of each row's real last token. Fix: pad on the left, or gather at mask.sum(1) - 1.

Why does a decoder embedder read the last token instead of averaging all tokens?

Chapter 2

Tell the Query What the Task Is

Put a one-sentence task description in front of the query, leave the documents alone, and measure what it buys

"Apple" should land near fruit for a recipe search and near phones for a tech search. One vector cannot serve both. E5-Mistral lets the caller say which task it is.

The model wraps every query in a template before it embeds it:

Instruct: {task_definition} Query: {query}

The task definition is one sentence, for example "Given a web search query, retrieve relevant passages that answer the query". For synthetic data the sentence comes from the brainstorm step of Chapter 3. For datasets such as MS-MARCO, the authors wrote one by hand.

Documents get no wrapper. So you embed the corpus once and keep it. A new task needs only a new sentence on the query side, not a new index.

Change how you talk to the model

Pick an instruction setting. The box shows the string the model reads; the bars show the seven MTEB categories against the default (outline).

E5-Mistral Table 5, trained on synthetic data plus MS-MARCO passages. The tag setting uses "classify: " for long-short tasks and "query: " for the other asymmetric tasks (Appendix A). The example query is ours.

Read the averages: a sentence gives 64.5, a tag 60.3, nothing 60.3. Deleting the sentence costs 4.2 points, which is (64.5 − 60.3)/64.5 = 6.5% of the score. Swapping Mistral-7B for LLaMA-2-7B costs only 1.6. The tag even helps retrieval a little (52.7 against 52.2) but loses classification, clustering and STS. A decoder reads sentences; a tag is a rare token with little meaning.

Failure. You serve a model trained with instructions but embed queries without them. Scores drop with no error message. Measure: embed a dev set both ways and compare recall. Fix: keep a table of one instruction per task and apply it at query time.

Why does E5-Mistral put the instruction on the query and never on the documents?

Chapter 3

Brainstorm, Then Generate

Let a strong LLM write the training pairs, and split the prompt in two so the data does not repeat itself

A training example for an embedder is a triple: a query, a positive document that answers it, and a hard negative, a document that looks relevant but is not. E5-Mistral asks GPT-4 to write these triples instead of collecting them.

Ask in one prompt, "write a query and a matching document", and the model repeats its most likely ideas. The paper tried this and found the diversity "not as satisfactory". So it splits the prompt in two:

  1. Brainstorm. "List about 20 distinct retrieval tasks." The output is plain task sentences, no examples.
  2. Generate. Give one task sentence and some random settings. Ask for one triple as JSON.
  3. Filter. Drop output that is not valid JSON. Drop exact duplicates.

Generate 60 examples

Each cell is one of 40 possible task types. A one-step generator keeps picking its favourites. A two-step generator samples from its brainstormed list. Press Generate and count the lit cells.

Toy sampler, ours: the one-prompt generator draws from a steep made-up preference; the two-step one draws a fresh list of 20 tasks, then picks from it. The paper reports only that one prompt gave less diverse data.

The random settings stretch each task further. The query length is one of "less than 5 words", "5 to 10 words" or "at least 10 words". The sampler draws the language from XLM-R's language list, weighted toward high-resource languages.

Tasks come in two families. Asymmetric tasks pair texts that relate but do not mean the same: short-long (web search), long-short (classification), short-short and long-long. Symmetric tasks pair texts with the same meaning: monolingual similarity (STS) and bitext, the same sentence in two languages. Symmetric tasks skip the brainstorm; the task is already clear.

QuantityValueWorked out
Examples500,000from 150,000 task sentences: 3.3 per sentence
Generator25% GPT-3.5-Turbo125,000 from GPT-3.5, the rest from GPT-4
Tokens usedabout 180Mabout 360 per example
Languages93English 43.1%; the bottom 75 about 1,000 each, 15% in total

Is it worth it? Train on MS-MARCO alone: 62.7. Add the synthetic data: 64.5 (Table 5). With synthetic data and no labeled data at all: 63.1 (Table 1).

Failure. Generated pairs pile up in the languages the sampler favours. Measure: count examples per language before training. Fix: reweight the language sampler, and expect the base model's own pretraining to limit what the fine-tune can add.

Why does the two-step prompt give more varied data than one prompt?

Chapter 4

InfoNCE: Pull the Answer Close

Score the right document against the wrong ones, and see how the temperature sharpens the contest

Training moves the query vector toward its positive and away from every negative. The loss treats retrieval as a multiple-choice test: pick the right document from all of them. Contrastive Learning covers the family.

First, a score for one query and one document. Call the query's embedding hq, the document's hd, and a small constant called the temperature τ.

Say it aloud

Phi of q and d equals e to the power of: the cosine of h-q and h-d, divided by tau.

φ(q, d)
phi of q and d the match score of query q and document d. Always positive.
exp
e to the power of turns any number into a positive one, and makes big gaps bigger.
cos(hq, hd)
the cosine of h-q and h-d how closely the two embeddings point the same way, from −1 to 1.
τ
tau the temperature: 0.02 in the paper. Dividing by it stretches small cosine gaps.
In plain words

Take the cosine of the two embeddings. Divide it by tau. Raise e to that power. The result phi is large when the two vectors agree.

With numbers

With made-up numbers: cosine 0.9 and tau 0.5 give exp(1.8) = 6.05. Cosine 0 gives exp(0) = 1.00. Cosine −0.5 gives exp(−1) = 0.37.

Call the positive document d+ and the set of negatives N, with one negative written n.

Say it aloud

L equals minus the log of: phi of q and d-plus, divided by phi of q and d-plus plus the sum over n in N of phi of q and n.

ℒ
L the InfoNCE loss for one query. 0 is perfect.
−log
minus the log of turns a probability near 1 into a loss near 0, and a probability near 0 into a large loss.
φ(q, d+)
phi of q and d-plus the score of the right document.
Σn∈N
the sum over n in N add one term for each negative: the other positives in the batch and one mined hard negative.
φ(q, n)
phi of q and n the score of one wrong document.
In plain words

Score the positive and every negative with phi. Divide the positive's score by the total. That share is the probability of picking the right document. The loss L is minus its log.

With numbers

With the scores above: 6.05 / (6.05 + 1.00 + 0.37) = 6.05 / 7.42 = 0.816, so L = −log 0.816 = 0.204. Drop the positive's cosine to 0.3: exp(0.6) = 1.82, the share is 1.82 / 3.19 = 0.571, and L = 0.560. A worse positive costs 2.7 times the loss.

Run the contest

The teal bar is the positive, the pink bar the hard negative, the grey bars easy negatives. Bar height is each document's share. Lower the temperature and watch a 0.02 cosine gap decide the contest.

0.80
0.78
0.50

Toy cosines, ours: one positive, one hard negative and six easy negatives at cosine 0.5. The real batch has 2,047 in-batch negatives and one hard negative per query; τ = 0.02 is the paper's.

In-batch negatives are free: in a batch of 2,048 pairs, every other pair's positive is a negative. Hard negatives are mined: where a dataset has none, the authors took non-answers from multilingual-e5-base's top 100.

Why τ = 0.02? Cosines lie between −1 and 1. Dividing by 0.02 turns a gap of 0.02 into a gap of 1 in the exponent. In the device at τ = 0.5, the positive ranks first but gets a share of only 0.40; at 0.02 it gets 0.73.

Failure. The loss stalls and retrieval stays mediocre. Measure: how many negatives score near the positive. Fix: add mined hard negatives, and check none is a true answer.

Why does E5-Mistral use a small temperature, τ = 0.02?

Chapter 5

LoRA: Train a Thin Slice of the Model

Freeze the 7 billion weights, train a small correction beside each matrix, and count the run's steps and GPUs

Training all 7 billion weights of Mistral-7B on 1.8 million pairs is costly. It also risks overwriting what pretraining built. LoRA (Low-Rank Adaptation) freezes every weight matrix and learns a small correction beside it. The full story is in LoRA and PEFT.

Call a frozen weight matrix W, with din inputs and dout outputs. LoRA adds two thin trainable matrices: A, with r rows, and B, with r columns. The small number r is the rank.

Say it aloud

W-prime equals W plus B times A. The trainable count is r times d-in plus d-out.

W′
W-prime the matrix the fine-tuned model uses.
W
W the frozen pretrained matrix, dout by din. It never changes.
B
B a trainable dout by r matrix.
A
A a trainable r by din matrix. B times A has the same shape as W but rank at most r.
r · (din + dout)
r times d-in plus d-out the numbers in A and B together: r is 16 in the paper.
In plain words

Keep W fixed. Train A and B. Add their product to W. The trainable count grows with the sum of the two sides, not their product.

With numbers

Mistral's query projection is 4,096 by 4,096: 16,777,216 frozen numbers. At r = 16, A and B hold 16 × (4,096 + 4,096) = 131,072, which is 0.8% of W.

Count the adapter

Each row is one of the seven linear layers in a Mistral-7B block, with its shape. The bar is its LoRA size. Change the rank and read the total over 32 blocks and the MTEB score.

Shapes from the public Mistral-7B-v0.1 config (hidden 4,096, MLP 14,336, key and value 1,024). Our count at r = 16 is 41.9M, matching the paper's 42M. MTEB averages: Table 5 (r = 64 was not run).

Sum the seven layers of one block: 16 × 81,920 = 1,310,720. Times 32 blocks: 41,943,040, the paper's 42M. Against about 7.2 billion weights that is 0.6%. Rank barely matters: r = 8 gives 64.8, r = 16 gives 64.5, r = 32 gives 64.6. The authors kept 16.

The run, from Appendix A: one epoch over about 1.8M examples, batch 2,048, so 1,800,000 / 2,048 = 879 steps, "fewer than 1k". Learning rate 10−4 with 100 warm-up steps, weight decay 0.1, sequences up to 512 tokens. It took about 18 hours on 32 V100 GPUs, 64 examples per GPU per step.

Failure. A GPU runs out of memory, even though only 42M weights train. The frozen 7B weights and the activations still have to live somewhere. Measure: memory per GPU at batch 64. Fix: what the paper used, gradient checkpointing, mixed precision and DeepSpeed ZeRO-3, which splits weights and optimizer state across the 32 GPUs.

At rank 16, how many trainable numbers does LoRA add to one 4,096 by 4,096 matrix?

Chapter 6

Does It Even Need to Learn?

Test the contrastive pretraining stage on an encoder and on a decoder, and see why only one of them needs it

Every strong embedder before this one had a middle stage: contrastive pretraining on billions of weak pairs, such as a page title with its body. E5 and BGE relied on it. Section 5.1 of the paper asks whether a decoder LLM still needs it.

The test: train two backbones on the same fine-tuning data, each with and without the extra stage. For Mistral, the stage followed the multilingual E5 recipe for 10,000 steps, about 11 times the 879 fine-tuning steps.

Switch the extra stage on and off

Pick a backbone. Solid bars are with contrastive pretraining; outlines are without. Read the gain above each pair.

E5-Mistral Table 7 and Figure 3, both backbones trained on the full data mix.

BackboneRetrievalMTEB average
XLM-R-large, without → with42.0 → 50.2 (+8.2)58.0 → 63.7 (+5.7)
Mistral-7B, without → with56.9 → 56.9 (+0.0)66.6 → 66.7 (+0.1)

Why the difference? Compare what each model practised. A masked language model such as XLM-R fills in a hidden word from the words around it. It never has to sum up a whole text, and never compares two texts. The extra stage teaches that.

A decoder predicts the next token, trillions of times. To do that well it must keep a running summary of what the text is about, at every position. That summary is what last-token pooling reads. So fine-tuning does not teach meaning. It reshapes a space that already holds meaning, so that cosine distance tracks relevance. That is a small job, which is why 0.6% of the weights and 879 steps suffice.

The paper's words: generative language modeling and text embeddings are "two sides of the same coin".

Failure. You copy the encoder recipe to a decoder and spend weeks on a pretraining stage. Measure: run a small ablation first, with and without the stage, on the same fine-tuning data. Fix: drop the stage if the gain is under noise.

Why does contrastive pretraining add 8.2 retrieval points to XLM-R-large and nothing to Mistral-7B?

Chapter 7

English Wins, Then Loses

Read the English leaderboard, then split the multilingual results by language and watch the lead turn into a deficit

On MTEB, 56 English datasets in seven task categories, E5-Mistral with the full data scored 66.6. The best earlier model, BGE-large-en-v1.5, scored 64.2 (Table 1). The full data is the synthetic set plus 13 public datasets.

Model or settingMTEB averageNote
BGE-large-en-v1.564.2best earlier model, about 335M parameters
E5-Mistral, synthetic only63.1no labeled data at all
E5-Mistral, synthetic + MS-MARCO64.5+1.4 from one labeled set
E5-Mistral, full data66.6+2.1 more from 12 further sets

On BEIR, the 15 retrieval datasets inside MTEB, it scored 56.9 against 55.6 for the best commercial model listed, voyage-lite-01-instruct (Table 3). That is (56.9 − 55.6)/55.6 = 2.3% better. A real win, but a narrow one. The table changed between versions: version 1 compared against OpenAI Ada-002, and version 3 against text-embedding-3-large (55.4).

Now leave English. MIRACL is a retrieval benchmark where native speakers wrote queries and judged answers in 18 languages. Its score, nDCG@10, rewards putting the right passages near the top of the first ten; Embedding Benchmarks derives it by hand.

Split the score by language

Each pair is one language: teal is E5-Mistral, blue is multilingual-e5-large, an XLM-R encoder. Switch between the languages and the two group averages.

E5-Mistral Table 2, nDCG@10 on the MIRACL dev set. The authors picked the four languages with the most and the fewest candidate documents.

Average the four high-resource languages (en, fr, es, ru): E5-Mistral (57.3 + 55.2 + 52.2 + 67.7)/4 = 58.1, multilingual-e5-large 56.9. A lead of 1.2. Average the four low-resource languages (te, hi, bn, sw): 66.2 against 74.4. A deficit of 8.2. Inside the small group, E5-Mistral spans 52.1 on Hindi to 73.9 on Telugu.

The paper names the cause: Mistral-7B "is predominantly pre-trained on English data". Its own bitext results say the same: it "excels in bitext mining for high-resource languages only". XLM-R, under multilingual-e5, was pretrained on 100 languages. Touching 93 languages in a fine-tune does not undo pretraining on mostly English.

Failure. You pick the model with the best average and your Hindi users get the worst results. Measure: report per-language scores, not one average. Fix: choose on the languages you serve.

E5-Mistral leads multilingual-e5-large by 1.2 on four high-resource MIRACL languages and trails by 8.2 on four low-resource ones. What best explains it?

Chapter 8

A Benchmark Beyond English

Gather 500+ tasks, cut them to the ones that add new information, and make the whole thing cheap enough to run

An MTEB score is a claim about English. MMTEB is the multilingual answer: over 500 tasks in 10 task categories and 250+ languages, built by an open collaboration on GitHub. New task types include instruction-following retrieval, long-document retrieval and code retrieval.

Every task passed a gate: two small models, multilingual-e5-small and MiniLM-L12, ran on it. A score within 2% of random, a near-perfect score, or two near-equal scores sent it to a reviewer.

From the pool the authors built smaller benchmarks (Table 1). They picked a scope, removed machine-translated or badly licensed sets, then dropped tasks that add little information.

BenchmarkScopeRefinedSelected
MTEB(Multilingual)500+343132
MTEB(Europe)42022874
MTEB(Indic)554423
MTEB(eng, v2), zero-shot565441

The last step is backward selection. Predict each task's scores from the other tasks with a linear regression. Remove the easiest one to predict. Stop when the best prediction's rank agreement falls below 0.8 (0.9 for eng v2). Never remove a language's last task in a category.

The ruler for "do two rankings agree" is Spearman's rank correlation. Call the number of models n, and for model i the difference between its two ranks di.

Say it aloud

Rho equals one minus six times the sum over i of d-i squared, divided by n times n squared minus one.

ρ
rho rank agreement: 1 for the same order, 0 for no relation, −1 for the reverse.
6 Σi
six times the sum over i add one term per model; the 6 makes a full reversal come out at −1.
di2
d-i squared how far model i moved between the two rankings, squared.
n(n2 − 1)
n times n squared minus one scales the sum by the number of models n.
In plain words

Rank the models twice, once on the full test and once on the cheap one. For each model, square the change in rank d-i. Add the squares, multiply by 6, divide by n(n² − 1), and take the result from 1.

With numbers

With made-up ranks: four models, ranked 1, 2, 3, 4 on the full test and 1, 3, 2, 4 on the cheap one. The d-i are 0, 1, 1, 0, so the sum of squares is 2. ρ = 1 − 12/60 = 0.8. One swap in the middle costs 0.2.

Cost was the other problem. MTEB(eng, v1) takes up to two days on one A100 for a mid-sized LLM; the E5-Mistral authors report three days on 8 V100s. So MMTEB cut the documents to embed, and checked each cut with Spearman.

Cut the evaluation bill

Pick a cut. The bars compare the work before and after, on a log scale. The read-out says what was checked.

MMTEB Sections 2.3 and 4. Clustering is drawn as relative work (1 before, 1/16.11 after), since the paper reports a speed-up.

CutHowResult
Clusteringencode a 4% subsample once, draw 10 sets from it16.11× faster on average, Spearman 0.96
Retrievalkeep the top 250 documents per query from BM25, multilingual-e5-large and e5-mistral; at most 1,000 querieslargest sets from over 5 million documents to at most 250,000
Bitextcache each sentence's embedding across language pairsFlores English side: 410,000 to 1,012 embeddings
eng v2all of the above, plus task selection, zero-shot2% of the documents; 3.11 h for GritLM-7B on one H100; Spearman 0.90 with v1

MTEB(eng, v2) drops MS-MARCO and Natural Questions, because many models, E5-Mistral included, train on them. The small English models trained on both score lower on v2.

Failure. A cheap test ranks models in a new order. Measure: Spearman between cheap and full rankings on reference models. Fix: keep the cut only if the order holds.

What tells MMTEB that a cost cut is safe to keep?

Chapter 9

The Leaderboard Flip

Rank 12 models on three benchmarks and watch the 7B decoders fall from the top to sixth

MMTEB ranks models with a Borda count, a voting rule. Each task is a voter that ranks every model. A model gets points on each task for the models it beats. Points add up over tasks. One task with an odd score scale then cannot swing the result, as it could swing a plain average.

Call the number of models M, a task t, and model m's place on task t rankt(m).

Say it aloud

Borda of m equals the sum over t of M minus rank-t of m.

Borda(m)
Borda of m model m's total points. The highest total ranks first.
Σt
the sum over t add one term per task: 132 tasks in MTEB(Multilingual).
M
M the number of models compared: 12 in MMTEB's Table 2.
rankt(m)
rank-t of m model m's place on task t: 1 is best.
In plain words

On each task t, give model m one point for every model ranked below it, which is M minus its rank. Add the points over all tasks.

With numbers

With made-up ranks: M = 3 models and two tasks. X is first then third: 2 + 0 = 2. Y is second then first: 1 + 2 = 3. Z is third then second: 0 + 1 = 1. Y wins, though X won a task. The paper breaks ties with the tournament Borda method.

Watch the order change

Teal: Mistral-7B decoders. Blue: XLM-R multilingual-e5 encoders. Grey: other encoders, dim grey for English-only models. Pick a benchmark, then switch the order between Borda rank and average score.

MMTEB Table 2: Borda rank, Borda points and average across all tasks.

Benchmarkmultilingual-e5-large-instruct (560M)GritLM-7Be5-mistral-7b-instruct
Multilingual, 132 tasks1st, 63.22nd, 60.93rd, 60.3
Europe, 74 tasks2nd, 62.21st, 63.03rd, 61.7
Indic, 23 tasks1st, 70.25th, 60.26th, 60.0

On Indic, all four multilingual-e5 models, even the small one, rank above both 7B decoders. The paper finds the decoders' rank "steadily decreases and becomes more volatile" as a language's native speakers drop, most clearly below about 300 million speakers.

One choice does carry across languages: instruction tuning. multilingual-e5-large-instruct beats multilingual-e5-large by 4.6 on Multilingual, 3.7 on Europe and 3.8 on Indic. GritLM keeps one real edge, the best retrieval score on MTEB(Multilingual), helped by its longer maximum input.

Order Indic by average and two rows swap: multilingual-e5-small (64.7) edges past multilingual-e5-base (64.6), and LaBSE (61.9) passes both decoders. Borda counts wins per task; the average counts margins.

Most of your users write in Indic languages. Which model do these numbers support?

Chapter 10

Field Guide

Keep the terms, the numbers, the code and the limits in one place

A decoder LLM becomes a strong embedder with four parts: last-token pooling, a task instruction on the query, GPT-4-written training triples, and an InfoNCE fine-tune of 0.6% of the weights. It works because next-token pretraining already built the meaning. That recipe won English in early 2024. MMTEB showed the win does not carry to languages the base model rarely saw.

TermMeaningNumber to remember
Last-token poolingthe [EOS] vector is the embedding64.5 vs 64.1 for mean pooling
Mean-pool coverageaverage share of text the averaged vectors read(N + 1)/(2N): 0.5625 at N = 8
Instructionone task sentence before the query onlyremoving it: 64.5 to 60.3
Synthetic dataGPT-4 and GPT-3.5 triples, two-step prompts500k examples, 150k tasks, 93 languages
InfoNCEcross-entropy over the positive and the negativesτ = 0.02, batch 2,048, 1 hard negative
LoRAfrozen W plus a trained rank-r B Ar = 16: 42M trainable, 0.6%
Training runone epoch over the mix879 steps, about 18 h on 32 V100s
Contrastive pretrainingextra stage on weak pairsXLM-R +8.2 retrieval; Mistral +0.0
MIRACL splitE5-Mistral vs multilingual-e5-large+1.2 high-resource, −8.2 low-resource
MMTEBcommunity benchmark, Borda ranking500+ tasks, 250+ languages; Indic: 560M model 1st, 7B decoders 5th and 6th

Checklist

  1. Pad on the left, or gather the last real token. Print its index for a mixed-length batch.
  2. Keep one instruction sentence per task. Never instruct the documents.
  3. Mine hard negatives, and spot-check that none is a true answer.
  4. Run the cheap ablations first: pooling, rank, instruction. Spend on data and instructions.
  5. Report scores per language and per task category, not one average.
  6. Pick a benchmark whose languages match your users, and build a small test set of your own.
  7. Check whether a model trained on the benchmark's training sets; prefer zero-shot tests such as MTEB(eng, v2).
pythonimport torch, torch.nn.functional as F

def last_token_pool(hidden, mask):           # hidden: (B, L, 4096), mask: (B, L)
    if mask[:, -1].all():                       # left-padded: last column is real
        return hidden[:, -1]
    last = mask.sum(1) - 1                         # right-padded: index of each real [EOS]
    return hidden[torch.arange(hidden.shape[0]), last]   # (B, 4096)

def with_instruction(task, query):            # queries only; documents stay as they are
    return f"Instruct: {task}\nQuery: {query}"

def info_nce(q, pos, hard, tau=0.02):          # q, pos, hard: (B, d)
    q, pos, hard = (F.normalize(x, dim=-1) for x in (q, pos, hard))
    logits = torch.cat([q @ pos.T, q @ hard.T], dim=1) / tau   # (B, 2B): in-batch + hard
    labels = torch.arange(q.shape[0])           # row i's positive is column i
    return F.cross_entropy(logits, labels)

What the papers leave open

E5-Mistral: 4,096-dimensional vectors cost more to store, and a 7B model costs more to run than a BERT-size one. Long inputs: the passkey test scores 100% up to 4k tokens with the default 4k sliding window, then drops. A 32k window alone is worse. With the RoPE base raised to 105, it passes 90% at 32k, with a small loss on short inputs. The contamination check string-matched the training data against MTEB and found only 4 DBPedia questions that also appear in TriviaQA. It cannot check GPT-4's or Mistral's pretraining data, which is not public.

MMTEB lists three limits. Human-translated tasks, such as SIB200ClusteringS2S, carry English labels and may favour English-leaning models. Every dataset earned the same credit points whatever the effort. English still appears in 290 tasks, and low-resource languages sit mostly in bitext mining and classification.

Keep going

Credit: Session 2 of Georgia Tech CS 8803, LLM seminar. Papers: Improving Text Embeddings with Large Language Models (Wang et al., ACL 2024, arXiv 2401.00368, version 3) and MMTEB: Massive Multilingual Text Embedding Benchmark (Enevoldsen et al., ICLR 2025, arXiv 2502.13595, version 4). The toy samplers and all made-up numbers are ours.

The takeaway. Next-token pretraining already builds the meaning an embedder needs; a light fine-tune only points it at cosine. The languages the base model read decide where that works.

Teach it back: open Present or Teach and explain last-token pooling and the leaderboard flip to a friend. Then go back to the benchmark dial and predict the sign of the gap before you press each stop.

CS 8803 LLM Seminar, Session 02: LLMs as Embedding Models
E5-Mistral paper · MMTEB paper · Back to Gleams