Skip to content

NV-Embed: Improved Techniques for Training LLMs as Generalist Embedding Models

Skip →Matryoshka (MRL)
main track #1corefundamentalpaperrubric 12/122024 · ICLR 2025 (Spotlight) · ~40 min

Chankyu Lee, Rajarshi Roy, Mengyao Xu, … Wei Ping

Status

TL;DR. NV-Embed turns Mistral 7B into a general embedding model with four changes: drop the causal mask, pool with a small latent-attention layer, mine hard negatives relative to the positive’s score, and train in two stages (retrieval first, then all tasks without in-batch negatives). NV-Embed-v1 scored 69.32 and v2 72.31 on the 56-task MTEB average; each was first on the leaderboard at the time.

Why it matters now. Most 2025–26 LLM embedders (Qwen3 Embedding, Llama-Embed-Nemotron, Gemini Embedding) face the same decisions NV-Embed ablates: causal or bidirectional mask, last-token or mean or learned pooling, which negatives to trust, and in what order to mix tasks. The paper is a clean set of controlled ablations on those choices. Read it for the design space, not for the leaderboard rank.

NV-Embed: a bidirectional LLM, latent-attention pooling and two-stage contrastive training Left: Mistral 7B with its causal mask removed produces one hidden state per token. Middle: the token states act as queries in a cross-attention over a trainable latent array of 512 vectors, followed by an MLP and mean pooling into one 4096-dimensional embedding. Right: stage one trains on retrieval data with in-batch negatives and seven mined hard negatives filtered by a 95 percent of positive score threshold; stage two blends in classification, clustering and STS data with in-batch negatives turned off. NV-Embed: pool with learned latents, train in two stages Mistral 7B (LoRA rank 16) causal mask removed h₁ h₂ h₃ … h_l token states Q: l × 4096 every token attends to every token query side: "Instruct: ‹task› Query: q" instruction tokens excluded from pooling; docs get no prefix max length 512 tokens latent array K = V 512 trainable vectors O = softmax(QKᵀ) V 8 heads, l output rows MLP (GELU) mean pool one 4096-d embedding vs mean: +0.84 nDCG@10 on 15 BEIR sets (Table 3) Stage 1: retrieval only in-batch negatives ON + 7 mined hard negatives keep a negative only if score < 0.95 × positive (E5-Mistral as teacher) Stage 2: blend tasks retrieval, classification, clustering, STS, synthetic in-batch negatives OFF: a batch-mate may share the query's class MTEB avg: v1 69.32 → v2 72.31
Original sketch. Left: a bidirectional Mistral 7B gives one state per token. Middle: each token state is re-coded through a trainable latent dictionary, passed through an MLP, then mean-pooled. Right: retrieval-only training with in-batch and filtered hard negatives, then a blended stage without in-batch negatives.

Bidirectional attention. During contrastive training the causal mask is simply removed. Unlike LLM2Vec, there is no separate warm-up with masked next-token prediction. LoRA (rank 16, alpha 32) adapts the backbone.

Latent-attention pooling. Let Q∈Rl×dQ \in \mathbb{R}^{l\times d} be the last-layer token states and K=V∈Rr×dK = V \in \mathbb{R}^{r\times d} a trainable latent array with r=512r = 512 and d=4096d = 4096:

O=softmax⁡(QK⊤) V,e=mean⁡i MLP⁡(Oi)O = \operatorname{softmax}(QK^{\top})\,V, \qquad e = \operatorname{mean}_i\,\operatorname{MLP}(O_i)

The softmax runs over the 512 latents, separately for each token. Every token is re-expressed as a mixture of learned “dictionary” vectors before the mean. In practice this is 8-head cross-attention with the tokens as queries, then a two-layer GELU MLP and a plain mean. The motivation: mean pooling dilutes key phrases and last-token pooling is biased to the end of the text.

Contrastive loss and instructions. Training uses the standard InfoNCE loss. For a query qq with positive d+d^+, negatives N\mathcal{N} and temperature τ\tau:

L=−log⁡exp⁡(s(q,d+)/τ)exp⁡(s(q,d+)/τ)+∑d−∈Nexp⁡(s(q,d−)/τ)\mathcal{L} = -\log \frac{\exp(s(q,d^+)/\tau)}{\exp(s(q,d^+)/\tau) + \sum_{d^-\in\mathcal{N}} \exp(s(q,d^-)/\tau)}

Queries get a prefix Instruct: <task definition> Query: q; documents get none, so one document index serves every task. Instruction tokens are masked out of the pooling, but they still shape the other tokens through attention.

Two stages. Stage 1 trains on retrieval data only, with in-batch negatives plus 7 mined hard negatives per query (batch 128, 20k steps). Stage 2 (18k steps) adds classification, clustering and STS data recast as (query, positive, negatives) and turns in-batch negatives off. For a binary classification set a random batch-mate shares the query’s class half the time, so in-batch “negatives” would often be positives.

Positive-aware hard negatives. E5-Mistral scores the candidates as a teacher. A candidate survives only if its score is below 95% of the positive’s score (the TopK-PercPos rule from NV-Retriever). This removes many unlabeled positives that would otherwise be pushed away.

All numbers are paper-reported, on MTEB (56 English tasks; the 15 retrieval sets are BEIR) or AIR-Bench 24.04.

Setting (stage 2, bidirectional)Retrieval (15)MTEB avg (56)Source
EOS pooling, v1 data58.3967.85Table 2
Mean pooling, v1 data58.7168.97Table 2
Latent attention, v1 data (= NV-Embed-v1)59.3669.32Table 2
Mean pooling, v2 data61.8171.71Table 3
Latent attention, v2 data (= NV-Embed-v2)62.6572.31Table 3
  • Leaderboard snapshot (Table 1, as of 2024-10-01): NV-Embed-v2 72.31, bge-en-icl 71.24, SFR-Embedding-2R 70.31, GritLM-7B 66.76, E5-Mistral-7B 66.63, OpenAI text-embedding-3-large 64.59. These are leaderboard numbers, not runs under one shared protocol.
  • Schedule ablation (Table 4): two-stage 72.31; single stage without in-batch negatives 71.94 (retrieval 61.37); single stage with in-batch negatives 70.83; reversed order 71.85.
  • Out-of-MTEB check (Appendix B): first on AIR-Bench Long-Doc (74.78) and second on QA, over 15 and 8 English datasets with hidden labels.
  • Compression (Appendix A): pruning, 8-bit quantization and LoRA retraining. The paper reports that the compressed model beats embedders built directly on 3–4B backbones.
  • In-domain training on BEIR sources. The training mix includes the training splits of MS MARCO, HotpotQA, NQ, FEVER, FiQA, SciFact, NFCorpus and ArguAna. The “BEIR” average is therefore not zero-shot in BEIR’s original sense. The paper says this follows common practice.
  • Small, single-seed margins. The latent-attention gain over mean pooling is 0.35 MTEB with v1 data and 0.6 with v2 data. No variance across seeds is reported.
  • A small inconsistency. The method section and Table 11 say 512 latents; the Figure 2 caption says 4096 latents.
  • Cost. A 7B forward pass per document and a 4096-d vector per passage are expensive at web scale: 100M passages need about 0.8 TB in fp16 before any compression.
  • English and short inputs. Training is English-centric (MIRACL and Mr.TyDi aside) with 512-token inputs. See Llama-Embed-Nemotron for NVIDIA’s multilingual follow-up.
  • The teacher limits the negatives. Hard negatives are mined with E5-Mistral, so its blind spots shape which negatives are seen and which false negatives survive.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Work through the two negative-handling choices in NV-Embed. (a) Stage 1 uses batch size 128, each query with 1 positive and 7 mined hard negatives. If in-batch negatives are the other 127 queries' positives, how many negatives does each query see, and what fraction are mined? (b) Now imagine running in-batch negatives on a balanced binary classification dataset recast as retrieval (query = text, positive = another text of the same class). In a batch of 128 such queries, how many of a query's 127 in-batch "negatives" are in fact same-class positives in expectation? (c) With the 95% TopK-PercPos rule and a positive scored 0.80 by the teacher, which of the candidates scored 0.79, 0.77, 0.75 and 0.62 can be kept as hard negatives?

    What a strong answer covers
    • (a) 127 in-batch + 7 mined = 134 negatives per query; only 7/134 ≈ 5% are mined, but they carry most of the useful gradient because they score high.
    • (b) Each batch-mate is the same class with probability about 1/2, so about 63 of the 127 "negatives" are really positives. InfoNCE pushes the query away from them, the opposite of what classification needs.
    • This is why stage 2 disables in-batch negatives. Table 4 shows single-stage training with in-batch negatives drops classification to 86.6, versus 90.2 with them disabled.
    • (c) Threshold = 0.80 × 0.95 = 0.76. Candidates at 0.75 and 0.62 are kept; 0.79 and 0.77 are dropped as likely false negatives.
    • Picking the hardest of the survivors keeps the negatives informative but below the positive, which is the point of anchoring the threshold to the positive score.
  2. Mechanism

    In the latent-attention layer the softmax runs over the 512 latents for each token, not over tokens, and a plain mean over tokens follows. So the layer never learns explicit per-token weights. Explain how it can still reduce "dilution of key phrases", and why an extra self-attention layer in the same position did not help.

    What a strong answer covers
    • Each token output O_i = softmax(q_i Kᵀ)V is a convex combination of 512 learned vectors, then an MLP. Every token is re-coded in a learned dictionary before averaging.
    • Uninformative tokens can be mapped to a shared or low-norm direction that contributes little to what separates documents, while content tokens map to distinctive latents. The mean of the re-coded tokens is then dominated by informative ones: an implicit reweighting.
    • The latent array adds new parameters outside the LLM and a nonlinear per-token map. Self-attention only mixes the same token states again, which the LLM layers already do; Table 2 shows mean 68.97 versus self-attention 69.10 MTEB and slightly lower retrieval.
    • Last-token (EOS) pooling suffers from recency bias. In Table 2 it trails mean pooling for both masks, so the gain is not just from a better summary token.
    • Caveat: the latent gain on retrieval is under one point (Table 3: 61.81 → 62.65), so the mechanism story is a hypothesis, not a proven cause.
  3. What if…

    Table 4 compares single-stage training with in-batch negatives on, single-stage with them off, the two-stage schedule, and a reversed two-stage schedule (all tasks first, then retrieval with in-batch negatives). Predict the retrieval and overall MTEB ordering of the four, explain each gap, and say which comparison isolates the effect of order rather than of in-batch negatives.

    What a strong answer covers
    • Two-stage is best on both: retrieval 62.65 and MTEB 72.31.
    • Single stage with in-batch on: lowest overall (70.83), mainly because classification falls to 86.6 from false in-batch negatives.
    • Single stage with in-batch off: close overall (71.94) but retrieval only 61.37, because retrieval loses the many cheap in-batch negatives.
    • Reversed: retrieval recovers only to 61.91 and clustering/STS fall, so MTEB 71.85. Fine-tuning retrieval last partly overwrites the non-retrieval geometry.
    • Two-stage versus reversed uses the same data and the same in-batch settings per phase and changes only the order, so it is the cleanest test of curriculum order.
  4. Critique

    NV-Embed reports 62.65 nDCG@10 averaged over the 15 BEIR retrieval sets in MTEB, and its training mix includes the training splits of MS MARCO, HotpotQA, NQ, FEVER, FiQA, SciFact, NFCorpus and ArguAna. As a BEIR author, state what this number does and does not tell you about zero-shot retrieval, and design the evaluation that would measure it.

    What a strong answer covers
    • BEIR was built to test zero-shot transfer. Training on the train splits of many BEIR sources makes those sets in-domain; the score measures supervised multi-task performance, not out-of-domain generalisation.
    • The paper says it follows prior practice (§4.1), and its own S1→S2 step shows that adding more public retrieval sets (including SciFact and NFCorpus) raises retrieval: the score tracks data overlap as well as method.
    • The AIR-Bench check (hidden labels, new domains) is the paper's partial answer: first on Long-Doc (74.78), second on QA. Useful evidence, but English only and against a leaderboard snapshot.
    • Experiment: split BEIR into sets whose training data was used and sets with none; report both averages for NV-Embed and for a baseline trained without those splits, plus benchmarks built after the model (BRIGHT, Q2D-Web, agent queries).
  5. Design

    You want a first-stage retriever for a BrowseComp-Plus-style deep-research agent over 100M passages, trained on a university budget (8 GPUs for about two weeks). Which NV-Embed ingredients would you copy, which would you change, and how would you validate the choice? Consider the 4096-d output, the 512-token training length and the CC-BY-NC-4.0 licence of the released v2 weights.

    What a strong answer covers
    • Cheap and portable: LoRA fine-tuning with the causal mask removed, positive-aware hard-negative mining, the two-stage schedule. None adds inference cost.
    • Index cost: 100M × 4096 dims × 2 bytes ≈ 819 GB in fp16 (1.6 TB in fp32). Add a Matryoshka loss or a down-projection, or start from a smaller backbone, and measure what is lost at 512–1024 dims.
    • Agent queries are long, multi-constraint and often reformulated; 512-token training may also truncate long evidence passages. Train with longer documents if the corpus needs them.
    • The NC licence blocks commercial reuse of the v2 weights; a lab can still study them, but a released artifact should start from a permissively licensed base.
    • Validate on agent-issued queries (BrowseComp-Plus, Q2D-Web) and on end-to-end agent accuracy at a fixed search budget, not only the MTEB average.
  6. Research idea

    Figure 2 of the paper suggests individual latents specialise (one tracks review sentiment). Pitch a project that tests whether latent-attention pooling helps most for multi-aspect queries and long documents, as the dilution argument predicts. Give the hypothesis, the minimal experiment and the falsifying result.

    What a strong answer covers
    • Hypothesis: the gain over mean pooling grows with the number of distinct facets a relevant document must match and with document length.
    • Minimal experiment: same backbone, data and steps, pooling ∈ (mean, latent); bucket test queries by number of constraints (for example BrowseComp-Plus-style queries) and documents by length.
    • Probe the latents: attention mass per latent across queries; ablate the most-used latents and see which buckets drop.
    • Falsified if the gain is flat across buckets or vanishes when mean pooling gets the same number of extra parameters (for example a per-token MLP of matched size).

Done with this page?

Status