← Back to all articles

Why Qwen3-Reranker-0.6B Hits Only 20.8% Strict Calibration on Financial Traps — And How We Built a Clean-Room 98.3% Fix + 5.4ms ONNX Drop-In

If you build production RAG over financial filings or statutory law, ranking the right chunk #1 isn't...

#RAG#Reranker#ONNX#VeriCorpus
Links & cross-posts: DEV.to ↗ GitHub ↗
On this page

If you build production RAG over financial filings or statutory law, ranking the right chunk #1 isn’t enough. Your reranker also needs calibrated separation so the pipeline knows when to answer vs. refuse.

When we evaluated stock Qwen/Qwen3-Reranker-0.6B on 240 zero-leakage held-out groups (across 19 unseen entities covering SEC filings and PRC statutes), we ran into a nasty failure mode:

  • Top-1 Accuracy looked decent (86.25%),
  • Mean positive probability was 0.9851,
  • Yet mean negative probability on wrong-caliber traps was 0.5621!

That meant a standard production gating rule (positive >= 0.70 AND all negatives <= 0.30, which we call StrictCal) passed on only 20.83% of groups — and 0.00% across all five financial caliber traps (consolidated_vs_parent, gaap_vs_nongaap, summary_vs_footnote, single_quarter_vs_cumulative, and cross_fiscal_year).

When a reranker scores both "FY2024 GAAP diluted EPS" and "FY2024 Non-GAAP adjusted EPS" above 0.85, an LLM downstream will happily blend the two numbers.

Today we’re open-sourcing two small, clean-room bilingual (ZH-Hans / ZH-Hant / EN) models on Hugging Face to solve both halves of the stack:

  1. Stage-1 Retriever (MIT): wasabihu/xerj-bilingual-fin-law-384
  2. Stage-2 Reranker (Apache-2.0): wasabihu/VeriCorpus-Reranker-0.6B

Both ship with full programmatic provenance audits (CLEAN_ROOM_AUDIT.json + SHA256SUMS.txt: 0 CNINFO, 0 HKEX, 0 proprietary records, and zero entity/doc/query train-eval leakage) alongside our benchmark repo wasabihu/vericorpus.


Part 1: Fixing Stage-1 Prefix Mismatch & ONNX Parity (5.42 ms/q on CPU)

Many Rust/C++ search engines — including XERJ (v1.0.0-rc.105+) — run local embeddings directly over raw document and query text with pad_token_id=0, attention-mask mean pooling, and L2 normalization, without injecting E5-style "query: " / "passage: " prefixes.

Running stock intfloat/multilingual-e5-small prefix-free drops Recall@1 sharply (52.48% on our 606-query held-out blind split), especially on Traditional Chinese queries and Arabic-numeral statute references (《會計法》第147條 vs 《会计法》第一百四十七条).

We fine-tuned xerj-bilingual-fin-law-384 strictly prefix-free on 2,751 audited triplets and verified three formats against the exact XERJ [batch, seq, 384] FP32 I/O wire contract:

Artifact Size Format Cosine vs FP32 (mean / min) R@1 Drop Live CPU Latency in XERJ
model.safetensors 448.8 MB PyTorch / Candle reference 0.00pp 20.44 ms/q
onnx/model.onnx 448.44 MB FP32 (opset 17) 1.000000 / 0.9999999 0.00pp 5.42 ms/q
onnx/model_fp16_io32.onnx 224.38 MB (2.00× smaller) FP16 weights, FP32 I/O 0.999998 / 0.999996 0.00pp 8.86 ms/q

Why we rejected Dynamic INT8

We also exported QUInt8/QInt8 ONNX variants — and threw them away. Cosine similarity vs FP32 dropped to 0.955–0.966, failing our strict 0.995 parity gate. Keeping weights in FP16 with keep_io_types=True (FP32 last_hidden_state) cut the file size in half while keeping 0.999998 mean cosine and 0.00pp Recall@1 loss.

Live Isolated XERJ v1.0.0-rc.105 Results (150 Stratified Queries, 238 Passages)

Mode R@1 R@5 R@10 MRR@10 Arabic Statute (n=20) Trad. CJK (n=34) SEC Filing (n=50) Latency
lexical (semantic_text) 39.33% 63.33% 76.00% 0.4980 60.00% 5.88% 14.00% 0.67 ms/q
bm25_xerj_cjk (#3377 CJK + T→S) 82.00% 96.00% 100.00% 0.8876 80.00% 97.06% 88.00% 0.89 ms/q
proxy_onnx (onnx/model.onnx FP32) 89.33% 98.00% 99.33% 0.9367 100.00% 97.06% 100.00% 5.42 ms/q
Native hybrid RRF (1:1.5, FP32 ONNX) 92.00% 100.00% 100.00% 0.9539 100.00% 97.06% 100.00% 5.96 ms/q

On the full 606-query held-out blind evaluation (6 unseen statutes, 11 unseen SEC tickers, 14 unseen clinical docs), offline Recall@1 jumped from 52.48% to 81.52% (+29.04pp), and live XERJ hybrid RRF (1:1.5) hit 99.17% Recall@10 — feeding nearly clean candidate sets into Stage 2.


Part 2: Calibrating Stage-2 Reranking (20.83% → 98.33% StrictCal)

To force Qwen3-Reranker-0.6B to reject plausible near-miss traps cleanly instead of hovering around 0.50–0.85, we combined:

  1. Groupwise Listwise InfoNCE (ranking the true caliber passage above hard negatives from the same entity/statute),
  2. Pointwise Binary Cross-Entropy directly on logit("yes") - logit("no") (pushing positives toward 1.0 and caliber traps toward 0.0), and
  3. Soft-score distillation from Qwen/Qwen3-32B-AWQ (Apache-2.0).

Crucially, we preserved the exact Qwen3-Reranker inference contract — left-padding, <Instruct> / <Query> / <Document> formatting, tail-only truncation of <Document>, and the <think>\n\n</think>\n\n assistant suffix — so any existing Qwen3-Reranker serving code can swap the model ID with zero changes.

Held-Out Blind Evaluation (240 Groups, 19 Unseen Entities, 0/0/0/0 Leakage)

Trap Category Groups (n) Base Top-1 Tuned Top-1 Base StrictCal Tuned StrictCal Base Margin Tuned Margin
consolidated_vs_parent 6 33.33% 100.00% 0.00% 100.00% -0.0024 +0.9994
gaap_vs_nongaap 8 50.00% 100.00% 0.00% 100.00% +0.0130 +1.0000
summary_vs_footnote 23 60.87% 100.00% 0.00% 95.65% -0.0022 +0.9358
single_quarter_vs_cumulative 17 70.59% 100.00% 0.00% 94.12% -0.0011 +0.9297
cross_fiscal_year 42 78.57% 100.00% 0.00% 100.00% +0.0091 +0.9971
statute_article_trap 144 98.61% 100.00% 34.72% 98.61% +0.3422 +0.9765
Overall 240 86.25% 100.00% 20.83% 98.33% +0.2070 +0.9743

Mean negative probability dropped from 0.5621 → 0.0065, while mean positive probability climbed from 0.9851 → 0.9938.

(Transparency note: enforcing strict entity-level separation leaves consolidated_vs_parent at n=6 and gaap_vs_nongaap at n=8 in this blind split; we publish exact n and CLEAN_ROOM_AUDIT.json so you can verify and test on your own filings.)


Try It Locally in 10 Lines

Stage-1 ONNX (onnxruntime, exact XERJ mean-pool + L2-norm)

import numpy as np
import onnxruntime as ort
from tokenizers import Tokenizer

sess = ort.InferenceSession("xerj-bilingual-fin-law-384/onnx/model.onnx", providers=["CPUExecutionProvider"])
tok = Tokenizer.from_file("xerj-bilingual-fin-law-384/tokenizer.json")
tok.enable_padding(pad_id=0, pad_token="[PAD]")
tok.enable_truncation(max_length=512)

def encode(texts: list[str]) -> np.ndarray:
    encs = tok.encode_batch(texts)  # Raw prefix-free text
    ids = np.array([e.ids for e in encs], dtype=np.int64)
    mask = np.array([e.attention_mask for e in encs], dtype=np.int64)
    hidden = sess.run(["last_hidden_state"], {"input_ids": ids, "attention_mask": mask, "token_type_ids": np.zeros_like(ids)})[0]
    mf = mask[..., None].astype(np.float32)
    pooled = (hidden * mf).sum(axis=1) / np.maximum(mf.sum(axis=1), 1e-9)
    return pooled / np.maximum(np.linalg.norm(pooled, axis=1, keepdims=True), 1e-12)

If you run bilingual RAG over filings, statutes, or contracts and want to test other domain traps (e.g. restatements, effective-date amendments, or multi-currency tables), drop a comment below.

Discussion & Feedback Join the discussion or share feedback on GitHub Discussions →