AI Agentic Handbook
Embeddings & Encoders

Fine-tuning an embedding model

Senior levelReviewed Oct 2026In 3 interview questions

Training an embedding model a bit further on your own question-and-passage pairs, so your field's jargon finally lands near its meaning.

In plain English

Off-the-shelf Embedding models learned from general internet text. If your field speaks its own language — part numbers, clause names, medical abbreviations — the model may have no idea that two related texts belong together.

Fine-tuning shows it thousands of 'this question goes with this passage' examples from your world until it learns those links. In-domain recall often jumps 5–15 points. Worth trying after the simpler fixes (like adding keyword search alongside vector search) have run out of room.

Analogy

A capable new hire who needs a month shadowing the team before 'CR-7 on the Q-line' means anything at all to them.

Common pitfall

Mining 'hard negatives' straight from the top search results seems clever and backfires in dense domains: plenty of those negatives are correct answers nobody labelled, and the model dutifully learns to push them away.

How it actually works

Standard recipe: contrastive training with in-batch negatives (MultipleNegativesRankingLoss in Sentence Transformers, an InfoNCE objective) on (query, positive passage) pairs, plus 1–3 hard negatives per pair mined from the current model's top-50 that are not labelled relevant. Larger batches give more negatives per step; GradCache or CachedMNRL makes batch 1,024+ fit on one GPU. Typical run: 5k–50k pairs, 1–3 epochs, learning rate 1e-5 to 2e-5, warmup 10%. A base model like bge-base (110M) trains in under an hour on one A100 at 20k pairs.

Pairs come from search logs (query → clicked or cited doc), support tickets resolved by an article, or synthetic questions generated per chunk by an LLM and filtered by a Cross-encoder. The main risks are false negatives in hard-negative mining (a 'negative' that is actually relevant teaches the wrong thing), overfitting to the synthetic question style, and forgetting general ability. Hold out 10–20% of queries by document, not by pair, so leakage does not inflate gains. A fine-tuned model is a new model: every vector must be re-embedded via a full Backfill. API models mostly cannot be fine-tuned (as of Oct 2026), so this usually means self-hosting an open model.

What I'd ship on day one

Sentence Transformers v3+ trainer, base model bge-base-en-v1.5 or bge-m3 (or Qwen3-Embedding-0.6B for multilingual), CachedMultipleNegativesRankingLoss, batch 512–1,024, 2 hard negatives per pair from ranks 10–50 filtered by a cross-encoder, lr 2e-5, 1–2 epochs, golden set split by document.

Worked example

Aerospace maintenance manuals, 1.4M chunks. Baseline bge-base-en-v1.5 recall@10 = 0.62 on 600 technician queries like 'torque spec MLG axle nut post-retread'. Hybrid with BM25 lifts it to 0.71.

Fine-tune on 18k pairs: 6k from search logs (query → doc opened > 30 s) and 12k synthetic questions from Claude Haiku 4.5, filtered by bge-reranker-v2-m3 score >0.5, with 2 hard negatives each from the base model's top-50. Recall@10 alone: 0.78; hybrid: 0.84. Re-embedding 1.4M chunks takes 40 minutes on one L4.

In the interview

State the order and the reason for it: 'Before fine-tuning I try hybrid search and a reranker, because both are reversible. I fine-tune when the golden set shows vocabulary misses BM25 cannot fix, I have at least 5k real or carefully filtered synthetic pairs, and I can own a self-hosted model and its backfills.' Expect 'how do you know the gain is real?' — a held-out split by document, the same golden set across baseline, hybrid and fine-tuned, and a check that ordinary queries did not quietly regress.

051020400.60.70.80.9diminishing past ~20kTraining pairs (thousands) →Recall@10 →
Fine-tuned bi-encoderBase + BM25 hybrid
Worked example (maintenance manuals): gains saturate; hybrid search is the bar to beat first.
01Collect pairslogs + synthetic
02Mine hard negstop-50, filter
03Train MNRL1–3 epochs
04Golden-set gateheld out by doc
05Backfill indexalias swap
Fine-tuning is a new model: it ends in a full re-embed.

Numbers worth knowing

Typical in-domain gain
+5–15 points recall@10jargon-heavy domain, 10k–50k pairs, vs same base model
Training time
<1 h on one A100110M model, 20k pairs, 2 epochs
Minimum useful data
~5k pairsreal or cross-encoder-filtered synthetic

How to decide

WhenDo this
Misses are exact identifiers (part numbers, statute ids)Add BM25 / Hybrid search first; fine-tuning won't memorize ids.
Misses are domain paraphrase ('MLG' vs 'main landing gear') and you have ≥5k pairsFine-tune an open model and backfill.
You must stay on an API embedding modelAdd a Reranker or a query-side instruction instead.

Cost maths

Training: 1 A100-hour ≈ $2–4 (illustrative on-demand, Oct 2026). Synthetic pairs: 12k questions × ~1.2k input + 60 output tokens on Claude Haiku 4.5 at $1/M in, $5/M out ≈ $14 + $4 = $18. Backfill: 1.4M chunks on one L4 at ~600 passages/s ≈ 40 min ≈ $0.60. The recurring cost is ownership: a GPU embedding service, retraining as the corpus shifts, and a backfill every retrain.

Operating it

Time to scale up when…
  • Golden-set recall plateaus after hybrid + reranker and misses are paraphrase, not identifiers
  • Search logs exceed ~5k distinct queries/week with click or citation signal: enough for a retrain cycle
  • Fine-tuned model's recall drifts >3 points as the corpus changes: schedule quarterly retraining
What to monitor
  • Golden-set recall@10 on real queries held out by document: gate any new checkpoint on ≥2-point gain
  • Recall on a general-domain control set: alert on a drop >3 points (catastrophic forgetting)
  • Online answer acceptance or citation click-through during canary: roll back on a 2-point drop

When it goes wrong

What users saw

A fine-tuned model scored +14 points offline, but live answer acceptance on a legal research tool fell.

How it was caught

A/B test over two weeks: acceptance 61% vs 66% control; offline golden set still showed the gain.

Root cause

Train/test split was by pair, not by document, so the same contracts appeared in both; synthetic questions also mirrored chunk wording that real users never used.

Fix

Re-split by document, rebuilt the golden set from real queries only, mixed 40% real log pairs into training; the honest gain was +6 points and held online.

Sources

  1. Sentence Transformers training overview — Sentence Transformers, 2025docs
  2. Representation Learning with Contrastive Predictive Coding (InfoNCE) — van den Oord et al., 2018paper
  3. Dense Passage Retrieval for Open-Domain Question Answering — Karpukhin et al., 2020paper
  4. M3-Embedding (BGE-M3) — Chen et al., 2024paper

Check yourself

Three questions. Every option is explained once you answer.

1ConceptWhy does mining hard negatives blindly from the current model's top results risk making a fine-tuned embedder worse?
2ScenarioGolden-set misses on a parts catalogue are mostly exact part numbers like 'P/N 7741-22B' that the dense model never ranks. You have 8k query-click pairs. What first?
3CalculationYou generate 12k synthetic training questions with Claude Haiku 4.5, each call using ~1.2k input and ~60 output tokens, at $1/M input and $5/M output. Roughly what does it cost?