Skip to content

Conversation

mridula-s109
Copy link
Contributor

@mridula-s109 mridula-s109 commented Jul 4, 2025

Implement support for weighted RRF

Summary

This PR implements support for weighted RRF (Reciprocal Rank Fusion) retrievers, allowing users to specify custom weights for each sub-retriever within an RRF retriever configuration. This addresses a common customer request to customize the influence of different retrievers in the RRF scoring process.

Core Implementation

  • Enhanced RRFRetrieverBuilder: Extended to support both weighted and non-weighted retriever configurations
  • New RRFRetrieverComponent: Added weight validation and handling for individual retrievers
  • Backward Compatibility: Maintains support for existing RRF configurations without weights (default weight = 1.0)

Key Features

1. Weighted Retriever Support

Users can now specify weights for individual retrievers:

{ "retriever": { "rrf": { "retrievers": [ { "retriever": { "standard": { "query": { "match": { "description": "pizza" } } } }, "weight": 0.7 }, { "retriever": { "knn": { "field": "vector", "query_vector": [1,2,3], "k": 10 } }, "weight": 0.3 } ] } } }
@mridula-s109 mridula-s109 marked this pull request as draft July 4, 2025 23:39
@Mikep86 Mikep86 self-requested a review July 15, 2025 13:32
@mridula-s109 mridula-s109 force-pushed the SEARCH-1026-implement-support-for-weighted-rrf branch from 7614936 to e7f0a90 Compare July 17, 2025 12:05
@mridula-s109 mridula-s109 force-pushed the SEARCH-1026-implement-support-for-weighted-rrf branch 5 times, most recently from f1eede5 to f5e1572 Compare July 17, 2025 16:56
@mridula-s109 mridula-s109 requested review from a team and removed request for a team July 17, 2025 16:59
@mridula-s109 mridula-s109 force-pushed the SEARCH-1026-implement-support-for-weighted-rrf branch from f1eede5 to 0640099 Compare July 17, 2025 17:05
@mridula-s109 mridula-s109 requested a review from Mikep86 July 28, 2025 17:54
@mridula-s109
Copy link
Contributor Author

@ioanatia have addressed all the comments. please let me know if there are any more concerns.

@mridula-s109 mridula-s109 requested a review from ioanatia July 29, 2025 11:19
Copy link
Contributor

@ioanatia ioanatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is getting super close! thank you for your patience 🙇‍♀️

@mridula-s109 mridula-s109 requested a review from ioanatia July 31, 2025 10:09
Copy link
Contributor

@ioanatia ioanatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@mridula-s109 mridula-s109 enabled auto-merge (squash) July 31, 2025 10:48
Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work!

@mridula-s109 mridula-s109 merged commit fc0ea64 into elastic:main Jul 31, 2025
33 checks passed
smalyshev pushed a commit to smalyshev/elasticsearch that referenced this pull request Jul 31, 2025
* RRFRetrieverComponent added: * Modified parser, toXcontent and included component in the RetrieverBuilder * [CI] Auto commit changes from spotless * Resolved merge conflicts * Fixed compile issues in tests * [CI] Auto commit changes from spotless * trying to resolve parse errros * wip * Modified builder * [CI] Auto commit changes from spotless * Removed unnecessary code * Fixed import * Enhanced tests * Fixed the failing tests * Yaml tests were added * Added cluster features to it * Fixed spotless * Update docs/changelog/130658.yaml * Fixed the relaxed constraints * Resolving issues * Resolved PR comments * removed simplified rrf * changed the test file back to its original state * Resolved comments to have ahelper method and the test case to use it * made parsing robust * IT test reverted * Replaced the declareString array parser * Enforced weights as nonnull * Fixed the weights null * Empty weight shouldnt be serialised * [CI] Auto commit changes from spotless * removed the hard coding * Cleanup and optimised the code flow * Fixed the comments * [CI] Auto commit changes from spotless * optimised test * Added additional test * addressed the commentS * Update docs/changelog/130658.yaml Co-authored-by: Liam Thompson <leemthompo@gmail.com> * Explicit check for retriever object * Resolved PR comments * Fixed the error message --------- Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co> Co-authored-by: Ioana Tagirta <ioana.tagirta@elastic.co> Co-authored-by: Liam Thompson <leemthompo@gmail.com>
@flobernd
Copy link
Member

flobernd commented Oct 17, 2025

Edit: nvm, the old syntax seems to be still valid.

@mridula-s109 @leemthompo Hey folks. Just double checking here. Judging from the provided JSON example, this seems to be a breaking change since the structure now includes a new nesting:

{ "retriever": { "rrf": { "retrievers": [ { // <- Retriever container "standard": { "query": { "match": { "description": "pizza" } } } },

to

{ "retriever": { "rrf": { "retrievers": [ { // <- New RRFRetrieverComponent class that wraps `retriever` and `weigth` "retriever": { "standard": { "query": { "match": { "description": "pizza" } } } }, "weight": 0.7 },

Is this expected to ship in a minor version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search - Relevance The Search organization Search Relevance team Team:SearchOrg Meta label for the Search Org (Enterprise Search) v9.2.0

6 participants