Parent Child (full doc) + Reranking does not seem right #8161

Closed
opened 2026-02-21 18:24:16 -05:00 by yindo · 3 comments
Owner

Originally created by @DavideDelbianco on GitHub (Feb 11, 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

0.15.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Create a KB using parent child in full doc mode and use hybrid search with cohere rerank model (jina is the same) using weaviate as vector DB

✔️ Expected Behavior

I would expect the TopK parameter to return the top X results after the rerank model reordered them
I would expect the score threshold to apply consistently

Actual Behavior

If I set a threshold of 0.77 I see the top 3 docs with 0.77+
Image

If I set 0.78 one of the docs with 0.78 disappears

Image

If I set TopK 10 a document with better score appear
Image

but applying a threshold that this document would surpass, makes it disappear
Image

Seems like the reordering is being done in reverse ?_?

Originally created by @DavideDelbianco on GitHub (Feb 11, 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 0.15.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Create a KB using parent child in full doc mode and use hybrid search with cohere rerank model (jina is the same) using weaviate as vector DB ### ✔️ Expected Behavior I would expect the TopK parameter to return the top X results after the rerank model reordered them I would expect the score threshold to apply consistently ### ❌ Actual Behavior If I set a threshold of 0.77 I see the top 3 docs with 0.77+ ![Image](https://github.com/user-attachments/assets/298ba319-bde7-4cb3-9fb7-e1d7c4da3651) If I set 0.78 one of the docs with 0.78 disappears ![Image](https://github.com/user-attachments/assets/ec85d985-61f4-449a-9512-de51e15da5ff) If I set TopK 10 a document with better score appear ![Image](https://github.com/user-attachments/assets/f63ffc79-481b-449d-bdd2-eeece505cea3) but applying a threshold that this document would surpass, makes it disappear ![Image](https://github.com/user-attachments/assets/76e8679c-deb3-4740-ab8c-ce7b47e453d6) Seems like the reordering is being done in reverse ?_?
yindo added the 🐞 bug👻 feat:rag labels 2026-02-21 18:24:16 -05:00
yindo closed this issue 2026-02-21 18:24:16 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 11, 2025):

I found two similar discussions that might be relevant to your issue:

  1. Doubt about the topk and threshold usage in rerank stage settings - This discussion is unsolved and might provide insights into how the TopK and score threshold parameters are expected to work in the rerank stage [1].

  2. Is the current integration of the embedding model and the reranking model not quite optimal? - This is another unsolved discussion that questions the integration of the embedding model with the reranking model, which might relate to the behavior you're observing [2].

Regarding your issue, the rerank model should sort documents based on their scores in descending order, as indicated by the code snippet:

rerank_documents.sort(key=lambda x: x.score, reverse=True)

This means higher scores should appear first [3]. If you're observing behavior that suggests the ordering is reversed, it might be worth checking if there are any specific conditions or configurations affecting this process. Additionally, the score threshold logic ensures that only documents with scores above the threshold are included:

if score_threshold is None or normalized_score >= score_threshold:
    rerank_documents.append(rerank_document)

This logic should consistently apply the threshold during the rerank process [4]. If documents are disappearing unexpectedly, it might be due to how scores are being normalized or calculated.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Feb 11, 2025): <!-- Answer --> I found two similar discussions that might be relevant to your issue: 1. [Doubt about the topk and threshold usage in rerank stage settings](https://github.com/langgenius/dify/discussions/3171) - This discussion is unsolved and might provide insights into how the TopK and score threshold parameters are expected to work in the rerank stage <sup>[[1]](https://github.com/langgenius/dify/discussions/3171)</sup>. 2. [Is the current integration of the embedding model and the reranking model not quite optimal?](https://github.com/langgenius/dify/discussions/3772) - This is another unsolved discussion that questions the integration of the embedding model with the reranking model, which might relate to the behavior you're observing <sup>[[2]](https://github.com/langgenius/dify/discussions/3772)</sup>. Regarding your issue, the rerank model should sort documents based on their scores in descending order, as indicated by the code snippet: ```python rerank_documents.sort(key=lambda x: x.score, reverse=True) ``` This means higher scores should appear first <sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/azure_ai_studio/rerank/rerank.py)</sup>. If you're observing behavior that suggests the ordering is reversed, it might be worth checking if there are any specific conditions or configurations affecting this process. Additionally, the score threshold logic ensures that only documents with scores above the threshold are included: ```python if score_threshold is None or normalized_score >= score_threshold: rerank_documents.append(rerank_document) ``` This logic should consistently apply the threshold during the rerank process <sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai_api_compatible/rerank/rerank.py)</sup>. If documents are disappearing unexpectedly, it might be due to how scores are being normalized or calculated. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/d1c25346-0ae8-499b-981c-eff3822ec747?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/d1c25346-0ae8-499b-981c-eff3822ec747?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/d1c25346-0ae8-499b-981c-eff3822ec747?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/d1c25346-0ae8-499b-981c-eff3822ec747?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d1c25346-0ae8-499b-981c-eff3822ec747?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/d1c25346-0ae8-499b-981c-eff3822ec747?feedback_type=other)</sup>
Author
Owner

@DavideDelbianco commented on GitHub (Feb 11, 2025):

It seems to me that TopK increases the number of child chunks evaluated to give a median score to the parent.
The more you allow the more accurate the score is.
Applying a threshold discards low-rank child chunks and gives a wrong median value for parent.

I think the Parent-Child when set in full-doc mode should first score every child of a parent, then use the median score to keep TopK number or parents.
Same goes for threshold, it should be applied to the median score of the parent and not used to filter child chunks.

This way full-doc mode would give accurate results
The way it seems to work right now is ok in paragraph mode where you want to keep relevant paragraphs only

@DavideDelbianco commented on GitHub (Feb 11, 2025): It seems to me that TopK increases the number of child chunks evaluated to give a median score to the parent. The more you allow the more accurate the score is. Applying a threshold discards low-rank child chunks and gives a wrong median value for parent. I think the Parent-Child when set in full-doc mode should first score every child of a parent, then use the median score to keep TopK number or parents. Same goes for threshold, it should be applied to the median score of the parent and not used to filter child chunks. This way full-doc mode would give accurate results The way it seems to work right now is ok in paragraph mode where you want to keep relevant paragraphs only
Author
Owner

@dosubot[bot] commented on GitHub (Mar 14, 2025):

Hi, @DavideDelbianco. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported an issue with the parent-child full document mode and reranking in a self-hosted Dify setup.
  • Documents that should meet the score threshold disappear, while others with better scores appear inconsistently.
  • I suggested checking the reranking logic and potential issues with score normalization or calculation.
  • You clarified that the TopK parameter affects the evaluation of child chunks, suggesting a discrepancy in the intended behavior for full-doc mode.

Next Steps:

  • Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting on this issue.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Mar 14, 2025): Hi, @DavideDelbianco. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported an issue with the parent-child full document mode and reranking in a self-hosted Dify setup. - Documents that should meet the score threshold disappear, while others with better scores appear inconsistently. - I suggested checking the reranking logic and potential issues with score normalization or calculation. - You clarified that the TopK parameter affects the evaluation of child chunks, suggesting a discrepancy in the intended behavior for full-doc mode. **Next Steps:** - Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting on this issue. - If there is no further activity, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8161