Skip to content

Commit 2894b2b

Browse files
authored
fix: replace noise-dominated retrieval assertion in test_full_pipeline (#967)
test_full_pipeline required all four top-4 retrieval slots to be programming documents. That is not a measurable property of a 0.6B embedding model at this corpus size, and the test has been failing since long before v1.12.1. The assertion's decision margin is the gap between the last programming doc and the first non-programming doc. On the shipped INT8 build, for the exact query this test uses: corpus[0] Python 0.5057 prog corpus[1] JavaScript 0.3159 prog corpus[3] SQL 0.2872 prog corpus[7] speed of light 0.2315 corpus[2] Rust 0.2286 prog <- loses its top-4 slot by 0.0029 So the whole assertion turns on 0.0029. Embedding the same corpus with the other shipped quantization of the same weights (Q4F16) moves these similarities by 0.089 on average and 0.13 at most. The assertion was roughly 30x below the model's own numerical noise floor: it was measuring the quantizer, not retrieval quality. Q4F16 passes the old assertion comfortably and INT8 does not, which is the symptom of a threshold set below the noise. This is a lowering of expectations, not a bug fix. The retrieval path is correct: query_embed does apply the Qwen3 instruction prefix, and it is byte-identical to embedding "Instruct: {task}\nQuery: {query}" by hand. Making the old assertion pass would have required removing that prefix, which contradicts the model card and would have made the library wrong in order to make a test green. The replacement keeps two claims that clear the noise floor by ~2x and hold on both shipped builds: - the most relevant document ranks first (margin 0.19) - programming docs outscore the rest as a group (gap 0.16, INT8) (gap 0.21, Q4F16) Both still have teeth. Swapping last-token pooling for first-token pooling flips the ranking to [4, 7, 5, 0, ...] and both assertions fail, so a real regression in this pipeline is still caught.
1 parent 35a525a commit 2894b2b

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

tests/test_integration.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,35 @@ def test_full_pipeline(self, embedding_model, reranker_model):
589589
# Stage 1: Dense retrieval (top-4 by cosine similarity)
590590
query_emb = list(embedding_model.query_embed(query))[0]
591591
doc_embs = list(embedding_model.embed(corpus))
592-
sims = [np.dot(query_emb, d) for d in doc_embs]
592+
sims = np.array([np.dot(query_emb, d) for d in doc_embs])
593593
top4_indices = np.argsort(sims)[-4:][::-1]
594594
top4_docs = [corpus[i] for i in top4_indices]
595595

596-
# All top-4 should be programming-related (indices 0-3)
597-
for idx in top4_indices:
598-
assert idx < 4, f"Non-programming doc (idx={idx}) in top-4 retrieval"
596+
# This test used to require every top-4 slot to be a programming doc
597+
# (indices 0-3). That claim is not measurable on a 0.6B model: its
598+
# decision margin is the gap between corpus[2] (0.2286) and corpus[7]
599+
# (0.2315), i.e. -0.003, while the two shipped quantizations of these
600+
# same weights disagree by 0.089 on average across these very
601+
# similarities. The assertion was ~30x below the model's own numerical
602+
# noise floor, so it measured quantization, not retrieval.
603+
#
604+
# The two claims below clear that floor by ~2x and hold on both the
605+
# INT8 and Q4F16 builds. Both flip to failing if last-token pooling
606+
# regresses, so they still detect a real break in this pipeline.
607+
608+
# The single most relevant document must rank first (margin ~0.19).
609+
assert top4_indices[0] == 0, (
610+
f"Expected the Python doc to rank first, got corpus[{top4_indices[0]}]: "
611+
f"{corpus[top4_indices[0]]!r} (similarities: {np.round(sims, 4).tolist()})"
612+
)
613+
614+
# Programming docs as a group must outscore the rest (gap ~0.16).
615+
prog_mean = float(sims[:4].mean())
616+
other_mean = float(sims[4:].mean())
617+
assert prog_mean - other_mean > 0.05, (
618+
f"Programming docs should score clearly above the rest, got "
619+
f"{prog_mean:.4f} vs {other_mean:.4f} (gap {prog_mean - other_mean:+.4f})"
620+
)
599621

600622
# Stage 2: Rerank top-4
601623
rerank_scores = list(reranker_model.rerank(query, top4_docs))

0 commit comments

Comments
 (0)