-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Implement support for weighted rrf #130658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mridula-s109
merged 54 commits into
elastic:main
from
mridula-s109:SEARCH-1026-implement-support-for-weighted-rrf
Jul 31, 2025
+663
−69
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
8be20f0
RRFRetrieverComponent added:
mridula-s109 a8f6487
Modified parser, toXcontent and included component in the RetrieverBu…
mridula-s109 e07c38d
[CI] Auto commit changes from spotless
33d3da4
Resolved merge conflicts
mridula-s109 5fb5568
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 3ba149c
Fixed compile issues in tests
mridula-s109 d5749f6
[CI] Auto commit changes from spotless
7614936
trying to resolve parse errros
mridula-s109 a5d9e34
wip
ioanatia 0640099
Modified builder
mridula-s109 cec23c2
[CI] Auto commit changes from spotless
6da9e15
Removed unnecessary code
mridula-s109 51b350e
Fixed import
mridula-s109 4050a3a
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 ea664eb
Enhanced tests
mridula-s109 98e72be
Fixed the failing tests
mridula-s109 7de8c7a
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 c778dd2
Yaml tests were added
mridula-s109 c7b331d
Added cluster features to it
mridula-s109 f543cbe
Fixed spotless
mridula-s109 75ab8d0
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 f5086c1
Update docs/changelog/130658.yaml
mridula-s109 fafb50f
Fixed the relaxed constraints
mridula-s109 e535864
Resolving issues
mridula-s109 78f8641
Resolved PR comments
mridula-s109 02647b1
removed simplified rrf
mridula-s109 2010f3a
changed the test file back to its original state
mridula-s109 7433023
Resolved comments to have ahelper method and the test case to use it
mridula-s109 a2bf4de
made parsing robust
mridula-s109 eebf577
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 0388abd
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 74ed8db
IT test reverted
mridula-s109 6d7e8ff
Replaced the declareString array parser
mridula-s109 f1e14ce
Enforced weights as nonnull
mridula-s109 fd30387
Fixed the weights null
mridula-s109 3a82a28
Empty weight shouldnt be serialised
mridula-s109 77c14d3
[CI] Auto commit changes from spotless
45ca068
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 2e121b0
removed the hard coding
mridula-s109 d66f5a6
Cleanup and optimised the code flow
mridula-s109 532e7df
Fixed the comments
mridula-s109 184330c
[CI] Auto commit changes from spotless
c43a075
optimised test
mridula-s109 e5f8079
Added additional test
mridula-s109 65cc528
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 4ac4940
addressed the commentS
mridula-s109 e6f22bc
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 3fc0d35
Update docs/changelog/130658.yaml
mridula-s109 5c364a0
Explicit check for retriever object
mridula-s109 978e182
Resolved PR comments
mridula-s109 032e946
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 1d807ee
Fixed the error message
mridula-s109 7f4c7cd
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 99f4ad2
Merge branch 'main' into SEARCH-1026-implement-support-for-weighted-rrf
mridula-s109 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 130658 | ||
summary: Add support for weighted RRF in retrievers | ||
area: Relevance | ||
type: enhancement | ||
issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverComponent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.rank.rrf; | ||
|
||
import org.elasticsearch.common.ParsingException; | ||
import org.elasticsearch.search.retriever.RetrieverBuilder; | ||
import org.elasticsearch.search.retriever.RetrieverParserContext; | ||
import org.elasticsearch.xcontent.ParseField; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class RRFRetrieverComponent implements ToXContentObject { | ||
|
||
public static final ParseField RETRIEVER_FIELD = new ParseField("retriever"); | ||
public static final ParseField WEIGHT_FIELD = new ParseField("weight"); | ||
static final float DEFAULT_WEIGHT = 1f; | ||
|
||
final RetrieverBuilder retriever; | ||
final float weight; | ||
|
||
public RRFRetrieverComponent(RetrieverBuilder retrieverBuilder, Float weight) { | ||
this.retriever = Objects.requireNonNull(retrieverBuilder, "retrieverBuilder must not be null"); | ||
this.weight = weight == null ? DEFAULT_WEIGHT : weight; | ||
if (this.weight < 0) { | ||
throw new IllegalArgumentException("[weight] must be non-negative, found [" + this.weight + "]"); | ||
} | ||
mridula-s109 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public RetrieverBuilder retriever() { | ||
return retriever; | ||
} | ||
|
||
public float weight() { | ||
return weight; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContentObject.Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(RETRIEVER_FIELD.getPreferredName(), retriever); | ||
builder.field(WEIGHT_FIELD.getPreferredName(), weight); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public static RRFRetrieverComponent fromXContent(XContentParser parser, RetrieverParserContext context) throws IOException { | ||
mridula-s109 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (parser.currentToken() != XContentParser.Token.START_OBJECT) { | ||
throw new ParsingException(parser.getTokenLocation(), "expected object but found [{}]", parser.currentToken()); | ||
} | ||
|
||
// Peek at the first field to determine the format | ||
XContentParser.Token token = parser.nextToken(); | ||
if (token == XContentParser.Token.END_OBJECT) { | ||
throw new ParsingException(parser.getTokenLocation(), "retriever component must contain a retriever"); | ||
} | ||
if (token != XContentParser.Token.FIELD_NAME) { | ||
throw new ParsingException(parser.getTokenLocation(), "expected field name but found [{}]", token); | ||
} | ||
|
||
String firstFieldName = parser.currentName(); | ||
|
||
// Check if this is a structured component (starts with "retriever" or "weight") | ||
if (RETRIEVER_FIELD.match(firstFieldName, parser.getDeprecationHandler()) | ||
|| WEIGHT_FIELD.match(firstFieldName, parser.getDeprecationHandler())) { | ||
// This is a structured component - parse manually | ||
RetrieverBuilder retriever = null; | ||
Float weight = null; | ||
|
||
do { | ||
String fieldName = parser.currentName(); | ||
if (RETRIEVER_FIELD.match(fieldName, parser.getDeprecationHandler())) { | ||
if (retriever != null) { | ||
throw new ParsingException(parser.getTokenLocation(), "only one retriever can be specified"); | ||
} | ||
parser.nextToken(); | ||
if (parser.currentToken() != XContentParser.Token.START_OBJECT) { | ||
throw new ParsingException(parser.getTokenLocation(), "retriever must be an object"); | ||
} | ||
parser.nextToken(); | ||
String retrieverType = parser.currentName(); | ||
retriever = parser.namedObject(RetrieverBuilder.class, retrieverType, context); | ||
context.trackRetrieverUsage(retriever.getName()); | ||
parser.nextToken(); | ||
} else if (WEIGHT_FIELD.match(fieldName, parser.getDeprecationHandler())) { | ||
if (weight != null) { | ||
throw new ParsingException(parser.getTokenLocation(), "[weight] field can only be specified once"); | ||
} | ||
parser.nextToken(); | ||
weight = parser.floatValue(); | ||
} else { | ||
throw new ParsingException( | ||
parser.getTokenLocation(), | ||
"unknown field [{}], expected [{}] or [{}]", | ||
fieldName, | ||
RETRIEVER_FIELD.getPreferredName(), | ||
WEIGHT_FIELD.getPreferredName() | ||
); | ||
} | ||
} while (parser.nextToken() == XContentParser.Token.FIELD_NAME); | ||
|
||
if (retriever == null) { | ||
throw new ParsingException(parser.getTokenLocation(), "retriever component must contain a retriever"); | ||
} | ||
|
||
return new RRFRetrieverComponent(retriever, weight); | ||
} else { | ||
RetrieverBuilder retriever = parser.namedObject(RetrieverBuilder.class, firstFieldName, context); | ||
context.trackRetrieverUsage(retriever.getName()); | ||
if (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
throw new ParsingException(parser.getTokenLocation(), "unknown field [{}] after retriever", parser.currentName()); | ||
} | ||
return new RRFRetrieverComponent(retriever, DEFAULT_WEIGHT); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.