Skip to content

Commit b909ab9

Browse files
committed
Update API - remove max size, default num snippets, rename
1 parent d8dbaab commit b909ab9

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

server/src/main/java/org/elasticsearch/search/rank/feature/RankFeatureShardPhase.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ public static void prepareForFetch(SearchContext searchContext, RankFeatureShard
6363
HighlightBuilder highlightBuilder = new HighlightBuilder().field(field).preTags("").postTags("");
6464
// Force sorting by score to ensure that the first snippet is always the highest score
6565
highlightBuilder.order(HighlightBuilder.Order.SCORE);
66-
if (snippets.numFragments() != null) {
67-
highlightBuilder.numOfFragments(snippets.numFragments());
68-
}
69-
if (snippets.maxSize() != null) {
70-
highlightBuilder.fragmentSize(snippets.maxSize());
66+
if (snippets.numSnippets() != null) {
67+
highlightBuilder.numOfFragments(snippets.numSnippets());
7168
}
69+
highlightBuilder.fragmentSize(20); // TODO use model limit
7270
SearchHighlightContext searchHighlightContext = highlightBuilder.build(searchContext.getSearchExecutionContext());
7371
searchContext.highlight(searchHighlightContext);
7472
}

server/src/main/java/org/elasticsearch/search/rank/feature/RerankSnippetInput.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@
1515

1616
import java.io.IOException;
1717

18-
public record RerankSnippetInput(Integer numFragments, Integer maxSize) implements Writeable {
18+
public record RerankSnippetInput(Integer numSnippets) implements Writeable {
19+
20+
private static final int DEFAULT_NUM_SNIPPETS = 1;
21+
22+
public RerankSnippetInput {
23+
if (numSnippets == null) {
24+
numSnippets = DEFAULT_NUM_SNIPPETS;
25+
}
26+
}
1927

2028
public RerankSnippetInput(StreamInput in) throws IOException {
21-
this(in.readOptionalVInt(), in.readOptionalVInt());
29+
this(in.readOptionalVInt());
2230
}
2331

2432
@Override
2533
public void writeTo(StreamOutput out) throws IOException {
26-
out.writeOptionalVInt(numFragments);
27-
out.writeOptionalVInt(maxSize);
34+
out.writeOptionalVInt(numSnippets);
2835
}
2936
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/rank/textsimilarity/TextSimilarityRankFeaturePhaseRankCoordinatorContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected void computeScores(RankFeatureDoc[] featureDocs, ActionListener<float[
6969

7070
List<RankedDocsResults.RankedDoc> rankedDocs = ((RankedDocsResults) results).getRankedDocs();
7171
final float[] scores;
72-
if (featureDocs.length > 0 && featureDocs[0].featureData != null && featureDocs[0].featureData.size() > 1) {
72+
if (this.snippets != null) {
7373
scores = extractScoresFromRankedSnippets(rankedDocs, featureDocs);
7474
} else {
7575
scores = extractScoresFromRankedDocs(rankedDocs);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/rank/textsimilarity/TextSimilarityRankRetrieverBuilder.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
4949
public static final ParseField FIELD_FIELD = new ParseField("field");
5050
public static final ParseField FAILURES_ALLOWED_FIELD = new ParseField("allow_rerank_failures");
5151
public static final ParseField SNIPPETS_FIELD = new ParseField("snippets");
52-
public static final ParseField NUM_FRAGMENTS_FIELD = new ParseField("num_fragments");
53-
public static final ParseField MAX_SIZE_FIELD = new ParseField("max_size");
52+
public static final ParseField NUM_SNIPPETS_FIELD = new ParseField("num_snippets");
5453

5554
public static final ConstructingObjectParser<TextSimilarityRankRetrieverBuilder, RetrieverParserContext> PARSER =
5655
new ConstructingObjectParser<>(TextSimilarityRankBuilder.NAME, args -> {
@@ -75,9 +74,8 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
7574

7675
private static final ConstructingObjectParser<RerankSnippetInput, RetrieverParserContext> SNIPPETS_PARSER =
7776
new ConstructingObjectParser<>(SNIPPETS_FIELD.getPreferredName(), true, args -> {
78-
Integer numFragments = (Integer) args[0];
79-
Integer maxSize = (Integer) args[1];
80-
return new RerankSnippetInput(numFragments, maxSize);
77+
Integer numSnippets = (Integer) args[0];
78+
return new RerankSnippetInput(numSnippets);
8179
});
8280

8381
static {
@@ -92,8 +90,7 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
9290
PARSER.declareInt(optionalConstructorArg(), RANK_WINDOW_SIZE_FIELD);
9391
PARSER.declareBoolean(optionalConstructorArg(), FAILURES_ALLOWED_FIELD);
9492
PARSER.declareObject(optionalConstructorArg(), SNIPPETS_PARSER, SNIPPETS_FIELD);
95-
SNIPPETS_PARSER.declareInt(optionalConstructorArg(), NUM_FRAGMENTS_FIELD);
96-
SNIPPETS_PARSER.declareInt(optionalConstructorArg(), MAX_SIZE_FIELD);
93+
SNIPPETS_PARSER.declareInt(optionalConstructorArg(), NUM_SNIPPETS_FIELD);
9794

9895
RetrieverBuilder.declareBaseParserFields(PARSER);
9996
}
@@ -235,11 +232,8 @@ protected void doToXContent(XContentBuilder builder, Params params) throws IOExc
235232
}
236233
if (snippets != null) {
237234
builder.startObject(SNIPPETS_FIELD.getPreferredName());
238-
if (snippets.numFragments() != null) {
239-
builder.field(NUM_FRAGMENTS_FIELD.getPreferredName(), snippets.numFragments());
240-
}
241-
if (snippets.maxSize() != null) {
242-
builder.field(MAX_SIZE_FIELD.getPreferredName(), snippets.maxSize());
235+
if (snippets.numSnippets() != null) {
236+
builder.field(NUM_SNIPPETS_FIELD.getPreferredName(), snippets.numSnippets());
243237
}
244238
builder.endObject();
245239
}

0 commit comments

Comments
 (0)