Weighted reranking ignores an enabled zero score threshold
- Dominant language
- TypeScript
- Stars
- 156k
- Forks
- 24.6k
- Avg merge
- 22h 9m
- Merged PRs (30d)
- 610
Description
### Self Checks
- [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542).
- [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general).
- [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
### Dify version
Current `main` at `02f9b3ca7c109fe1b0d5e26a8d553659e5e1e78e`.
### Cloud or Self Hosted
Self Hosted (Source)
### Steps to reproduce
1. Configure high-quality knowledge retrieval to use hybrid search and weighted-score reranking.
2. Enable score-threshold filtering and set the threshold to `0`.
3. Retrieve a query/document pair whose combined weighted score is negative, for example a keyword score of `0` and cosine similarity of `-0.5` with vector weight `1`.
4. Inspect the returned results.
`WeightRerankRunner.run()` checks `if score_threshold and score < score_threshold`. Because `0.0` is false in Python, the negative-score document is retained.
### ✔️ Expected Behavior
An enabled threshold of `0` should remove documents whose weighted score is below `0`, while retaining documents at score `0`. Disabling the threshold should remain distinct from enabling it with value `0`.
### ❌ Actual Behavior
The enabled zero threshold skips filtering and returns negative-score documents. Several production callers also encode a disabled threshold as `0.0`, so changing only the runner condition would incorrectly enable filtering for those callers. The disabled state needs to remain `None` through the retrieval pipeline.
I reproduced this on current `main` with focused tests covering weighted reranking and its production retrieval boundaries. The regression fails on the original implementation and passes when only `None` means disabled, while `0.0` remains an active threshold. The tested patch preserves the existing vector-database boundary behavior and reuses Dify's optional threshold representation.
If this direction is acceptable, please assign the issue to me so I can submit the tested patch.
AI disclosure: I used Codex to help trace the production paths, build the reproduction, and draft this report. I reviewed the findings, patch, and tests and am responsible for this report.
Contributor guide
Research direction
Start at WeightRerankRunner.run() and trace the weighted reranking threshold through the retrieval pipeline, including the production retrieval boundaries mentioned in the report. Run the focused weighted-reranking and retrieval-boundary tests; done means an enabled 0.0 threshold filters negative scores while disabled thresholds remain distinct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100