When elasticsearch is used as the vector database, the Retrieval Test fails to filter the data after setting the Score Threshold, and the score of the recalled results is empty #14370

Closed
opened 2026-02-21 19:16:57 -05:00 by yindo · 1 comment
Owner

Originally created by @zhaobingshuang on GitHub (Jun 2, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.3.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Before setting the Score Threshold
Image

After setting the Score Threshold to 0.74
Image

When elasticsearch is used as the vector database, the Retrieval Test fails to filter the data after setting the Score Threshold, and the score of the recalled results is empty

✔️ Expected Behavior

Image

Actual Behavior

Image

Originally created by @zhaobingshuang on GitHub (Jun 2, 2025). ### Self Checks - [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 (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.3.1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce Before setting the Score Threshold ![Image](https://github.com/user-attachments/assets/453ffec6-bc96-45e0-9434-ce723b0a74a0) After setting the Score Threshold to 0.74 ![Image](https://github.com/user-attachments/assets/339d836e-8101-4b07-96f3-22feb0aa034c) When elasticsearch is used as the vector database, the Retrieval Test fails to filter the data after setting the Score Threshold, and the score of the recalled results is empty ### ✔️ Expected Behavior ![Image](https://github.com/user-attachments/assets/c4999a6e-857c-4288-9337-48fcc61f7fd5) ### ❌ Actual Behavior ![Image](https://github.com/user-attachments/assets/339d836e-8101-4b07-96f3-22feb0aa034c)
yindo added the 🐞 bug👻 feat:rag labels 2026-02-21 19:16:57 -05:00
yindo closed this issue 2026-02-21 19:16:57 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 2, 2025):

Your issue with Elasticsearch as the vector database—where the Retrieval Test fails to filter data after setting the Score Threshold and the recalled results have empty scores—matches known behavior in Dify.

The root cause is in the implementation of the ElasticSearchVector class, specifically the search_by_vector method. This method retrieves documents and their scores from Elasticsearch, but the way it handles the score threshold is not as strict as you might expect. Instead of filtering out documents below the threshold, it attaches the score as metadata only if the score exceeds the threshold, but still returns all documents regardless of their score. This means you may see results with empty or missing scores even after setting a threshold, and the filtering you expect does not occur at this layer. If strict filtering is required, it needs to be implemented either by modifying this method or by post-processing the results at a higher layer in your application logic. See the relevant code and explanation here.

Another common cause for empty scores is the configuration of the retrieval model. If the score_threshold_enabled parameter is set to false, the scoring mechanism is not enabled, and scores will not be calculated or returned. If it is set to true but the score_threshold value is missing or null, the default may also be null, resulting in missing scores. Double-check your retrieval model configuration to ensure both score_threshold_enabled is true and a valid score_threshold value is set. More details on this configuration issue are discussed here.

If you are using the UI to set the score threshold, ensure that the input component allows float values between 0 and 1. There have been bugs where only 0 or 1 were accepted, which would prevent proper thresholding. The UI should allow values like 0.74, with a default of 0.7 and a step of 0.01. If you suspect a UI bug, check the implementation in RetrievalSettings.tsx and score-threshold-item.tsx as described here.

In summary: the current Elasticsearch integration in Dify does not strictly filter out results below the score threshold, and configuration issues can also result in empty scores. You may need to adjust your retrieval logic or post-process results to enforce strict threshold filtering.

To reply, just mention my name @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jun 2, 2025): <!-- Answer --> Your issue with Elasticsearch as the vector database—where the Retrieval Test fails to filter data after setting the Score Threshold and the recalled results have empty scores—matches known behavior in Dify. The root cause is in the implementation of the `ElasticSearchVector` class, specifically the `search_by_vector` method. This method retrieves documents and their scores from Elasticsearch, but the way it handles the score threshold is not as strict as you might expect. Instead of filtering out documents below the threshold, it attaches the score as metadata only if the score exceeds the threshold, but still returns all documents regardless of their score. This means you may see results with empty or missing scores even after setting a threshold, and the filtering you expect does not occur at this layer. If strict filtering is required, it needs to be implemented either by modifying this method or by post-processing the results at a higher layer in your application logic. See the relevant code and explanation [here](https://github.com/langgenius/dify/blob/c29cb503beb3d1b440a7faef680ddadff4be5ecd/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py). Another common cause for empty scores is the configuration of the retrieval model. If the `score_threshold_enabled` parameter is set to `false`, the scoring mechanism is not enabled, and scores will not be calculated or returned. If it is set to `true` but the `score_threshold` value is missing or null, the default may also be null, resulting in missing scores. Double-check your retrieval model configuration to ensure both `score_threshold_enabled` is `true` and a valid `score_threshold` value is set. More details on this configuration issue are discussed [here](https://github.com/langgenius/dify/issues/13284). If you are using the UI to set the score threshold, ensure that the input component allows float values between 0 and 1. There have been bugs where only 0 or 1 were accepted, which would prevent proper thresholding. The UI should allow values like 0.74, with a default of 0.7 and a step of 0.01. If you suspect a UI bug, check the implementation in `RetrievalSettings.tsx` and `score-threshold-item.tsx` as described [here](https://github.com/langgenius/dify/issues/15959). In summary: the current Elasticsearch integration in Dify does not strictly filter out results below the score threshold, and configuration issues can also result in empty scores. You may need to adjust your retrieval logic or post-process results to enforce strict threshold filtering. <!-- Dosu Comment Footer --> *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/f24146fe-026e-4a54-9901-ea7e90e447c3?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/f24146fe-026e-4a54-9901-ea7e90e447c3?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/f24146fe-026e-4a54-9901-ea7e90e447c3?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/f24146fe-026e-4a54-9901-ea7e90e447c3?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f24146fe-026e-4a54-9901-ea7e90e447c3?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/f24146fe-026e-4a54-9901-ea7e90e447c3?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/f24146fe-026e-4a54-9901-ea7e90e447c3?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/20560)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14370