mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-05 18:38:17 -05:00
[PR #20228] [MERGED] fix: normalize local CrossEncoder reranking scores for relevance threshold #41143
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/20228
Author: @Classic298
Created: 12/28/2025
Status: ✅ Merged
Merged: 12/31/2025
Merged by: @tjbck
Base:
dev← Head:patch-1📝 Commits (6)
d3e4ceaUpdate utils.py2d9d0a2Update retrieval.py2555177Update utils.py039e73fUpdate retrieval.pyfc9620eadd env vard80be8brename to SENTENCE_TRANSFORMERS_CROSS_ENCODER_SIGMOID_ACTIVATION_FUNCTION📊 Changes
2 files changed (+14 additions, -0 deletions)
View changed files
📝
backend/open_webui/env.py(+7 -0)📝
backend/open_webui/routers/retrieval.py(+7 -0)📄 Description
Description:
Fix: Normalize local CrossEncoder reranking scores to 0-1 range
The relevance threshold setting (0-1 range in the UI) doesn't work correctly with local CrossEncoder reranking models because MS MARCO models (the most commonly used rerankers) return raw logits (roughly -10 to +10) instead of normalized scores. When a user sets a threshold of 0.5, practically everything passes because even poor matches score above 0.5 in logit space.
Solution: Pass
activation_fn=torch.nn.Sigmoid()to the CrossEncoder constructor. This is the approach recommended by the sentence-transformers documentation for MS MARCO models and has the following benefits:Source: https://www.sbert.net/docs/cross_encoder/pretrained_models.html
Edge case: Models that already output 0-1 scores (like STS-B) will have sigmoid applied twice, compressing their output range. However, STS-B models are designed for semantic similarity, not reranking and should not be used for reranking - in practice, reranking pipelines use MS MARCO or BGE models. Even if someone did use an STS-B model, ranking order is preserved (sigmoid is monotonic) and thresholds still function, just with compressed score magnitudes.
RE: https://github.com/open-webui/open-webui/discussions/19999
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.