Skip to content

Nomic Embed: Training a Reproducible Long Context Text Embedder

optionalcorefrontierpaperrubric 10/122024 · TMLR (per arXiv comment) · ~35 min

Zach Nussbaum, John X. Morris, Brandon Duderstadt, Andriy Mulyar

Status

TL;DR. Nomic Embed (nomic-embed-text-v1) is a 137M-parameter English embedder with an 8,192-token context. Its main contribution is openness: the authors release the weights, the training code and the curated training pairs. The model beats OpenAI’s text-embedding-ada-002 and text-embedding-3-small on MTEB and on the long-context LoCo benchmark (Table 1). The full recipe runs in about a week on one 8×H100 node.

Why it matters now. Most strong embedders, open-weight or not, hide their data and filtering. That makes it hard to say why a model wins on MTEB, or whether BEIR test domains leaked into training. Nomic gives you a recipe you can ablate stage by stage on an academic budget. Its successor, Nomic Embed v2, keeps the same pipeline and swaps in a multilingual mixture-of-experts encoder.

The recipe has the three stages common to E5, GTE and BGE, but every stage is rebuilt so that it can run at 2048 tokens and be released.

  1. A long-context BERT (nomic-bert-2048). BERT-base with rotary position embeddings (RoPE) instead of learned absolute positions, SwiGLU, FlashAttention, dropout 0, 30% masking and no next-sentence prediction. Trained on BooksCorpus and Wikipedia packed into 2048-token chunks. GLUE average 0.84, close to MosaicBERT and RoBERTa-base (Table 2).
  2. Weakly supervised contrastive pretraining. 470M pairs from 29 public sources (Reddit title–body, PAQ, Amazon reviews, S2ORC, …) are consistency-filtered: a pretrained gte-base model embeds 1M sampled pairs, and a pair survives only if its document is in the query’s top 2. About 235M pairs remain. Each batch of 16,384 comes from one source. Task prefixes (search_query, search_document, classification, clustering) tell the model which notion of similarity to use.
  3. Supervised fine-tuning. 1.6M labelled pairs (MS MARCO, NQ, NLI, HotpotQA, FEVER, parts of MEDI, …) with 7 hard negatives per query, sampled at random from the gte-base top 20 to dilute false negatives. Batch 256, one epoch.

Both contrastive stages use one-directional InfoNCE with cosine score ss and temperature τ\tau. In stage 3 the denominator adds HH hard negatives:

L=−1n∑ilog⁡es(qi,di)/τes(qi,di)/τ+∑j≠ies(qi,dj)/τ+∑m=1Hes(qi,di,m−)/τ\mathcal{L} = -\frac{1}{n}\sum_i \log \frac{e^{s(q_i,d_i)/\tau}}{e^{s(q_i,d_i)/\tau} + \sum_{j\neq i} e^{s(q_i,d_j)/\tau} + \sum_{m=1}^{H} e^{s(q_i,d^{-}_{i,m})/\tau}}

Reading 8,192 tokens after training on 2,048. The model never trains beyond 2048 tokens. At inference, Dynamic NTK scaling raises the RoPE base bb (set to 1,000 here) according to the input length ll:

b′=b (αs−(α−1))∣D∣/(∣D∣−2),s=max⁡(1,l/L), L=2048, α=2b' = b\,\big(\alpha s - (\alpha - 1)\big)^{|D|/(|D|-2)}, \qquad s = \max(1, l/L),\ L = 2048,\ \alpha = 2

where ∣D∣|D| is the head dimension. For l≤Ll \le L the factor is 1, so short inputs are untouched. For longer inputs a larger base slows every rotation, which keeps the angles of the slowest position pairs inside the range seen in training. The paper writes s=L′/Ls = L'/L for a target length L′L'; the dynamic version recomputes it from the actual input.

Nomic Embed: a three-stage open recipe for a 137M long-context embedder Three boxes left to right. Stage 1 trains a long-context BERT with masked language modelling at 2048 tokens. Stage 2 runs weakly supervised contrastive pretraining on about 235 million pairs that survive top-2 consistency filtering, with one data source per batch and task prefixes. Stage 3 fine-tunes on 1.6 million labelled pairs with seven mined hard negatives. A bottom band shows that at inference Dynamic NTK RoPE scaling stretches the 2048-token model to 8192 tokens, and that weights, code and data are all released. Nomic Embed: every stage, data set and script released 1 · MLM: nomic-bert-2048 BooksCorpus + Wikipedia RoPE, SwiGLU, FlashAttention 30% masking, no NSP 2048-token packed chunks 137M parameters ≈ 4 days on 8×H100 2 · Weak contrastive 470M pairs, 29 sources top-2 filter with gte-base → ≈ 235M pairs kept batch 16,384, one source per batch, task prefixes InfoNCE, in-batch negatives ≈ 3.5 days 3 · Supervised fine-tune 1.6M labelled pairs 7 hard negatives, sampled from gte-base top-20 batch 256, one epoch same prefixes as stage 2 ≈ 1 hour Inference: train at 2048, read 8192 Dynamic NTK raises the RoPE base only when input exceeds 2048 tokens (α = 2)
Original sketch of the recipe. The colours mark stages, not models. Times are the paper's Appendix A estimates on one 8×H100 node.

All numbers are paper-reported (Tables 1, 4–6). MTEB inputs are truncated to 512 tokens.

ModelParamsMTEB avgMTEB RetrievalLoCo (8192)Jina LC (8191)
nomic-embed-text-v1137M62.3952.885.5354.16
nomic-embed-text-v1-ablated (no FEVER, HotpotQA, MEDI)137M61.3651.486.8953.53
jina-embeddings-v2-base-en137M60.3947.985.4551.90
text-embedding-ada-002n/a60.9949.352.7055.25
text-embedding-3-smalln/a62.2651.182.458.21
  • The unsupervised checkpoint (after stage 2 only) already reaches MTEB 59.9. The one-hour fine-tune adds about 2.5 points.
  • Among similar-size open models, only BGE-base is higher on MTEB (63.6 vs 62.4 in Table 4).
  • At 4096 tokens on LoCo, both Nomic variants score close to E5-Mistral-7B (85.6 and 86.7 vs 87.8), a model about 70× larger, except on Tau Scrolls (§5.2.4).
  • On the Jina long-context benchmark the picture is weaker: at 8191 tokens Nomic (54.2) is below ada-002 (55.3) and text-embedding-3-small (58.3). The authors note that WikiCities falls with length for every model and may be a poor long-context test, and that QASPER abstracts look saturated.
  • English only. Multilingual coverage needed a new encoder and data, which is what v2 does.
  • Long-context evidence is thin. LoCo and the Jina set are small, and two of their datasets are flagged as saturated or misleading by the authors. A single 8k vector also competes with chunking strategies the paper does not compare against.
  • “Zero-shot” depends on what you count. The main model trains on BEIR train splits (FEVER, HotpotQA). The ablated model is the cleaner zero-shot reference.
  • Filter circularity. Consistency filtering inherits the filter model’s idea of relevance. Its effect on low-overlap or reasoning-heavy pairs is not measured in the paper.
  • Recipe family: E5 (weak contrastive pretraining and consistency filtering), NV-Retriever (positive-aware negative mining, used by v2), and the comparison table in Embedding recipes.
  • Successor: Nomic Embed v2 (multilingual, mixture of experts, Matryoshka dimensions).
  • Long inputs: RoPE for the position encoding being stretched; Late Chunking for using a long-context encoder to embed short chunks instead of one long vector.
  • Evaluation: MTEB / MMTEB for what the average hides.

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

    Nomic Embed trains with RoPE base b = 1,000 at L = 2,048 tokens and, at inference, uses Dynamic NTK scaling b′ = b·((α·s) − (α − 1))^(|D|/(|D|−2)) with α = 2. Assume head dimension |D| = 64 (BERT-base). (a) Compute b′ for an 8,192-token input. (b) The slowest RoPE pair rotates by angle m·b^(−(|D|−2)/|D|) at position m. Compare the largest angle that pair reached in training with its angle at m = 8,192 before and after rescaling. (c) What happens to a 1,500-token input?

    What a strong answer covers
    • (a) s = 8192/2048 = 4, so α·s − (α − 1) = 8 − 1 = 7. Exponent 64/62 ≈ 1.032, so b′ ≈ 1000 · 7^1.032 ≈ 7,450. Static NTK (α = 1) would give 1000 · 4^1.032 ≈ 4,180.
    • (b) With b = 1,000 the slowest pair has wavelength 2π·1000^(62/64) ≈ 5,060 tokens. Training reached at most 2048 · 2π/5060 ≈ 2.54 rad. Unscaled, position 8,192 gives ≈ 10.2 rad, more than a full turn the model never saw.
    • With b′ ≈ 7,450 the wavelength grows to ≈ 35,400 tokens, so position 8,192 maps to ≈ 1.45 rad, inside the trained range. High-frequency pairs change much less, so local order is mostly preserved.
    • (c) For l ≤ L the dynamic rule uses s = 1, so the factor is α − α + 1 = 1 and b′ = b: short inputs see exactly the trained positions. This is why the paper can use it with no long-context fine-tuning.
  2. Mechanism

    Stage 2 fills every 16,384-pair batch with pairs from a single source and prepends task prefixes such as search_query / search_document or clustering. Explain, at the level of the InfoNCE denominator, what shortcut each choice removes and what conflicting signal the prefixes resolve.

    What a strong answer covers
    • InfoNCE asks the query to score its own positive above the other 16,383 documents in the batch. If sources are mixed, a Reddit title can find its Reddit body just by matching style, length or domain, so the loss falls without learning relevance.
    • Same-source batches make every in-batch negative look like the positive at the surface level, so only content can separate them. Negatives become harder at no extra mining cost.
    • Prefixes break the symmetry of a shared encoder. For "What is the capital of France?" a paraphrase is the right neighbour for a similarity task and "Paris is the capital of France." is right for QA. Without a prefix, the same pair of texts gets opposite gradients from different sources.
    • Asymmetric tasks use different query and document prefixes; symmetric tasks put the same prefix on both sides. Forgetting the prefix at inference therefore changes which geometry you get.
  3. What if…

    nomic-embed-text-v1-ablated drops FEVER, HotpotQA and MEDI from fine-tuning. Table 1 reports MTEB 62.39 → 61.36 and LoCo 85.53 → 86.89; Table 4 reports MTEB Retrieval 52.8 → 51.4. Explain why removing data lowers one benchmark and raises the other, and what this says about reading "zero-shot BEIR" numbers on MTEB.

    What a strong answer covers
    • FEVER and HotpotQA are BEIR datasets inside MTEB Retrieval. Training on their train splits makes those test sets in-domain, which lifts the retrieval average and therefore the MTEB average.
    • LoCo is long-document retrieval with a different distribution. The paper itself suggests the BEIR training data may be orthogonal to LoCo, so the extra short QA pairs do not help and may pull capacity away.
    • A 1.4-point retrieval drop is large relative to the gaps between nearby models on the leaderboard (BGE-base 53.3, text-embedding-3-small 51.1), so leaderboard order can flip on this choice alone.
    • For a fair zero-shot claim, report the ablated model or split BEIR results into datasets whose train splits were or were not used.
  4. Critique

    Consistency filtering keeps a weak pair only if a pretrained embedder (gte-base) ranks the paired document in the query's top 2 among 1M sampled pairs; 470M pairs shrink to about 235M. Identify the weakest assumption in this step and design an experiment that would show whether it biases the final model.

    What a strong answer covers
    • Assumption: the filter model's top-2 is a good proxy for "true positive". The filter can only keep pairs it already gets right, so the new model is trained toward the filter's notion of relevance.
    • The paper reports that a 22M MiniLM filter discarded true positives with low lexical overlap, which is why it moved to gte-base. A larger filter has the same blind spots, only fewer.
    • Likely casualties: paraphrastic, cross-domain or reasoning-heavy pairs, and long documents truncated by the filter. These are the cases deep-research queries need most.
    • Experiment: train matched models on (a) top-2 filtered, (b) a random 50% subset of the same size, (c) a filter from a different model family. Compare on low-lexical-overlap slices (for example BRIGHT, or BEIR queries binned by BM25 overlap) and on long-document LoCo.
  5. Design

    You want a reproducible English embedder for scientific full-text retrieval (papers up to ~8k tokens) on one 8×H100 node for about one week, the same budget Nomic reports. Decide which of Nomic's stages you keep, change or skip, and how you would validate the result.

    What a strong answer covers
    • Budget split in the paper: MLM ≈ 4 days, contrastive pretraining ≈ 3.5 days, fine-tuning ≈ 1 hour. Starting from the released nomic-bert-2048 or the unsupervised checkpoint frees most of the week.
    • Spend the saved time on domain pairs: S2ORC title–abstract and abstract–body pairs are already in the mix; add citation-context → cited-paper pairs and long-form pairs, still with one source per batch.
    • Decide whether to train longer than 2048 or rely on Dynamic NTK. Measure it: evaluate at 2k, 4k and 8k on LoCo-style and in-domain full-text retrieval.
    • Mine hard negatives with a stronger domain model, sample them rather than taking the top N, and keep a held-out set with no train-split overlap so the evaluation stays zero-shot.
    • Report against the released v1 at matched input length, and against chunk-and-pool or late chunking, since long single vectors may lose to chunking on localised evidence.
  6. Connect

    Nomic Embed and E5 both use weak contrastive pretraining with consistency filtering followed by supervised fine-tuning with hard negatives. State precisely what Nomic changes in the encoder, the loss direction and the release, and which of those changes plausibly drives the long-context results.

    What a strong answer covers
    • Encoder: Nomic first trains its own BERT with RoPE, SwiGLU, FlashAttention, no dropout and 2048-token packing, so the contrastive stages run at 2048 tokens instead of 512.
    • Loss: Nomic uses a one-directional query→document InfoNCE with cosine similarity; some contemporaries add the document→query term.
    • Release: Nomic ships the curated pairs, filtering model choice and training code, so each stage can be rerun or ablated.
    • The long-context gains come mainly from the 2048-token training plus RoPE extrapolation. The loss direction and the release do not change length behaviour.

Done with this page?

Status