-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Simplified RRF Retriever #129659
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
base: main
Are you sure you want to change the base?
Simplified RRF Retriever #129659
Changes from all commits
34040c9
041e4f3
488ecf5
d2c439f
337e17d
ff29ab8
d2138e9
88d13da
55bbdf8
79afadf
2611ff5
09aab96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 129659 | ||
summary: Simplified RRF Retriever | ||
area: Search | ||
type: enhancement | ||
issues: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import org.elasticsearch.action.search.SearchRequest; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
import org.elasticsearch.search.retriever.CompoundRetrieverBuilder; | ||
import org.elasticsearch.search.retriever.RetrieverBuilder; | ||
import org.elasticsearch.search.retriever.RetrieverParserContext; | ||
import org.elasticsearch.search.retriever.TestRetrieverBuilder; | ||
|
@@ -45,13 +46,22 @@ public static RRFRetrieverBuilder createRandomRRFRetrieverBuilder() { | |
if (randomBoolean()) { | ||
rankConstant = randomIntBetween(1, 1000000); | ||
} | ||
var ret = new RRFRetrieverBuilder(rankWindowSize, rankConstant); | ||
|
||
List<String> fields = null; | ||
String query = null; | ||
if (randomBoolean()) { | ||
fields = randomList(1, 10, () -> randomAlphaOfLengthBetween(1, 10)); | ||
query = randomAlphaOfLengthBetween(1, 10); | ||
} | ||
|
||
int retrieverCount = randomIntBetween(2, 50); | ||
List<CompoundRetrieverBuilder.RetrieverSource> innerRetrievers = new ArrayList<>(retrieverCount); | ||
while (retrieverCount > 0) { | ||
ret.addChild(TestRetrieverBuilder.createRandomTestRetrieverBuilder()); | ||
innerRetrievers.add(CompoundRetrieverBuilder.RetrieverSource.from(TestRetrieverBuilder.createRandomTestRetrieverBuilder())); | ||
--retrieverCount; | ||
} | ||
return ret; | ||
|
||
return new RRFRetrieverBuilder(innerRetrievers, fields, query, rankWindowSize, rankConstant); | ||
} | ||
|
||
@Override | ||
|
@@ -94,28 +104,32 @@ protected NamedXContentRegistry xContentRegistry() { | |
} | ||
|
||
public void testRRFRetrieverParsing() throws IOException { | ||
String restContent = "{" | ||
+ " \"retriever\": {" | ||
+ " \"rrf\": {" | ||
+ " \"retrievers\": [" | ||
+ " {" | ||
+ " \"test\": {" | ||
+ " \"value\": \"foo\"" | ||
+ " }" | ||
+ " }," | ||
+ " {" | ||
+ " \"test\": {" | ||
+ " \"value\": \"bar\"" | ||
+ " }" | ||
+ " }" | ||
+ " ]," | ||
+ " \"rank_window_size\": 100," | ||
+ " \"rank_constant\": 10," | ||
+ " \"min_score\": 20.0," | ||
+ " \"_name\": \"foo_rrf\"" | ||
+ " }" | ||
+ " }" | ||
+ "}"; | ||
String restContent = """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we parse this twice, once with retrievers and once with field/query? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is only for XContent parsing purposes, the resulting retriever does not need to pass |
||
{ | ||
"retriever": { | ||
"rrf": { | ||
"retrievers": [ | ||
{ | ||
"test": { | ||
"value": "foo" | ||
} | ||
}, | ||
{ | ||
"test": { | ||
"value": "bar" | ||
} | ||
} | ||
], | ||
"fields": ["field1", "field2"], | ||
"query": "baz", | ||
"rank_window_size": 100, | ||
"rank_constant": 10, | ||
"min_score": 20.0, | ||
"_name": "foo_rrf" | ||
} | ||
} | ||
} | ||
"""; | ||
SearchUsageHolder searchUsageHolder = new UsageService().getSearchUsageHolder(); | ||
try (XContentParser jsonParser = createParser(JsonXContent.jsonXContent, restContent)) { | ||
SearchSourceBuilder source = new SearchSourceBuilder().parseXContent(jsonParser, true, searchUsageHolder, nf -> true); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kderusso I know you requested that we refactor this common code, can we handle that in a follow up along with refactoring the common test code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, given the timing I'm fine with that happening in a followup