feat(rerank): portable score_threshold via opt-in score normalization - #3000
Open
chethanuk wants to merge 1 commit into
Open
feat(rerank): portable score_threshold via opt-in score normalization#3000chethanuk wants to merge 1 commit into
chethanuk wants to merge 1 commit into
Conversation
chethanuk
force-pushed
the
feat/rerank-portable-threshold
branch
from
July 4, 2026 02:57
ff07cb9 to
6139d51
Compare
Contributor
Author
|
Please review cc: @qin-ctx @ZaynJarvis @zhoujh01 @yufeng201 @chenjw - Please let me know if you require any changes, or if the project is currently accepting contributions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RerankConfig.thresholddefaults to0.1and is applied asscore > threshold. That assumes reranker scores live in[0, 1](VikingDB/Cohere) — but cross-encoder rerankers (BGE/MiniLM served via OpenAI-compatible / LiteLLM endpoints) return raw, unbounded logits, for which a fixed0.1threshold is meaningless (it filters almost everything or nothing depending on the model). The threshold is not portable across providers.Adds an opt-in
RerankConfig.normalize_scores(defaultFalse). When enabled, each reranker score is mapped through an overflow-safe logistic (sigmoid) into[0, 1]before thresholding and blending, so a threshold in[0, 1]means the same thing everywhere.How it works
flowchart TD A["rerank_batch → raw score per doc"] --> B{"normalize_scores?"} B -- "False (default) → parity" --> C["use raw score<br/>logit space, may be unbounded"] B -- "True (opt-in)" --> D["sigmoid(score) → [0, 1]<br/>overflow-safe, monotonic"] C --> E{"score > threshold"} D --> E E -- keep --> F["directory retained + blended"] E -- drop --> G["filtered out"]With
normalize_scores=Truethethresholdis portable in[0, 1]across providers; with it off,thresholdlives in the provider's native score space (bounded for VikingDB/Cohere, unbounded logits for logit-based cross-encoders).Why opt-in (not auto-detected)
Whether a reranker returns a logit or a probability is model-dependent, not provider-dependent — the same OpenAI-compatible endpoint can serve either. So there is no safe way to auto-detect it; normalization is an explicit switch. (Leave it off for providers that already return normalized
[0, 1]scores, or double-normalization distorts them.)Correctness
default=False= byte-identical parity with the prior_finite_score(score, fallback)loop across every branch (valid / NaN / non-finite / unparseable scores)._sigmoidis overflow-safe for extreme logits (±1000) — the exponent is always ≤ 0. Output is[0, 1]: endpoints are reachable for extreme logits via floating-point saturation.Field(default=False, strict=True);extra="forbid"keeps typos fatal.Tests / docs
Covers parity-off, sigmoid mapping, overflow safety, fallback-not-transformed, and config validation.
en+zhrerank-table rows added, threshold-range semantics documented for both normalization states.Review
Eight inline review-bot comments were triaged and independently verified. Valid ones fixed (sigmoid range wording
(0,1)→[0,1],normalize_scoresadded to the full-schema example, threshold-range docs, VikingDB double-normalize caveat); two over-reaching suggestions declined with rationale — a per-providerraise(contradicts the model-dependent design) and a hot-path sentinel refactor for an exact-0.0sigmoid output that requires a logit ≲ −745 (unreachable for real rerankers). No executable code changed by the review round.