Confusion about weighted rerank #12308

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

Originally created by @bohaocheung on GitHub (Mar 28, 2025).

Originally posted by @bohaocheung in #17048

I am still confused.
There are 2 rerank ways: One is using specific reranking model whose input is query full text and output is document.metadata["score"].
Another is keyword and vector weighted hybrid reranking, which I talked in this issue exactly. In this condition, I think the code confused the meaning of document.metadata["score"].

Originally created by @bohaocheung on GitHub (Mar 28, 2025). _Originally posted by @bohaocheung in [#17048](https://github.com/langgenius/dify/issues/17048#issuecomment-2760779994)_ > I am still confused. > There are 2 rerank ways: One is using specific reranking model whose input is query full text and output is `document.metadata["score"]`. > Another is keyword and vector weighted hybrid reranking, which I talked in this issue exactly. In this condition, I think the code confused the meaning of `document.metadata["score"]`.
yindo closed this issue 2026-02-21 19:06:50 -05:00
Author
Owner

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

The confusion seems to stem from the different uses of document.metadata["score"] in the two reranking methods:

  1. Specific Reranking Model: This method uses a pre-calculated score stored in document.metadata["score"]. The score is generated by a specific reranking model that processes the full query text and outputs a score for each document. This score is then used directly for ranking the documents.

  2. Keyword and Vector Weighted Hybrid Reranking: In this approach, document.metadata["score"] is dynamically calculated as a weighted sum of keyword and vector scores. The keyword score is based on TF-IDF-like calculations, while the vector score is based on cosine similarity between query and document vectors. The combined score is stored in document.metadata["score"] and used for reranking [1].

The key difference is that the specific reranking model relies on pre-existing scores, while the hybrid method calculates scores dynamically based on the current query and document content.

To continue talking to Dosu, mention @dosu.


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

@dosubot[bot] commented on GitHub (Mar 28, 2025): <!-- Answer --> The confusion seems to stem from the different uses of `document.metadata["score"]` in the two reranking methods: 1. **Specific Reranking Model**: This method uses a pre-calculated score stored in `document.metadata["score"]`. The score is generated by a specific reranking model that processes the full query text and outputs a score for each document. This score is then used directly for ranking the documents. 2. **Keyword and Vector Weighted Hybrid Reranking**: In this approach, `document.metadata["score"]` is dynamically calculated as a weighted sum of keyword and vector scores. The keyword score is based on TF-IDF-like calculations, while the vector score is based on cosine similarity between query and document vectors. The combined score is stored in `document.metadata["score"]` and used for reranking <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/rag/rerank/weight_rerank.py)</sup>. The key difference is that the specific reranking model relies on pre-existing scores, while the hybrid method calculates scores dynamically based on the current query and document content. <!-- 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/3306aacc-8599-44d9-953e-35abb1923149?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/3306aacc-8599-44d9-953e-35abb1923149?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/3306aacc-8599-44d9-953e-35abb1923149?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/3306aacc-8599-44d9-953e-35abb1923149?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3306aacc-8599-44d9-953e-35abb1923149?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/3306aacc-8599-44d9-953e-35abb1923149?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3306aacc-8599-44d9-953e-35abb1923149?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12308