Adding deprecation warnings for rank and sub_searches (#114854)

This commit is contained in:
Panagiotis Bailis 2024-10-16 21:56:13 +03:00 committed by GitHub
parent e144184896
commit e79127ba2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 178 additions and 31 deletions

View file

@ -36,16 +36,17 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
/**
* The builder to support RRF. Adds user-defined parameters for window size and rank constant.
*
* @deprecated RRF support is provided through the retriever framework. Please use {@link RRFRetrieverBuilder instead}
*/
@Deprecated
public class RRFRankBuilder extends RankBuilder {
public static final int DEFAULT_RANK_CONSTANT = 60;
public static final ParseField RANK_CONSTANT_FIELD = new ParseField("rank_constant");
static final ConstructingObjectParser<RRFRankBuilder, Void> PARSER = new ConstructingObjectParser<>(RRFRankPlugin.NAME, args -> {
int windowSize = args[0] == null ? DEFAULT_RANK_WINDOW_SIZE : (int) args[0];
int rankConstant = args[1] == null ? DEFAULT_RANK_CONSTANT : (int) args[1];
int rankConstant = args[1] == null ? RRFRetrieverBuilder.DEFAULT_RANK_CONSTANT : (int) args[1];
return new RRFRankBuilder(windowSize, rankConstant);
});

View file

@ -19,7 +19,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import static org.elasticsearch.xpack.rank.rrf.RRFRankBuilder.DEFAULT_RANK_CONSTANT;
import static org.elasticsearch.xpack.rank.rrf.RRFRetrieverBuilder.DEFAULT_RANK_CONSTANT;
/**
* {@code RRFRankDoc} supports additional ranking information

View file

@ -12,6 +12,7 @@ import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.search.rank.RankBuilder;
import org.elasticsearch.search.rank.RankDoc;
import org.elasticsearch.search.retriever.CompoundRetrieverBuilder;
import org.elasticsearch.search.retriever.RetrieverBuilder;
@ -31,7 +32,6 @@ import java.util.Objects;
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
import static org.elasticsearch.xpack.rank.rrf.RRFRankPlugin.NAME;
/**
* An rrf retriever is used to represent an rrf rank element, but
@ -50,6 +50,7 @@ public final class RRFRetrieverBuilder extends CompoundRetrieverBuilder<RRFRetri
public static final ParseField RANK_WINDOW_SIZE_FIELD = new ParseField("rank_window_size");
public static final ParseField RANK_CONSTANT_FIELD = new ParseField("rank_constant");
public static final int DEFAULT_RANK_CONSTANT = 60;
@SuppressWarnings("unchecked")
static final ConstructingObjectParser<RRFRetrieverBuilder, RetrieverParserContext> PARSER = new ConstructingObjectParser<>(
NAME,
@ -57,8 +58,8 @@ public final class RRFRetrieverBuilder extends CompoundRetrieverBuilder<RRFRetri
args -> {
List<RetrieverBuilder> childRetrievers = (List<RetrieverBuilder>) args[0];
List<RetrieverSource> innerRetrievers = childRetrievers.stream().map(r -> new RetrieverSource(r, null)).toList();
int rankWindowSize = args[1] == null ? RRFRankBuilder.DEFAULT_RANK_WINDOW_SIZE : (int) args[1];
int rankConstant = args[2] == null ? RRFRankBuilder.DEFAULT_RANK_CONSTANT : (int) args[2];
int rankWindowSize = args[1] == null ? RankBuilder.DEFAULT_RANK_WINDOW_SIZE : (int) args[1];
int rankConstant = args[2] == null ? DEFAULT_RANK_CONSTANT : (int) args[2];
return new RRFRetrieverBuilder(innerRetrievers, rankWindowSize, rankConstant);
}
);

View file

@ -41,7 +41,7 @@ public class RRFRetrieverBuilderParsingTests extends AbstractXContentTestCase<RR
if (randomBoolean()) {
rankWindowSize = randomIntBetween(1, 10000);
}
int rankConstant = RRFRankBuilder.DEFAULT_RANK_CONSTANT;
int rankConstant = RRFRetrieverBuilder.DEFAULT_RANK_CONSTANT;
if (randomBoolean()) {
rankConstant = randomIntBetween(1, 1000000);
}

View file

@ -2,6 +2,8 @@ setup:
- requires:
cluster_features: "gte_v8.8.0"
reason: 'rank added in 8.8'
- skip:
features: "warnings"
- do:
indices.create:
@ -59,7 +61,14 @@ setup:
---
"Simple rank with bm25 search and kNN search":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
search:
index: test
body:
@ -94,7 +103,15 @@ setup:
---
"Simple rank with multiple bm25 sub searches":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -135,7 +152,15 @@ setup:
---
"Simple rank with multiple bm25 sub_searches and a knn search":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:

View file

@ -63,7 +63,15 @@ setup:
---
"Standard pagination within rank_window_size":
# this test retrieves the same results from two queries, and applies a simple pagination skipping the first result
- requires:
cluster_features: [ "gte_v8.16.0" ]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -170,7 +178,15 @@ setup:
---
"Standard pagination outside rank_window_size":
# in this example, from starts *after* rank_window_size so, we expect 0 results to be returned
- requires:
cluster_features: [ "gte_v8.16.0" ]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -274,7 +290,15 @@ setup:
---
"Standard pagination partially outside rank_window_size":
# in this example we have that from starts *within* rank_window_size, but "from + size" goes over
- requires:
cluster_features: [ "gte_v8.16.0" ]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -384,7 +408,15 @@ setup:
# queryA has a result set of [1, 2, 3, 4] and
# queryB has a result set of [4, 3, 1, 2]
# so for rank_constant=10, the expected order is [1, 4, 3, 2]
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -488,6 +520,9 @@ setup:
- match: { hits.hits.1._id: "4" }
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -597,7 +632,15 @@ setup:
# queryA has a result set of [5, 1] and
# queryB has a result set of [4, 3, 1, 2]
# so for rank_constant=10, the expected order is [1, 5, 4, 3, 2]
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -685,6 +728,9 @@ setup:
- match: { hits.hits.1._id: "5" }
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -772,6 +818,9 @@ setup:
- match: { hits.hits.1._id: "3" }
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -867,7 +916,15 @@ setup:
# queryB has a result set of [4, 3]
# so for rank_constant=10, the expected order is [5, 4, 1, 3],
# and the rank_window_size-sized result set that we'd paginate over is [5, 4]
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -955,6 +1012,10 @@ setup:
- match: { hits.hits.1._id: "4" }
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:

View file

@ -67,7 +67,14 @@ setup:
---
"RRF using single knn and single BM25 with a scripted metric aggregation":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
search:
index: test
body:
@ -140,7 +147,14 @@ setup:
---
"RRF using multi-knn only with a scripted metric aggregation":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
search:
index: test
body:
@ -195,7 +209,14 @@ setup:
---
"RRF using multi-knn and single BM25 with a scripted metric aggregation":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
search:
index: test
body:

View file

@ -75,7 +75,14 @@ setup:
---
"using a top level knn and query":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
search:
index: test
body:
@ -129,7 +136,15 @@ setup:
---
"using sub_searches":
- requires:
cluster_features: [ "gte_v8.16.0" ]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -194,7 +209,14 @@ setup:
---
"using named top level knn and query":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
search:
index: test
body:
@ -251,7 +273,15 @@ setup:
---
"using named sub_searches":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:
@ -320,7 +350,15 @@ setup:
---
"using a mix of named and unnamed queries":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
- Deprecated field [sub_searches] used, replaced by [retriever]
search:
index: test
body:

View file

@ -172,7 +172,14 @@ setup:
---
"using query and dfs knn search":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "deprecation added in 8.16"
test_runner_features: warnings
- do:
warnings:
- "Deprecated field [rank] used, replaced by [retriever]"
search:
index: test
body: