I once switched embedding models for what seemed like a solid reason at the time: on public leaderboards, the new model scored several points higher than the old one.
I rebuilt the full index and ran the evaluation set, and overall Recall@20 barely moved. But on the group of queries for “error codes” and “internal codenames,” it actually dropped. Only later did I figure it out: that batch of queries relies on literally rare tokens, and the new model was weaker at distinguishing long-tail strings; the leaderboard mostly tests general semantic Q&A, which is nothing like my query distribution.
Since then, leaderboards only give me a candidate list; they don’t make the decision.
Post 6/15 in this series · Previous: Chunking isn’t about cutting characters, it’s about cutting semantic boundaries · Next: The four axes of vector database selection
What a bi-encoder is actually computing
The embedding models used for retrieval are usually bi-encoders: the query and the document each pass through the same (or a pair of) encoders, each compressed into a fixed-dimension vector, and online matching is done with a single vector similarity comparison.
1 | q_vec = normalize(E_q(query)) |
The key is the word “separately.” Document vectors are computed at index time, query vectors only at query time, and the two never interact during encoding. This lets retrieval run at millisecond latency and handle tens of millions of candidates, but it also imposes a hard ceiling: all interaction information must be compressed into a dense vector of a few hundred to a few thousand dimensions. Fine-grained word-level matching, negation, numeric comparison, and multi-condition combinations were never suited to this representation.
Once you understand this, a lot of downstream design becomes obvious. Hybrid retrieval compensates for literal matching; reranking compensates for deep interaction between query and document (a cross-encoder feeds both together through a model). They aren’t nice-to-haves; they patch the structural weaknesses of the bi-encoder.
A few representation details that don’t error, only degrade results
Normalization is where many people trip on the first step. If vectors are L2-normalized, inner product, cosine, and Euclidean distance on the unit sphere all produce the same ranking; without normalization, computing cosine directly versus using the index’s default IP gives different results. My habit is to normalize uniformly before offline writes, normalize online queries the same way, fix the index configuration to inner product, and hard-code this into index_manifest, leaving a single source of truth.
Pooling method is the kind that doesn’t error but only degrades. CLS, mean pooling, and last-token pooling each have their preferences, and model docs usually state them; use the wrong one and nothing throws an exception, all similarity absolute values just get uniformly worse, and then you start doubting your data.
Asymmetric retrieval is even easier to miss. Many models require different prefixes for queries and documents, e.g., adding “Retrieve relevant passages for this sentence:” on the query side and nothing on the document side. This is determined by the training task; omitting it or reversing it often causes silent degradation. I put prefixes into index_manifest, read them online from the same config, and never write them in two places.
Truncation is the kind that doesn’t even leave a log. Embedding models have a max token count, commonly 512, with long-context models reaching 8192. Overlong embed_text gets silently truncated: the request succeeds, the vector returns normally, but the latter half never participated in encoding. Post 5, on index construction, counts the token distribution mainly to catch this.
Six dimensions for selection
I actually run candidate models through this table; if any of the six can’t be answered, it doesn’t enter evaluation.
| Dimension | Question to ask | Common pitfall |
|---|---|---|
| Language & domain | Chinese proportion, whether it includes code/dialect/proper nouns | High on English leaderboards, poor on Chinese long tail |
| Max input length | Is the chunk’s token distribution truncated | Long document tails silently lost |
| Dimension | Storage, memory, index build cost | Double the dimensions, index size and latency rise together |
| Symmetry | Are query/passage prefixes required | Prefix omitted, silent degradation |
| Deployment form | API or local inference | API has data egress and rate-limit issues; local needs GPU |
| Version stability | Will the vendor silently swap weights | Online query and offline index models inconsistent |
Dimension deserves its own note. Many models use Matryoshka representation learning, which can truncate 1024 dimensions to 256 with limited loss. For corpora of a million or more this is very practical: vector storage, ANN index memory, and build time all drop almost linearly. My approach is to use short dimensions for coarse recall first, then the original dimensions or a reranker for fine ranking, treating dimension as a tunable knob in the recall stage rather than a constant fixed once and for all.
Deployment form is often a veto item in enterprise settings. If private documents can’t leave the intranet, you can only deploy locally, and then you have to consider GPU memory, batch throughput, and restart costs during model upgrades. API solutions save on ops, but you have to handle rate limits, retries, and the hardest-to-diagnose one: the vendor silently updating the model version. I record the model identifier at every index build, plus a vector hash of a fixed sentence, and verify it at online startup, alerting on mismatch.
Domain fine-tuning is the last resort, not the first choice. It does improve representations of industry terms and internal abbreviations, but it requires positive and negative sample pairs, and constructing high-quality pairs is expensive; after fine-tuning you still have to go back and verify that general queries haven’t degraded. My order has always been: check corpus cleaning first, then chunking, then hybrid retrieval, and only then fine-tuning. The vast majority of “the embedding isn’t good” cases are actually earlier steps done wrong.
Build your own evaluation: a hundred real queries is enough to start
Selection can’t rely on gut feeling, but you don’t need to build a large-scale benchmark right away. My minimum viable evaluation set looks like this:
- Sample 60–80 queries from real logs, stratified by frequency, not just high-frequency ones;
- Hand-write 20–30 boundary queries: error codes, IDs, model numbers, colloquial rewrites, containing negation, multi-condition combinations;
- For each, label the relevant
doc_idorchunk_id, only marking “which should appear in the top 20 positions”; - Keep a separate set of “no answer in the corpus” queries to test refusal.
Three metrics are enough: Recall@K (whether the ground truth was recalled, with K set to the final rerank candidate depth), MRR (what rank the first correct answer gets), and recall broken out by category. Overall metrics are easily inflated by high-frequency simple queries; only by looking per category do you know what the new model actually changed.
1 | def evaluate(model, cases, k=20): |
There are two paths in evaluation that most easily lead to self-deception. One is evaluating with model-generated queries: synthetic queries tend to be highly similar in wording to the documents, inflating recall — essentially grading your own exam. The other is forgetting to rebuild the full index when switching models, mixing old and new vectors in the same space, making scores incomparable and the results meaningless. The dual-index shadow switch mentioned in Post 4 is necessary infrastructure here, not an optional optimization.
There is another type of result to watch for: after switching models, the overall score goes up by 2 points, but the “ID-type” queries drop by a chunk. In this case I usually don’t switch, or I switch while adding a BM25 path alongside. Average scores masking distribution shifts is the most typical pitfall in model selection.
Switching a model involves more than the model name
- Fully rebuild the
embed_textvectors for all chunks with the new model, generate the newcorpus_version, and check the query prefix, normalization, pooling, dimensions, metric, and index configuration one by one; - Run the same evaluation set against the new index in a shadow environment, comparing by query type rather than just overall score;
- Check the impact of dimension changes on ANN index parameters (HNSW’s M, efConstruction) and storage;
- Atomically switch
active_version, keeping the old index for at least one rollback cycle; - Monitor the similarity distribution of online queries; an overall downward shift usually means the online-side configuration wasn’t synced, not that the model got worse.
The last item is one I added later. After a switch, online average similarity dropped from 0.7 to 0.4 — no errors, no timeouts, just answers that started getting vague. After a long investigation, it turned out the online service had missed adding the query prefix. No alert catches this kind of error; only distribution monitoring can.
What it’s good at, and when to stop investing in the model
Dense vectors are strongest at semantic generalization: when users rephrase, use colloquial language, or describe a concept rather than the original words, it still recalls. This exactly fills the vocabulary gap of BM25 from article 8.
Its structural weaknesses are equally clear: rare literal strings (error codes, IDs, version numbers — strings that get chopped up by BPE), exact negation, numeric comparison, and scenarios requiring word-level alignment. Also, vectors are a black box; the reason for a recall is unexplainable, and when something goes wrong it’s hard to explain to users why a passage was selected. Multi-vector representations — e.g., keeping a set of vectors per token and doing late interaction — can mitigate some of this, at the cost of an order-of-magnitude increase in storage and computation.
There’s another rarely mentioned boundary: when the corpus is highly homogeneous, all document vectors crowd into a very narrow region with extremely low discriminability. With hundreds of documents on the same topic, the top1 and top20 scores might differ by only a few hundredths. In this case, a bigger model yields limited gains; what you should do instead is add metadata filtering, add structured fields, or simply let BM25 handle primary retrieval. The way to judge is simple: plot the similarity scores of a batch of queries and look at the distribution width. If it’s absurdly narrow, don’t spend money on the model yet.
Once the model is chosen and the vectors are computed, they need somewhere to be stored and efficiently retrieved. The next article covers vector databases and ANN indexes: what HNSW and IVF-PQ each sacrifice, and why “retrieval with filter conditions” is the item most worth actually testing during selection. By the way, in your current system, how much do the top1 and top20 similarities differ?
Comments