Embedding models: training, choosing and fine-tuning

How a text becomes one vector, how contrastive training shapes the space, what prompts, truncation and quantisation do, why the MTEB rank does not carry over to your data, and how to choose and fine-tune a model on a few hundred labelled queries. Measured on the topic's SciFact and NFCorpus running example on an Apple M1 Pro; published numbers kept apart. A child of Topic: rag-and-retrieval. Data as of October 2026. Reading: 30 min, plus 12 in closed details.

The idea in one screen

An embedding model is a transformer plus a pooling step that maps any text to one vector of fixed length, trained with a contrastive loss so that a query and the passage that answers it point the same way; which model works for you is decided on your own labelled queries with paired statistics, not by a leaderboard.

Fig. 1 follows one real pair through bge-small: the shortest SciFact test claim and its labelled abstract. The section that owns each part is named in its step.

  1. The query, per search. The claim "CCL19 is absent within dLNs." plus bge-small's query prefix (§6) is 19 tokens. One transformer reads them; pooling (§1) and normalisation (§2) turn its 19 token vectors into one vector of 384 numbers (the first 16 drawn, real values).
  2. The document, once at indexing. Its labelled abstract (275 tokens) goes through the same weights: one glass plate spans both lanes. A model reads at most its maximum length and drops the rest silently (§8); the stored vector can be cut or quantised to save memory (§7).
  3. They meet only at the cosine. cos(q, d) = q · d = 0.633 for this pair. Training (§3 to §5) is what makes a query and the passage that answers it point the same way.
  4. Search is one query against every stored vector. Encoding the query takes 10.0 ms here; 5,183 exact dot products take 0.5 ms; the top k go on to a reranker. Which model puts the right abstract first on your queries is decided on your own labelled set (§9 to §11).

You need: InfoNCE as a softmax over a line-up of candidates (Contrastive and self-supervised learning, section "InfoNCE, the workhorse loss"), nDCG@10 and bootstrap intervals (Evaluation metrics), and the parent Topic: rag-and-retrieval for where retrieval sits in a pipeline. The running example: SciFact (5,183 scientific abstracts and 300 test claims) and NFCorpus (3,633 medical documents and 323 test queries).

Bi-encoder
query and document encoded separately by one model, compared by one dot product; this page's subject.
Pooling
collapsing the per-token outputs into one vector: the first token (CLS), the mean, or the last token.
In-batch negative
another query's positive in the same training batch, used as a free wrong answer.
Hard, false negative
a mined wrong answer that looks right; one that is in fact relevant but unlabelled.
Temperature τ
divides the cosines before the softmax; 0.05 by default in sentence-transformers.
Asymmetric prompt
a prefix or instruction added to the query side only (or a different one per side).
Matryoshka
training so that the first m numbers of the vector are a usable embedding on their own.
MTEB
the Massive Text Embedding Benchmark: one protocol, many tasks, a leaderboard by the mean.
Paired bootstrap
resampling the same queries for two models to get an interval for their difference.
How to read the numbers
measured here: run on an Apple M1 Pro (16 GB, shared with other jobs) on the running example with a script in this page's src/scripts; relevance numbers (nDCG@10, recall) are deterministic and do not depend on the machine. published: a paper, model card or results repository, with its date. derived: computed from numbers shown, with the formula. nDCG@10 scores how high the relevant documents sit in the top 10 (1 is perfect); recall@100 is the share of relevant documents anywhere in the top 100.

1. One vector per text: a transformer, a pooling step, a normalisation

Why one vector. Relevance belongs to a pair, but a corpus has millions of documents and a query arrives in real time. A bi-encoder computes every document vector once, at indexing; a query then costs one model pass plus dot products. A cross-encoder reads query and document together (more accurate, nothing precomputable), so it can only reorder a short list; it is owned by Rerankers and late interaction, as is late interaction (ColBERT: one small vector per token). The gap, from the topic's own timings (MPS, batch 1) measured here:

step, per querybi-encodercross-encoder
encode the query (bge-small / Qwen3-Embedding-0.6B)10.0 / 51.3 msnone
score all 5,183 abstracts0.5 ms (exact dot products)21.9 s (MiniLM cross-encoder, 236.8 pairs/s)
rerank only the top 30not needed155 ms (MiniLM) to 6.6 s (Qwen3-Reranker-0.6B)

The all-documents cell is derived: 5,183 / 236.8 pairs per second. The others: the setup's timings and the root's latency run (its src/pipe) (p50 over 40 claims, 2026-10-14). So every pipeline uses both: the bi-encoder (with BM25) narrows millions to tens, the cross-encoder orders the tens.

The two steps after the transformer. The transformer returns one vector per token. Pooling keeps one: CLS (the first token; bge-small, gte-modernbert), mean (average of the real tokens, padding ignored; all-MiniLM-L6, e5-small-v2) or last token (Qwen3-Embedding: in a decoder only the last token has seen the whole text). Normalisation divides by the length, so a dot product is a cosine (section 2; gte-modernbert ships without this step). The pooling is fixed by training, written in the model's 1_Pooling/config.json and modules.json: read them before writing your own inference.

Fig. 2: the claim "" through each model's real weights (CPU, float32). The second switch runs the same hidden states through a different pooling. measured here

  1. Tokens. The model's own tokenizer cuts the claim: 19 tokens for bge-small (the first 8 after [CLS] are its query prefix, drawn grey), 11 for MiniLM-L6, 30 for Qwen3-Embedding (19 of instruction). The model reads the prompt too.
  2. One vector per token. Each row is one token's output; its first 16 numbers (of 384, or 1,024 for Qwen3) stand as bars, positive up and negative down. Each depends on every token it could attend to (in Qwen3, a decoder, only the tokens before it).
  3. Pooling keeps one row. The dots show which rows feed the pooled vector: the first (CLS), all of them averaged number by number (mean) or the final one (last token); the rest fade.
  4. The pooled vector has its own scale. On this claim its length (the bar on the right) is 9.2 for bge-small, 6.1 for MiniLM-L6 and 107 for Qwen3.
  5. Normalise. Dividing by the length keeps the direction (the bars keep their shape and shrink) and makes the length 1 (the length bar), so the dot product of two such vectors is their cosine.
  6. The cosine to the labelled abstract. The abstract goes through the same steps; for bge-small with its own pooling the cosine is 0.633. Switch to a wrong pooling: nothing fails, a vector and a cosine still come out.
Predict: read all-MiniLM-L6 (trained with mean pooling) with CLS pooling instead. The cosine between the claim and its labelled abstract will be...

How much the wrong pooling costs in retrieval depends on the model, measured over whole corpora with queries pooled the same wrong way (512 tokens): bge-small read with mean pooling loses almost nothing (SciFact nDCG@10 0.708 instead of 0.713; NFCorpus 0.347 instead of 0.343), while MiniLM-L6 read with CLS pooling drops from 0.654 to 0.597 on SciFact and from 0.310 to 0.289 on NFCorpus. Nothing in the code warns you either way. measured here Each model also lives at its own scale before normalising (on the six texts of the table below, MiniLM's pooled vectors have length about 2 to 5, Qwen3's about 100), so cosines from different models are never comparable.

The pooling code, and five models rebuilt by hand (sentence-transformers 6.1.0 source; 2 min)

sentence_transformers/sentence_transformer/modules/pooling.py, lines 185 to 195 (CLS), 200 to 214 (mean) and 232 to 242 (last token), read in the installed package


sentence_transformers/base/modules/normalize.py, lines 39 to 43


Two details that bite people who write their own inference: the CLS branch takes the first real token (argmax on the mask), so left padding is handled; the last-token branch finds the last real token from the mask, so a decoder embedder works with either padding side. Rebuilt by hand with plain transformers (scripts/e_pooling.py), the five models give vectors identical to SentenceTransformer.encode (largest difference 0.0). Tokenisation differs per model (WordPiece pieces such as cc ##l ##19 with [CLS] and [SEP] for BERT-style models, byte-level pieces and an end-of-text token for Qwen3; see Tokenizers). measured here

"Length before normalising" is the pooled vector's L2 length on 6 texts.

2. Similarity and normalisation: use what the model was trained with

A small case first. Query q = (0.6, 0.8), length 1. Documents d1 = (1, 0), d2 = (0, 1) and d3 = (2, 0), which points the same way as d1 but is twice as long.

The dot product Σ qidi grows with both lengths; the cosine divides it by both lengths, so only the angle counts; the L2 distance |q − d| is smaller when closer. For vectors of length 1 the three rank documents identically, because |q − d|2 = 2 − 2 cos(q, d). On real vectors: gte-modernbert has no Normalize step, and ranking its raw vectors by dot product drops SciFact nDCG@10 from 0.767 to 0.740, while L2 and cosine agree (the parent's shared runs, src/vec) measured here (parent page).

Rule. For a model trained with cosine (all five here), normalise once at indexing and use the inner product, which every vector index (Vector indexes from the inside) does fastest; never mix normalised documents with an unnormalised query. Hosted APIs usually return normalised vectors: OpenAI's embeddings are "normalized to length 1" (its embeddings guide, read 2026-10-14) published, vendor.

The dot product puts the longest vector first; cosine and L2 agree on d2

Dot products 0.6, 0.8, 1.2: d3 first. Cosines 0.6, 0.8, 0.6: d2 first, d1 and d3 tied. L2 distances 0.894, 0.632, 1.612: d2 first. Check: 2 − 2 × 0.8 = 0.4 = 0.6322. derived

3. Training: pick your positive out of a line-up

The problem. A pretrained transformer's hidden states are not a retrieval space: masked-token or next-token training never asked a claim and its evidence to point the same way. The geometry is taught with (query, positive) pairs: a question and its answer passage, a title and its body, a claim and its evidence, a search and the page clicked. SciFact's train split gives 919 pairs from 809 claims; production models use hundreds of millions (Qwen3-Embedding: about 150 million synthetic pairs for a weakly supervised first stage, then about 12 million selected synthetic pairs plus labelled data, then model merging; arXiv 2506.05176, sections 3.2 and 3.3) published, vendor.

Fig. 3 is a real batch: 8 SciFact train claims the parent drew at random (seed 0), each with its labelled abstract and its own mined hard negative, scored by bge-small (the parent's src/vec/out/contrastive.json). Probabilities and losses are derived from those cosines with the formula below at τ = 0.05.

  1. One claim, one positive. "A deficiency of vitamin B6 decreases blood levels of homocysteine." and its labelled abstract: cosine 0.765.
  2. The batch: 8 claims × 8 abstracts. Rows are the claims, columns every abstract the batch embedded; the diagonal (green) is each row's positive, every other cell a free in-batch negative. The diagonal is the tallest bar in 8 of 8 rows, but the cosines all sit between 0.43 and 0.79.
  3. Divide by τ, softmax each row. At τ = 0.05 a cosine gap of 0.1 becomes a factor e2 ≈ 7.4, so the bars, now each row's probabilities, separate: the diagonal gets 39% to 85%. The loss is minus the log of the diagonal: 0.333 on average here (the parent's mean over 32,320 random batches of 8: 0.266).
  4. Add each row's mined hard negative. The highest-scoring unlabelled abstract of the whole corpus joins each row as a ninth candidate (red). It outscores the labelled abstract in 4 of 8 rows; the diagonal falls to 18% to 69% and the mean loss rises to 0.979 (parent's mean: 0.825). Nearly all the push now lands on that one column.
  5. Unless it is not wrong. Row 1's hard negative, "Effect of homocysteine lowering on mortality and vascular disease in advanced chronic kidney disease" (cosine 0.807), reads as evidence about the claim: a likely false negative (section 4). Over the parent's 809 train claims the top unlabelled abstract outscores the labelled one for 38.8%. A duplicate (a column also labelled relevant to the row) must be masked, not pushed; this batch has none.
Li = −log  exp(si,i/τ) / Σj exp(si,j/τ)
si,j
cosine between query i and column j of Fig. 3 (B positives plus the mined negatives)
τ
the temperature; sentence-transformers writes it as a scale 1/τ = 20, so τ = 0.05 by default

This is InfoNCE (van den Oord et al. 2018, arXiv 1807.03748) with in-batch negatives as Dense Passage Retrieval used them (Karpukhin et al. 2020, arXiv 2004.04906): free, because the batch's documents are embedded anyway. How its gradient splits among the negatives and what τ does is taught on Contrastive and self-supervised learning (48 real sentence pairs with a τ slider); its reading as a bound on mutual information on Information theory for ML; the same loss on image-text pairs (CLIP, SigLIP) on Vision encoders. The short version: nearly all the push lands on the one or two negatives closest to the query, which is why section 4 is about choosing them.

Batch size. A bigger batch is a bigger line-up. The parent's measurement on real vectors: with 8 candidates the labelled abstract already beats all in-batch negatives for 97.9% of train claims under bge-small; with 512, for 82.8% measured here (parent page). Small batches give a nearly solved task and little gradient, which is why BGE's general-purpose stage trained with batches up to 19,200 and in-batch negatives only (C-Pack, arXiv 2309.07597, section 3.4) published. Section 5 shows that at a fixed number of epochs on a small set this advice can reverse.

Duplicates. In SciFact train, 248 abstracts are the positive of more than one claim (602 of the 919 pairs), so a random batch of 32 holds such a clash about 46% of the time (derived, assuming independent draws). This page's loss masks any column labelled relevant to the row; sentence-transformers offers a no-duplicates batch sampler instead.

The library's loss, our check against it, and gradient caching (2 min)

sentence-transformers 6.1.0, sentence_transformers/sentence_transformer/losses/multiple_negatives_ranking.py, lines 322 to 338 (the end of compute_loss_from_embeddings; sim_matrices["query_to_doc"] is the B × (B + B·negatives) cosine matrix already multiplied by the scale)


  • Same loss. On a real batch of 8 claims with 8 mined negatives, this page's training code (scripts/e_train.py, verified by e_losscheck.py) gives 0.8568 and sentence-transformers' MultipleNegativesRankingLoss 0.8568 (difference 2e-07). measured here
  • Big batches without big memory. Gradient caching (Gao et al. 2021, arXiv 2101.06983; CachedMultipleNegativesRankingLoss) embeds the batch without gradients, takes the loss's gradient with respect to the embeddings, then re-encodes chunk by chunk with gradients. Ours, at chunk 4 against one plain backward pass, gives parameter gradients equal to a relative difference of 1e-06. measured here

4. Hard negatives, and the false negatives among them

Hard negatives teach fine distinctions: a random cardiology abstract is trivially wrong for a claim about a chemokine; an abstract about the same chemokine that does not support the claim is what the model must learn to rank second. They are mined by running a retriever over the corpus and taking high-ranked documents not labelled relevant. Two miners on the 919 SciFact train pairs (scripts/e_mine.py), BM25 and bge-small, have top-10 pools that overlap by only 33% on average: they find different negatives. measured here

False negatives are the catch: "not labelled relevant" is not "irrelevant". SciFact's annotators labelled the abstracts cited for each claim, not every abstract that bears on it.

Two models agreeing is a strong hint that a label is missing. For 154 pairs both put the same unlabelled abstract first; they read like this:

For a third of the training pairs, two different models put an unlabelled abstract above the labelled one

Per (claim, positive) pair: does the top unlabelled abstract of the whole corpus score above the labelled one? Both bge-small and Qwen3-Embedding say yes for 33.8% of pairs. Counted per claim with its first labelled abstract (the parent's way), the rates are 38.8% for bge-small and 38.4% for Qwen3-Embedding, equal to the parent's 38.8% and 38.4%. measured here

Filtering. NV-Retriever (Moreira et al. 2024, arXiv 2407.15831) proposed positive-aware mining: drop candidates scoring above 95% of the positive's own score ("TopK-PercPos"), their best setting published; sentence-transformers' mine_hard_negatives(relative_margin=0.05) is the same rule. Qwen3-Embedding's loss instead masks any negative scoring more than 0.1 above the positive (report, section 3.1). On SciFact train with bge-small scores, the 95% filter removes 42.1% of the top-10 dense candidates; the first surviving candidate sits at rank 3 (median), and 65 pairs have none left in the top 200, so they fall back to a random abstract. measured here Other remedies: skip the very top ranks when sampling, let a guide model mask candidates it scores above the positive (GISTEmbed, section 12), or relabel the candidates with a cross-encoder. Whether filtering helps is an empirical question: the sibling Rerankers and late interaction found random negatives beat BM25-mined ones for a cross-encoder on the same 809 train claims (rerank nDCG@10 0.734 against 0.726, 2 seeds each) and named false negatives as the likely cause; section 5 tests it on a bi-encoder.

5. A tiny fine-tune, measured

The question. Does in-domain contrastive training help a small general model on SciFact, and does the choice of negatives matter once false negatives are counted? bge-small-en-v1.5 (33 M parameters) trained on the 919 SciFact train pairs for 2 epochs, InfoNCE at τ = 0.05, four arms at batch 32: in-batch negatives only; +BM25 one BM25-mined negative per pair; +dense one bge-small-mined negative; +dense, filtered the same after the 95% filter. Plus in-batch only at batch 8 and 128. Three seeds each; the spread across seeds is the noise floor. Deliberately tiny: it shows the mechanics and their size on one corpus, not a production recipe.

  1. In-domain training helps even at this size: in-batch negatives alone take SciFact from 0.713 to 0.746; every arm's paired interval against the starting model is clear of zero.
  2. Mined hard negatives add about one point: BM25-mined 0.756 (paired difference against in-batch +0.004 to +0.016), bge-mined 0.757 (+0.005 to +0.018). Unlike the sibling cross-encoder run, the bi-encoder keeps its in-batch negatives, so the mined one is an addition, not a replacement.
  3. The false-negative filter took the gain away: 0.748, against in-batch 0.746. It removed 42.1% of the top-10 candidates and pushed the first kept candidate to rank 3, so the negatives left were easier. Whether the removed abstracts were truly relevant needs new labels; on this set, keeping them helped.
  4. At a fixed number of epochs, smaller batches won: batch 8 0.760 (228 steps), 32 0.746 (56 steps), 128 0.732 (14 steps). With 919 pairs a bigger batch means far fewer updates, and that dominates; recipes like BGE's 19,200 train on millions of pairs, and this run cannot test that regime.
  5. No forgetting: every arm also gains +0.009 to +0.014 on NFCorpus, a domain it never saw.
  6. The noise floor: seeds move an arm's mean by at most 0.005, less than the effects in 1, 2 and 4; the filtered arm's +0.002 over in-batch is inside it. The test set adds a paired interval of about ±0.008 for differences between arms.

How to read a small difference: one model's nDCG@10 on 300 claims carries a 95% interval about ±0.05 wide (section 11), but two runs on the same claims are compared with a paired bootstrap, which is much tighter; seeds add their own spread, which only repeats reveal. A difference smaller than the spread across seeds is not a finding.

Every arm beats the starting model; the arms differ by about a point, the seeds by less

nDCG@10 per arm, every seed a dot, the starting model as a dashed line; SciFact above, NFCorpus below (a domain it never trained on).
The full setup and the result table (2 min)
settingvalue
modelbge-small-en-v1.5 (33 M parameters, CLS pooling, normalised), its query prefix on claims, 512 tokens, float32 on MPS
dataSciFact train: 919 (claim, labelled abstract) pairs from 809 claims; nothing from the test claims
lossInfoNCE, τ = 0.05, labelled-relevant columns masked; gradient caching in chunks of 16
optimiserAdamW, learning rate 2e-5, weight decay 0.01, 10% warm-up then linear decay, 2 epochs
mined negativeseach drawn per epoch from the top 10 of its pool
batch-size armin-batch only at batch 8, 32 and 128 (same epochs, so a larger batch also means fewer steps: the two effects are not separated)
repeats3 seeds per arm
evaluationre-embed the SciFact and NFCorpus corpora with the trained weights; nDCG@10 on the test queries; paired bootstrap against the starting model
armSciFact nDCG@10 (seed mean)seed rangegain over the starting model (paired 95%)against in-batch only (paired 95%)NFCorpus nDCG@10NFCorpus change (paired 95%)
starting model0.7130.343
in-batch only0.7460.005+0.016 to +0.051reference0.354+0.004 to +0.019
+BM25 negatives0.7560.004+0.026 to +0.061+0.004 to +0.0160.354+0.004 to +0.019
+dense negatives0.7570.003+0.028 to +0.062+0.005 to +0.0180.357+0.006 to +0.021
+dense negatives, filtered0.7480.004+0.018 to +0.053-0.002 to +0.0070.357+0.006 to +0.022
in-batch, batch 80.7600.001+0.026 to +0.068+0.005 to +0.0230.352+0.001 to +0.016
in-batch, batch 1280.7320.002+0.006 to +0.032-0.026 to -0.0030.352+0.003 to +0.015

Measured on Apple M1 Pro (MPS), 2026-10-15 09:04; per-query nDCG@10 averaged over seeds before the paired bootstrap (10,000 resamples of the test queries). measured here

What training does to the vectors. Twelve SciFact test claims (never trained on), each with its labelled abstract, its three highest-scoring unlabelled abstracts under the starting model, and twelve random abstracts, re-encoded every 4 training steps. Fig. 4 is exact, not a projection: each abstract sits at distance 1 − cosine from the claim at the centre, at a fixed angle (the angle only groups the kinds), so moving in means "more similar". Predict before it plays: does the labelled abstract move closer to the claim?

  1. Before training. The starting bge-small: the labelled abstract (green, mean cosine 0.741 over the 12 claims) and the three hardest unlabelled ones (red, 0.730) crowd the claim; the other claims' abstracts (blue) and random ones (grey, 0.564) sit farther out.
  2. Steps 4 to 16: everything moves out. The first updates spread the whole space: random abstracts fall to 0.357, but the labelled abstract also falls, to 0.652, and the hard ones to 0.624. The far abstracts move furthest.
  3. Steps 20 to 56: settling. The labelled abstract stops moving (0.637 at the end) while the hard negatives keep receding (0.589) and the random ones reach 0.267.
  4. The gap, not the cosine. The green ring is the labelled abstract's cosine, the red ring the nearest other abstract's; retrieval needs green inside red. The mean gap between the labelled and the hard abstracts grows from 0.010 to 0.047 (in-batch arm), although every cosine fell.

What to watch. Training spreads the whole space: with filtered dense negatives the mean cosine of a claim to the random abstracts falls from 0.564 to 0.246, and to its own labelled abstract from 0.741 to 0.619. Absolute cosines fall; what retrieval needs is the gap between the labelled abstract and everything else. On these 12 claims the labelled abstract wins before training for 7 and after for 6: a sample this small does not show the gain that the 300-claim nDCG@10 measures (the chart above), which is why this view is for seeing the mechanism and the chart for judging it. measured here

All twelve claims at the current step. Margin = cosine to the labelled abstract minus the highest cosine to any other abstract in the set; positive means the labelled abstract wins.

Every run: 6 arms × 3 seeds (table)

6. Asymmetric prompts: telling the model which side it is encoding

The problem. Queries are short questions or claims; documents are long statements. Many models are trained with a marker for the side, some with a task description:

modelquery sidedocument sidewhat the card says
e5-small-v2query: passage: "Yes, this is how the model is trained, otherwise you will see a performance degradation" (FAQ, card at revision ffb93f3b, read 2026-10-14) published, vendor
bge-smallRepresent this sentence for searching relevant passages: nothing
Qwen3-EmbeddingInstruct: <task>\nQuery:nothinginstructions "typically" improve results by 1% to 5% published, vendor
all-MiniLM-L6, gte-modernbertnothingnothing
Predict: Qwen3-Embedding with no instruction at all on the NFCorpus queries. How many nDCG@10 points does it lose against its task instruction?

bge-small without its prefix: SciFact 0.713 to 0.720 (paired interval -0.006 to +0.021), NFCorpus 0.343 to 0.337 (-0.013 to +0.002): opposite directions, both inside their intervals, so on these sets the prefix is a coin toss, not the rule its card implies. Qwen3-Embedding: no instruction costs 2.1 points on SciFact and 6.6 on NFCorpus, clear of the noise; the wording barely matters (the card's generic web-search instruction 0.702 against the task instruction's 0.700 on SciFact, interval -0.011 to +0.014; 0.356 against 0.363 on NFCorpus, -0.013 to -0.000; the other set's instruction 0.368 on NFCorpus, -0.001 to +0.011). A decoder embedder trained with instructions needs to be told "this is a query"; which task it is told matters much less.

Dropping Qwen3's instruction costs points; changing its wording, or bge's prefix, stays inside the noise

Queries re-encoded with each setting (CPU, float32), stored document vectors searched (scripts/e_prefix.py). Dot: difference to the model's documented setting; bar: its paired 95% interval; red when the whole interval is below zero. measured here

e5's document prefix, measured (1 min)

e5-small-v2 (each corpus re-embedded with and without "passage: ", on MPS): with both prefixes 0.688 on SciFact (the MTEB results repository has 0.689) and 0.325 on NFCorpus; with neither, 0.680 and 0.318 (paired 95% interval of the difference: -0.028 to +0.013 and -0.014 to +0.001); with only the query prefix, 0.687 and 0.320. Its card's warning is right in direction but small here: under one nDCG@10 point, and both intervals include zero. measured here

The rule
Use the documented prompt as the default, then measure without it and with one or two task wordings on your own labelled queries: that costs one re-encoding of the queries, not of the corpus. A document prefix changes every stored vector, so changing it means re-embedding the corpus, and a query encoded with a mismatched setting silently loses quality.

7. Smaller vectors: fewer numbers (Matryoshka) or fewer bits (int8, binary)

Qwen3-Embedding stores 1,024 float32 numbers per text: 4,096 bytes, 4 GB for a million chunks (derived: 106 × 1,024 × 4 bytes). Two knobs shrink it: keep the first m numbers, or store fewer bits per number. Whether cutting works depends on training:

LMRL = Σm ∈ M cm  L(v1:m)
M
the nested sizes, for example {32, 64, 128, 256, 512, 1024}
v1:m
the first m numbers of the embedding, re-normalised
L
the contrastive loss of section 3, applied to the truncated vector
cm
a weight per size, often 1

Matryoshka Representation Learning (Kusupati et al. 2022, arXiv 2205.13147) adds the loss on every prefix, so the front of the vector carries the most; sentence-transformers wraps any loss this way (MatryoshkaLoss). Qwen3-Embedding was trained like this (its card: "user-defined output dimensions ranging from 32 to 1024"); bge-small was not.

Predict: Qwen3-Embedding cut to 256 numbers and stored as 1 bit each (32 bytes, 128 times smaller), searched without any rescoring. What share of its full nDCG@10 is left?

The defaults reproduce the parent's figures from its own output: Qwen3-Embedding keeps 98% of its nDCG@10 at half its dimensions and 95% at a quarter; bge-small keeps 94% and 81%; gte-modernbert cut to 384 dimensions (0.726) still beats Qwen3-Embedding at 1,024 (0.700). In bits: int8 (1 byte per number) is free (Qwen3 at 1,024: 0.996 of the exact top 10); binary codes of all 1,024 dimensions keep 0.674 of the exact top 10, and with the top 100 rescored in float32 keep all of the quality (0.700). Re-normalise after cutting. Hosted models expose the same idea as a parameter: OpenAI's text-embedding-3 models take a dimensions argument (1,536 by default for -small, 3,072 for -large), and OpenAI states that "a text-embedding-3-large embedding can be shortened to a size of 256 while still outperforming an unshortened text-embedding-ada-002 embedding with a size of 1536" (OpenAI embeddings guide) published, vendor. Index-side compression (product quantisation, RaBitQ) is on Vector indexes from the inside; indexing a Matryoshka prefix in pgvector on Search and vector databases.

The old page's figure "up to 14x smaller embeddings at the same ImageNet accuracy" is the MRL paper's ImageNet-1K classification result; it says nothing about retrieval on your corpus.

A Matryoshka-trained model keeps most of its quality at a quarter of its numbers; one trained without does not

SciFact test, exact search; y is the share of each model's own full nDCG@10. Precision applies to Qwen3-Embedding (the parent's runs quantised only it); bge-small and gte-modernbert are float32 truncations. int8: per-dimension ranges calibrated on the corpus, float query against decoded codes; binary: one sign bit per number, Hamming order; rescoring: the top 100 by the compressed score rescored with full float32 vectors. Data: the parent's src/vec/out/mrl_quant.json (2026-10-14). measured here (parent page)

8. Long inputs: the silent cut

Every model reads at most a fixed number of tokens and silently drops the rest: all-MiniLM-L6 256 by default, bge-small and e5-small-v2 512 (the e5 card: "Long texts will be truncated to at most 512 tokens"), gte-modernbert 8,192 (run here at 1,024), Qwen3-Embedding 32K (run here at 1,024). The vector of a truncated text is still a vector.

52.8% of evidence sentences end after BERT token 256, and for 38.7% of (claim, abstract) pairs even the first evidence sentence does, so all-MiniLM-L6 at its default never reads the sentence that makes the abstract relevant; it still retrieves many of them from the topic words in the title and opening. At 512 tokens, 12.1% of evidence sentences are cut. Re-embedding SciFact at four limits, bge-small scores 0.680 at 128 tokens and 0.713 at 512; on NFCorpus the limit barely matters past 128.

In scientific abstracts the evidence comes late, past where a 256-token model stops reading

Left: share of documents longer than each limit, per tokenizer (the same text is a different number of tokens to each). Right: for every SciFact evidence sentence of a train or dev claim (the original release marks them), the BERT-token position where it ends. measured here
What the cut costs, per model and limit (1 min)

What the cut costs, measured by re-embedding each corpus at four limits with the stored queries measured here:

model, set64 tokens128256512
bge-small, scifact0.5900.6800.7010.713
bge-small, nfcorpus0.3200.3300.3430.343
minilm-l6, scifact0.5720.6240.6450.654
minilm-l6, nfcorpus0.3170.3150.3160.310

On SciFact the curve climbs to 512 for both models: bge-small gains 3.2 points from 128 to 512, and MiniLM-L6, whose default is 256, scores 0.654 at 512 against 0.645 at 256 (its card: "The sequence length was limited to 128 tokens" in training, and input "longer than 256 word pieces is truncated" by default; it still uses text beyond both). On NFCorpus the limit barely matters past 128 (MiniLM is even slightly lower at 512): likely because the opening of these documents already carries their topic. Measure on your own documents before raising or lowering a limit.

In chunked pipelines the same problem is measured by The retrieval pipeline on QASPER papers: LangChain's default 4,000-character chunks are 782 BERT tokens at the median, so all-MiniLM-L6 reads 33.3% of their tokens and bge-small 65.1%; even 256-Qwen3-token chunks exceed MiniLM's 256 BERT tokens 16.9% of the time measured here (sibling page). Size chunks in the embedding model's tokens. Long-context embedders (gte-modernbert, Qwen3-Embedding, modernbert-embed at 8K to 32K) can embed a whole paper, but one vector for 8,000 tokens averages many topics; the usual design still chunks, and late chunking (embed the long text once, pool per chunk) is measured on the pipeline page.

9. Domains and languages: quality belongs to (model, data)

The running example has three labelled sets in different domains: SciFact (scientific claims against abstracts), NFCorpus (consumer health questions against medical documents, many relevant documents per query) and the multi-hop set (200 HotpotQA questions against Wikipedia paragraphs).

gte-modernbert leads SciFact by a clear margin (paired difference against bge-small +0.054, interval +0.029 to +0.081); on NFCorpus it is exactly tied with bge-small (+0.000, interval -0.016 to +0.017) and both trail Qwen3-Embedding; on the multi-hop set bge-small and gte lead and Qwen3 is third, although Qwen3-Embedding declares HotpotQA among its training data. The 22 M MiniLM is last or close to last everywhere: the one stable conclusion. Fine-tuning moves a model towards its training domain; section 5's NFCorpus panel shows it did not hurt the other set here.

The same models change order from one set to the next

nDCG@10 with 95% bootstrap intervals (resampling queries), from the setup's recorded runs; lines join each model across sets. measured here
A shift inside one dataset: SciFact's train and test claims disagree (1 min)

On the 809 train claims, bge-small and gte-modernbert are tied (bge ahead by 0.004, interval -0.011 to +0.020); on the 300 test claims gte is ahead by 0.054. Neither model declares SciFact training data in MTEB's metadata. The test set (the original release's dev claims) scores much higher on claims with annotated evidence (gte 0.895) than the train set does (0.739), so the two splits are not samples of one population, and a model chosen on one did not carry to the other. Choose on labelled queries that look like your production traffic, and keep a separate set to confirm. measured here

Multilingual retrieval is not measured here: both BEIR sets are English and two of the models (bge-small-en, MiniLM) are English-only. A multilingual model maps a query in one language near a passage in another, but quality per language follows its training data, so check on your own languages. Two open examples published, vendor: Qwen3-Embedding ("Supported Languages: 100+ Languages", its card; it also advises writing the instructions in English) and BGE-M3 ("more than 100 working languages", inputs "up to 8,192 tokens", and dense, sparse and multi-vector retrieval from one model; Chen et al. 2024, arXiv 2402.03216). For a multilingual shortlist, MMTEB extends MTEB to "over 500 quality-controlled evaluation tasks across 250+ languages" (arXiv 2502.13595).

10. MTEB: what its scores do and do not predict

MTEB scores a model on many tasks with one fixed protocol and ranks models by the mean. The current English benchmark, MTEB(eng, v2) (introduced with MMTEB, Enevoldsen et al. 2025, arXiv 2502.13595), has 41 tasks: 10 retrieval, 9 semantic similarity (STS), 8 classification, 8 clustering, 3 pair classification, 2 reranking, 1 summarization. SciFact and NFCorpus are not among its 10 retrieval tasks, so they are a fair test of transfer.

Predict: take the 10 best models by the MTEB(eng, v2) average and the 10 best on SciFact (149 models). How many models are in both lists?
  • Across the whole range the average is informative: Spearman rank correlation 0.83 with SciFact and 0.90 with NFCorpus. A model near the bottom of the leaderboard is rarely good on your set.
  • Near the top it is not: the 10 best by the average and the 10 best on SciFact share 2 models (3 for NFCorpus). Of the 889 pairs of models whose averages differ by less than one point, 45% are ordered the other way on SciFact.
  • The leader by the average (Qwen/Qwen3-Embedding-8B) is 8th on SciFact; the SciFact leader (Salesforce/SFR-Embedding-2_R) is 16th by the average. Qwen3-Embedding-0.6B is 13th by the average and 73th on SciFact; bge-small 47th and 60th (all read at the commit above; these positions move with every submission).

Why rank does not transfer, in order of size here: the task mix (the mean blends classification, clustering and similarity with retrieval: a model can climb on 31 non-retrieval tasks); your domain (the retrieval tasks are arguments, questions, fact-checking, finance, COVID literature; your corpus is none of them); contamination (13 of these 149 models declare SciFact training data and 14 NFCorpus, while 28 declare nothing at all, so their zero-shot status is unknown); noise (a few hundred queries per task; section 11); and setup (a model run without its query instruction or at a shorter maximum length scores below its leaderboard number; sections 6 and 8). The leaderboard is a shortlist generator: read the retrieval tasks nearest your domain, not the mean.

The average sorts the field but not the top: near the top, the order on your set is a coin flip

Each dot is a model: x = MTEB(eng, v2) mean over tasks, y = its nDCG@10 on the chosen set; the running example's models labelled. 149 models of the MTEB results repository with all 41 tasks and both sets (scripts/e_mteb.py, repository commit 34a44096, 2026-10-14) published (results repository), analysis measured here.
How each task type is scored (1 min)

Retrieval and reranking: nDCG@10 or MAP; classification: accuracy of a logistic regression on the vectors; clustering: V-measure; semantic similarity: Spearman correlation of cosines with human scores; pair classification: average precision. MTEB(eng, v2)'s description in mteb 2.24.13: "prioritizing tasks not commonly used for fine-tuning to give a more realistic estimate of generalization performance". The parent's Tool map tab has the leaderboard view, version caveats and the zero-shot table.

11. Choosing a model on your own data

  1. Shortlist 3 to 6 models: licence, languages, maximum length against your chunk size, vector size against your memory, hosted or local budget, and the MTEB retrieval tasks nearest your domain.
  2. Label a few hundred real queries (from logs if you have them) with their relevant chunks; keep 20 to 30% aside as a confirmation set. Same chunking for every model.
  3. Run each model with its documented prompt and without; exact search (no index, so the index does not blur the comparison); BM25 and a hybrid as references.
  4. Compare paired: per-query nDCG@10 (or recall@k at your k), the difference between models on the same queries, bootstrap interval of the difference. Models within the interval are tied; break ties on cost (bytes per vector, query latency, indexing time, licence).
  5. Confirm the winner on the held-out queries, then on a sample of production traffic after launch.

Steps 4 and 5 on the measured models: who is tied with the best, and what each costs

Pick the labelled set that looks most like your queries, then your limits. "Against the best" is the paired difference to the best system on the same queries; if its interval covers zero, the model is tied and cost decides. Costs are this machine's (Apple M1 Pro, MPS, batch 1 for queries): the ratios transfer, the milliseconds do not. measured here

The full table: intervals, paired differences and costs (table)

ColBERT (late interaction, about 45 KB per abstract) and BM25 are listed for reference; their storage is not one vector per document. Query cost: single-query encode p50 on MPS for the four models (setup records); 62 ms for ColBERT is the setup's exhaustive MaxSim over all 5,183 abstracts per query; 0.25 ms for BM25 is the root's latency run.

How many labelled queries? Subsampling the test sets (2,000 random subsets per size, scripts/e_choose.py) measured here:

Predict: how often do 50 random SciFact test claims pick the same winning model as all 300?

On SciFact, where the best model leads by 0.054, 100 queries pick the same winner 99.95% of the time and 50 queries 96%. On NFCorpus, whose top two are 0.020 apart, 100 queries agree only 90%. Per-model 95% intervals are about ±0.05 wide at 300 SciFact claims, but the paired half-width is far tighter and shrinks like 1/√n, about 0.044 at 100 SciFact queries. The order of all four models is much less stable than the winner: 50% at 200 NFCorpus queries.

How many queries you need depends on the gap you must detect

The models on this page, and two newer candidates (dated table, October 2026; volatile)
modelparamsdimspoolingquery promptmax tokensMatryoshkalicenceMTEB(eng, v2) rank by meanrank on SciFactSciFact nDCG@10 here
all-MiniLM-L6-v222 M384meannone256noApache 2.098930.645
bge-small-en-v1.533 M384CLSquery prefix512noMIT47600.713
gte-modernbert-base149 M768CLSnone8,192 (run at 1,024)not statedApache 2.0not in resultsnot in results0.767
Qwen3-Embedding-0.6B0.6 B1024last tokentask instruction32K (run at 1,024)yes, 32 to 1,024Apache 2.013730.700

Parameters, dims, pooling, prompt and licence from the parent's model records (2026-10-14); ranks from the MTEB results repository at commit 34a44096 (2026-10-14) among the 149 models with full results (gte-modernbert has none there); SciFact nDCG@10 measured here. Matryoshka: Qwen3-Embedding's card; bge-small and MiniLM were not trained for it.

The current hosted and open models (OpenAI text-embedding-3, Gemini embedding, Voyage 4, Cohere embed v5, Jina v5, Qwen3-Embedding, bge, gte, e5, MiniLM), with status, licences and context lengths as read in October 2026, are on the parent's Tool map tab. When images, audio or video must share the index with text, EmbeddingGemma 2 (Google, 6 October 2026, Apache 2.0) is a small open candidate: 740M parameters, of which a text-only deployment loads 270M; text, code, images, audio and video in one 768-dimensional space, trained to truncate to 512, 256 or 128 dimensions; 8K-token context; Google reports MTEB Code rising from 68.76 for EmbeddingGemma 1 to 78.68 published (Google). vLLM 0.32.0 and SGLang 0.5.22 serve it.

12. Fine-tuning for real: when it pays and how

When. After the protocol above says the best off-the-shelf model is not good enough, and when you have a domain the general models have not seen (internal jargon, product codes, queries that are error messages), at least a few thousand (query, positive) pairs or a way to make them (a language model writing questions for your passages is the common route; Qwen3-Embedding's report describes synthetic pairs at scale), and a labelled evaluation set never used for training.

How, with sentence-transformers 6.1.0 (the tools this page's run mirrors): mine_hard_negatives(..., relative_margin=0.05) for positive-aware mining; MultipleNegativesRankingLoss, or CachedMultipleNegativesRankingLoss for large batches on a small GPU; GISTEmbedLoss, which uses a second "guide" model to mask in-batch negatives the guide scores above the positive; MatryoshkaLoss around any of them if you will truncate; a no-duplicates batch sampler; evaluation on held-out queries every epoch; three seeds.

The core of this page's training loop (code)

The costs people forget. A new model means re-embedding the whole corpus (bge-small: 36 s for SciFact here; Qwen3-Embedding-0.6B: 816 s), and vectors from the old and new model cannot share an index: a running system needs a second index and a switch-over (RAG in production measures what mixing them does: nDCG@10 0.379 at 50% re-embedded against 0.713 clean). Check the other domains for forgetting (section 5's NFCorpus panel).

Depth: two design questions

Switch a 50-million-chunk index to a better embedding model without downtime. Plan it. (1 min)
Evaluate offline on a labelled set first (paired, with intervals). Then build a second index: re-embed all chunks with the new model in a batch job (throughput-bound; cost = tokens × price or GPU-hours), while new and updated documents are written to both indexes. Shadow-query the new index and compare results and latency; switch reads with a flag per tenant or a percentage; keep the old index until the new one has been stable; then delete. Never mix vectors of two models in one index: a query vector from one model is meaningless against the other's documents. Budget memory for two indexes during the switch, or use Matryoshka truncation or quantisation (section 7) to fit.
Retrieval over internal documents is poor on product codes and jargon. What do you try, in what order? (1 min)
Measure first (golden set from search logs). Add BM25 and hybrid fusion (exact terms are BM25's strength); check chunking and the query prompt; try two or three stronger off-the-shelf models with the protocol of section 11; add a reranker; only then fine-tune on mined pairs from logs or LLM-generated questions, with positive-aware hard negatives, several seeds and a held-out set, and check general-domain queries for forgetting.
Measured on the topic's shared runs: what the root page used to show (moved here when the root's Vector search lab was retired, 2026-10-24; 2 min)

These runs are recorded in the root page's src/vec (the same vectors this page uses).

  • Why words are not enough. The claim "Mitochondria are uninvolved in apoptosis" should find an abstract about cytochrome c release triggering programmed cell death, which shares almost none of its words.
  • Cosine ranges differ by model. On one batch of eight SciFact training claims and their abstracts, bge-small's cosines run from 0.43 to 0.79 and Qwen3-Embedding's from 0.14 to 0.70; the median cosine of random pairs is 0.563 for bge-small and 0.097 for MiniLM. bge-small puts unrelated pairs near 0.5 and good matches near 0.75; Qwen3-Embedding puts unrelated pairs near 0.2. "Keep results above 0.7" means something different for each model, and changes silently when you swap models: tune thresholds per model.
  • If vectors are not normalised, the dot product favours long vectors and L2 favours short ones; cosine is the safe default.
  • Cost scales with size. Per document, Qwen3-Embedding indexes about 20 times slower than bge-small (6.4 against 144 documents per second on MPS), roughly in proportion to its parameter count (18 times), which holds on any hardware; absolute milliseconds do not.
  • The order changes again on multi-hop. On the topic's 200 HotpotQA questions bge-small scores 0.860 nDCG@10, gte-modernbert 0.857 and Qwen3-Embedding 0.825, and Qwen3-Embedding declares HotpotQA and FEVER among its training data, so it is not zero-shot there.
  • A 2-D picture of the vectors. PCA kept 10.5% of the variance of these vectors and placed between 0 and 3 of each claim's 10 true neighbours among its 10 nearest dots; t-SNE kept neighbourhoods but invents the distances between clusters. Use a 2-D map to see that topics cluster and to spot a corpus that sits apart, never to judge whether retrieval works: retrieval is decided in the full 1,024 dimensions. (Projection on a 705-point sample, seed 0.)
  • Compression at scale. The truncation and quantisation numbers of section 7 are SciFact's (5,183 short abstracts, one relevant abstract per claim for most claims); on a corpus of millions, more near-duplicates compete for the top 10, so compression costs more recall there: check on your own data at your own size.
  • BGE's task-specific stage adds one mined hard negative per pair, "mined from the task's original corpus, following the ANN-style sampling strategy".
  • Provenance. The model comparison comes from the setup's records (quality: pytrec_eval; speed: three runs on MPS, load average 1.5 to 11.8 on a shared machine); the raw gte-modernbert vectors for the cosine, dot and L2 comparison were re-embedded for that alone (SciFact corpus and 300 claims, MPS, bench lock held).
Every measured number on this page comes from the scripts in this page's src/scripts folder, run on an Apple M1 Pro (10 CPU cores, 16 GB) in October 2026 against the running example of Topic: rag-and-retrieval (its src/data/load.py); results in src/data. Versions: sentence-transformers 6.1.0, transformers 5.19.0, torch 2.14.1, pytrec_eval-terrier 0.5.10; mteb 2.24.13 for the leaderboard analysis. Models at the revisions in the parent's src/data/manifest.json, plus intfloat/e5-small-v2 at revision ffb93f3b. Source quoted from those installed versions. Published numbers are labelled and kept apart.