fix: apply score threshold after reranking in hybrid search#35263
Merged
fatelei merged 2 commits intoApr 16, 2026
Conversation
The score threshold was applied to pre-rerank/fusion scores before the reranker ran. Documents with high reranked scores (0.84-0.96) were incorrectly filtered out because their pre-rerank scores were below the threshold. Move score threshold filtering to after the reranking step so it uses the final scores users see in the UI. Fixes langgenius#35233 Made-with: Cursor
fatelei
reviewed
Apr 16, 2026
…search Per reviewer feedback, set embedding_score_threshold to 0.0 rather than None when deferring threshold to post-rerank filtering. Made-with: Cursor
Contributor
Pyrefly DiffNo changes detected. |
fatelei
approved these changes
Apr 16, 2026
|
Hi, I am using Dify Cloud and tested this after the PR was merged but the behavior appears unchanged — score threshold is still being applied before reranking in hybrid search. Could you confirm whether this fix has been deployed to Dify Cloud, or if I need to wait for a specific release? Thanks. |
Contributor
yes, in next release |
HanqingZ
pushed a commit
to HanqingZ/dify
that referenced
this pull request
Apr 23, 2026
asukaminato0721
pushed a commit
to asukaminato0721/dify
that referenced
this pull request
Apr 24, 2026
6 tasks
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
Fixes #35233
In hybrid search with reranking enabled, the score threshold is applied to the pre-rerank/fusion score instead of the post-rerank score. This causes documents with high reranked scores (0.84-0.96) to be filtered out because their pre-rerank scores were below the threshold.
Root Cause
RetrievalService.embedding_searchpassesscore_thresholdto the vector DB query forHYBRID_SEARCH, which filters on pre-rerank similarity scores. After reranking produces new scores, the threshold-filtered results are already gone.Fix
HYBRID_SEARCH, passscore_threshold=Noneto the vector DB search step so no pre-filtering occursRerankModelRunner,WeightRerankRunner) apply the threshold to the final reranked/fused scoresMade with Cursor