Skip to content

When Retrieval Quality Suddenly Drops: An Embedding Index Drift Decision Tree

A RAG system that has been running well, and then one day users suddenly say "it got dumber" — queries that used to be answered accurately are now off, the right chunks no longer rank at the top, and some queries even throw a dimension error. This class of failure is different from "RAG returns nothing": it is not "nothing came back," it is "something came back but it is wrong," which makes it harder to classify and the most easily misdiagnosed as "the chunks got worse" or "the threshold needs a tweak."

I have consolidated this kind of triage into three branches, all organized around one quantity — cosine similarity — as the branching point. The single core idea: first confirm "is it drift," then branch into "which kind of drift," and only then talk about a rebuild. Many people jump straight to a full rebuild, which takes hours to a day, only to find the root cause was that the query side was using the wrong model and the index was never the problem — a wasted run. The section below starts with the confirmation command, then walks the three branches.

Prerequisite: Confirm "is it drift" — the cosine baseline comparison is the only criterion

The only reliable evidence that an embedding index has drifted is whether the cosine over known relevant chunks has collapsed. So the first step is not touching the index — it is building a "golden query set" and comparing it to the baseline:

# Take one "known-answer" query plus its correct chunk, compute the cosine between
# the query vector and the correct chunk
python3 -c "
import requests, numpy as np
qv = requests.post('http://localhost:11434/api/embed',
    json={'model':'bge-m3','input':'the golden query text'}).json()['embeddings'][0]
# cv = the vector of this query's known-correct chunk (fetched from the vector store;
#       confirm it was produced by the same model version)
print('cos =', np.dot(qv, cv) / (np.linalg.norm(qv)*np.linalg.norm(cv)))
"

Compare that cosine against the "pre-launch baseline." The baseline is the average cosine over the golden query set that you recorded the first time the RAG was tuned. If the cosine has collapsed overall (say from 0.7 to 0.35), it is drift. With that conclusion in hand, you are routed straight into a branch of the decision tree:

Symptom: retrieval quality dropped / relevant chunks rank low / dimension error
|
+-- (1) query vector dim != stored vector dim
|  +-- hard matrix-shape error -----------> Branch A: model swap not aligned (query / build used different models)
|  +-- dims match but cosines collapsed overall -> Branch B: swapped the model but did not rebuild (two vector spaces)
|
+-- (2) dims match, cosines collapsed below baseline overall
|  +-- golden-set avg cosine dropped > 10% -> Branch B: index drift (full rebuild)
|  +-- golden-set cosines normal, only specific queries bad -> Branch C: not drift, it is chunking / query rewriting (back to the RAG piece)
|
+-- (3) cosine distribution is bimodal (some high, some low)
   +-- Branch B variant: the index mixes two model-version vectors (incremental ingestion did not re-embed old data)

One scenario I postmortemed (built from a typical production pattern): a knowledge-base RAG, and the team, "for better quality," swapped the embedding model from A to B. They changed the query side and left the index alone. Three days later, users reported "it answers the wrong thing." Running the golden query set showed the average cosine drop from 0.71 to 0.38 — the classic "new space on the query side, old space in the index" drift. A full rebuild brought it back to 0.70. The most expensive part of the whole thing was not the rebuild (two hours); it was the false assumption that "swap the model, tweak the query side, done." When you swap the embedding model, the index must be rebuilt with it — that is not optional, it is a hard constraint of the vector space.

Why cosine, specifically, as the criterion rather than anything else? Because the essence of drift is "two vector spaces no longer aligned," and cosine similarity is exactly the measure of "the angle between the same content in the query space and the target space." Within one embedding-model space, the cosine over a known relevant chunk is stable and reproducible; the moment the space changes, that stable value shifts systematically. So "the cosine over known relevant chunks" is the most sensitive and cheapest probe for drift — it does not depend on user query quality or on the chunking strategy, only on the single stable premise that "this content and this query are genuinely related." That is exactly why the golden query set has to be of "known answers": only with a definite answer can the cosine's collapse be cleanly attributed to "space drift" instead of being contaminated by "the query itself was written badly."

Branch A: Dimension mismatch — "the query and the build used different models"

Signature: the query vector's dimension differs from the stored vector's dimension. Light: the cosine is computed by some convention but comes out globally wrong. Heavy: a hard matrix-shape error (numpy's shapes not aligned). This branch is a pure engineering bug, unrelated to content quality.

# One command aligns the two dimensions: query vector dim vs stored vector dim
python3 -c "
import requests
qv = requests.post('http://localhost:11434/api/embed',
    json={'model':'the-model-at-query-time','input':'anything'}).json()['embeddings'][0]
import json, urllib.request
# cv_dim = the dimension of one stored vector (qdrant shown; swap the query API for other stores)
cv = json.load(urllib.request.urlopen(
    'http://localhost:6333/collections/kb_chunks/points?limit=1'))['result']['points'][0]['vector']
print('query dim =', len(qv), ' | stored dim =', len(cv))
"

Branching:

  • query dim != stored dim, with a hard error -> the model used at query time and the model used at build have different dimensions. This is the most common "swapped the model but only changed the query side" incident. Fix: either switch the query side back to the build model (temporary stopgap), or do a full rebuild under the new model (root fix).
  • Dimensions differ but no error (silently padded or truncated as "tolerance") -> sneakier: some frameworks silently pad or truncate on a dimension mismatch, so the computed cosine "looks computable" but is entirely wrong. Fix: add a dimension assertion at both ingestion and query time, and fail-fast on mismatch — do not let the framework tolerate it.
  • Dimensions match, but the same set of documents gives a wildly varying cosine across two queries -> not a dimension problem; the embedding service is unstable (returning zero vectors or degraded vectors). Check the embedding service's health and whether batching is dropping rows.

One independent judgment worth holding: a dimension mismatch must fail-fast, never be "tolerated." Because padding or truncation turns a bug that should surface immediately into "the cosine quietly getting worse," and by the time you notice, the index has been loaded with the wrong model's vectors for days. My hard rule: at ingestion, record "the collection's vector dimension + model version," and at query time, assert the dimensions match first — throw an error on mismatch and never enter the cosine computation.

Branch B: Index drift — "swapped the model but did not rebuild, two vector spaces"

Signature: dimensions match (you swapped to a same-dimension model), but the golden-set average cosine has collapsed overall below baseline. This is the most typical face of embedding drift: the model changed, the vector space changed, but the index still holds old-space vectors, so new queries against old vectors land at a low floor overall.

# Run the golden query set once and compare the average cosine to the baseline
# (the baseline was recorded at launch)
python3 - <<'PY'
import requests, numpy as np, json
golden = json.load(open('golden_queries.json'))   # [{q, correct_chunk_id}]
base = json.load(open('baseline.json'))['avg_cos']  # baseline recorded at launch
scores = []
for item in golden:
    qv = requests.post('http://localhost:11434/api/embed',
        json={'model':'current-model','input':item['q']}).json()['embeddings'][0]
    cv = fetch_chunk_vector(item['correct_chunk_id'])   # the stored chunk vector
    scores.append(np.dot(qv, cv)/(np.linalg.norm(qv)*np.linalg.norm(cv)))
avg = float(np.mean(scores))
print(f'avg cos = {avg:.3f}  (baseline {base:.3f}, delta {avg-base:+.3f})')
if avg < base * 0.9:
    print('>>> DRIFT DETECTED: avg cos dropped >10% vs baseline')
PY

DRIFT DETECTED settles it. Branching:

  • Golden-set average cosine dropped more than 10 percent, and top-1 hit rate dropped too -> confirmed index drift. Fix: a full rebuild (re-embed all chunks under the current model). This is the only correct action; tuning the threshold or re-chunking cannot rescue it.
  • Average cosine dropped, but top-1 hit rate did not -> the cosine values collapsed but the relative ordering held. That is usually the new model's score distribution shifting down overall (say, the new model's cosines are uniformly 0.2 lower than the old one), not true drift. In that case what should change is "re-calibrating the threshold to the new model," not a rebuild.
  • Cosines did not collapse, but specific queries got worse -> not global drift, it is query rewriting or chunking; go back to the RAG piece's branches, do not touch the index.

One scenario I postmortemed (built from a typical production pattern): a team upgraded the embedding model, changed the query side, and "while at it" rebuilt part of the index — only the new documents from the last three months — and thought that was enough. Old-document queries were still inaccurate, because the old documents' vectors were still in the old space and new queries against them collapsed. The incremental rebuild only fixed the "new documents," not the "old documents." An "incremental rebuild" when swapping models is a trap: old vectors and the new model are not in one space, and adding new data cannot rescue the old data. The fix was a full rebuild of all chunks under the new model, not "rebuild only the added portion."

Branch B variant: Two vector versions mixed in the index — "incremental ingestion did not re-embed old data"

Signature: the cosine distribution is bimodal — some high (loaded by the new model), some low (leftover old-model vectors). The essence here: the index is not "all old" or "all new," but "half old, half new," so queries that hit an old vector collapse and queries that hit a new vector are fine, presenting as "flaky, randomly gets worse."

# See whether the golden-set cosine distribution is bimodal (a histogram shows it at a glance)
python3 - <<'PY'
import numpy as np
scores = [...]   # each golden item's cosine, from the previous section
hist, _ = np.histogram(scores, bins=20)
for b, c in zip(hist, np.linspace(scores.min(), scores.max(), 21)[:-1]):
    print(f'{b:.2f} | {"#"*int(c*3)}')
PY

A bimodal distribution makes the problem clear at once: two vector spaces are mixed in the index. Branching:

  • Clearly bimodal, with the low peak holding about half -> incremental ingestion only computed new documents; the old documents are still the old model. Fix: a full rebuild, or at least re-embed "the low-peak batch of chunks" under the new model.
  • Bimodal but the high peak dominates -> most is already rebuilt; a small batch of old vectors was never re-embedded. Fix: locate the low-peak chunks (usually the earliest-ingested ones) and top them up under the new model.
  • Unimodal but shifted low overall -> not mixed versions, it is Branch B's global drift; back to the previous section.

A tradeoff worth stating: "flaky, randomly gets worse" is the signature of "mixed versions in the index," and it is more confusing than "uniformly gets worse." A uniform drop can still be attributed to "we swapped the model," but a flaky drop sends the troubleshooter suspecting "network jitter" or "service instability." My localization move: pull a histogram of the golden-set cosines. A single peak, read the mean (global drift); a double peak, read the proportions (mixed versions) — one glance routes it.

Three Failure Postmortems (built from typical production scenarios)

Case 1: Swapped the model, changed only the query side, cosine collapsed overall (Branch A + B). To "improve quality," the team swapped the embedding from model A to B, changed the query side, left the index alone; three days later users reported "it answers the wrong thing." Golden-set average cosine 0.71 to 0.38. Fix: full rebuild. Lesson: when you swap the embedding model, the index must be rebuilt with it — a hard constraint of the vector space, not optional. The most expensive part was not the rebuild (two hours), it was the false assumption that "swap the model, tweak the query side, done."

Case 2: An incremental rebuild rescued only new documents; old documents still collapsed (the Branch B trap). After a model upgrade, the team "while at it" rebuilt only the new documents from the last three months and thought that was enough, so old-document queries were still inaccurate — the old documents' vectors were still in the old space. The incremental rebuild fixed only new data, not old data. Fix: a full rebuild of all chunks under the new model. Lesson: an "incremental rebuild" when swapping models is a trap; old vectors and the new model are not in one space, so it must be full.

Case 3: Two versions mixed in the index, bimodal cosines, flaky degradation (Branch B variant). Incremental ingestion only computed new documents, so the index held half old vectors and half new. Queries hitting the old ones collapsed, queries hitting the new ones were fine, presenting as "randomly gets worse," and the team even suspected network jitter. A histogram of the cosines showed the bimodal shape at a glance. Fix: locate the low-peak old chunks and top them up under the new model, or do a full rebuild. Lesson: "flaky, randomly gets worse" is the signature of "mixed versions," and it is more confusing than a uniform drop. Pull the cosine histogram — single peak, read the mean; double peak, read the proportions; one glance routes it.

Turning the Triage Into Standing Monitoring: A Drift Monitor You Can Ship

All three branches walked, and you cannot watch cosines by eye in production. My approach is to make "golden-query-set cosine" a permanent monitor that runs automatically on every ingestion or model change:

# Standing drift monitor (hooked on the ingestion / model-change hook)
def drift_monitor(golden, baseline_avg, threshold=0.10):
    scores = [cosine(query_embed(item['q']), fetch_chunk_vector(item['correct_chunk_id']))
              for item in golden]
    avg = float(np.mean(scores))
    top1 = float(np.mean([top1_hit(item['q']) for item in golden]))
    # Rule 1: average cosine drops more than threshold vs baseline -> drift alert
    if avg < baseline_avg * (1 - threshold):
        alert("embedding_drift", avg=avg, baseline=baseline_avg)
    # Rule 2: bimodal cosine distribution (abnormally high coefficient of variation) -> mixed-versions alert
    if np.std(scores) / (np.mean(scores) + 1e-9) > 0.35:
        alert("mixed_vector_versions", std_over_mean=float(np.std(scores)/np.mean(scores)))
    # Rule 3: dimension mismatch -> fail-fast immediately (Branch A)
    if len(query_embed(golden[0]['q'])) != len(fetch_chunk_vector(golden[0]['correct_chunk_id'])):
        raise ValueError("embedding dimension mismatch: query vs stored collection")
    return {"avg": avg, "top1": top1}

The thresholds are a starting point, not gospel: a "10 percent drop" is what I set for big changes like a model upgrade; ordinary small data updates can relax it. The "0.35" coefficient-of-variation floor for bimodality should be set to your golden set's natural variance. This monitor moves drift from "discovered after a user complaint" to "visible immediately after a change" — the cost is a few dozen extra queries per change (a few dozen seconds), far cheaper than shipping a broken index, getting user complaints, and then going back to troubleshoot.

The final independent judgment: the order of embedding-drift triage is "first confirm whether it is drift (cosine baseline comparison), then branch into which kind (dimension / global / mixed versions), and only then rebuild." Because the confirmation and the branching are both deterministic (the cosine does not lie, the histogram shows at a glance), while a "full rebuild" is the high-cost action (hours to a day). Putting the deterministic judgment first and the expensive rebuild last is what drops the cost of "one blind rebuild" to "one correct rebuild."


Originality statement: All cosine-computation scripts, the drift monitor, the decision tree, and the cases in this article are organized by the author from hands-on RAG operations. Cases are built from typical production scenarios and contain no real company names, IP addresses, or specific timelines. - Stale RAG Answers: A Layer-by-Layer Deci…