Skip to content

Commit 6355282

Browse files
committed
Rename num_chunks to size
1 parent 246dfa2 commit 6355282

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
public class ChunkScorerConfig implements Writeable {
2222

23-
public final Integer numChunks;
23+
public final Integer size;
2424
private final String inferenceText;
2525
private final ChunkingSettings chunkingSettings;
2626

2727
public static final int DEFAULT_CHUNK_SIZE = 300;
28-
public static final int DEFAULT_NUM_CHUNKS = 1;
28+
public static final int DEFAULT_SIZE = 1;
2929

3030
public static ChunkingSettings createChunkingSettings(Integer chunkSize) {
3131
int chunkSizeOrDefault = chunkSize != null ? chunkSize : DEFAULT_CHUNK_SIZE;
@@ -48,31 +48,31 @@ public static ChunkingSettings chunkingSettingsFromMap(Map<String, Object> map)
4848
}
4949

5050
public ChunkScorerConfig(StreamInput in) throws IOException {
51-
this.numChunks = in.readOptionalVInt();
51+
this.size = in.readOptionalVInt();
5252
this.inferenceText = in.readString();
5353
Map<String, Object> chunkingSettingsMap = in.readGenericMap();
5454
this.chunkingSettings = ChunkingSettingsBuilder.fromMap(chunkingSettingsMap);
5555
}
5656

57-
public ChunkScorerConfig(Integer numChunks, ChunkingSettings chunkingSettings) {
58-
this(numChunks, null, chunkingSettings);
57+
public ChunkScorerConfig(Integer size, ChunkingSettings chunkingSettings) {
58+
this(size, null, chunkingSettings);
5959
}
6060

61-
public ChunkScorerConfig(Integer numChunks, String inferenceText, ChunkingSettings chunkingSettings) {
62-
this.numChunks = numChunks;
61+
public ChunkScorerConfig(Integer size, String inferenceText, ChunkingSettings chunkingSettings) {
62+
this.size = size;
6363
this.inferenceText = inferenceText;
6464
this.chunkingSettings = chunkingSettings;
6565
}
6666

6767
@Override
6868
public void writeTo(StreamOutput out) throws IOException {
69-
out.writeOptionalVInt(numChunks);
69+
out.writeOptionalVInt(size);
7070
out.writeString(inferenceText);
7171
out.writeGenericMap(chunkingSettings.asMap());
7272
}
7373

74-
public Integer numChunks() {
75-
return numChunks;
74+
public Integer size() {
75+
return size;
7676
}
7777

7878
public String inferenceText() {
@@ -88,13 +88,13 @@ public boolean equals(Object o) {
8888
if (this == o) return true;
8989
if (o == null || getClass() != o.getClass()) return false;
9090
ChunkScorerConfig that = (ChunkScorerConfig) o;
91-
return Objects.equals(numChunks, that.numChunks)
91+
return Objects.equals(size, that.size)
9292
&& Objects.equals(inferenceText, that.inferenceText)
9393
&& Objects.equals(chunkingSettings, that.chunkingSettings);
9494
}
9595

9696
@Override
9797
public int hashCode() {
98-
return Objects.hash(numChunks, inferenceText, chunkingSettings);
98+
return Objects.hash(size, inferenceText, chunkingSettings);
9999
}
100100
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public RankFeaturePhaseRankCoordinatorContext buildRankFeaturePhaseCoordinatorCo
198198
minScore,
199199
failuresAllowed,
200200
chunkScorerConfig != null
201-
? new ChunkScorerConfig(chunkScorerConfig.numChunks, inferenceText, chunkScorerConfig.chunkingSettings())
201+
? new ChunkScorerConfig(chunkScorerConfig.size, inferenceText, chunkScorerConfig.chunkingSettings())
202202
: null
203203
);
204204
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
5353
public static final ParseField FIELD_FIELD = new ParseField("field");
5454
public static final ParseField FAILURES_ALLOWED_FIELD = new ParseField("allow_rerank_failures");
5555
public static final ParseField CHUNK_RESCORER_FIELD = new ParseField("chunk_rescorer");
56-
public static final ParseField NUM_CHUNKS_FIELD = new ParseField("num_chunks");
56+
public static final ParseField CHUNK_SIZE_FIELD = new ParseField("size");
5757
public static final ParseField CHUNKING_SETTINGS_FIELD = new ParseField("chunking_settings");
5858

5959
public static final ConstructingObjectParser<TextSimilarityRankRetrieverBuilder, RetrieverParserContext> PARSER =
@@ -79,11 +79,11 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
7979

8080
private static final ConstructingObjectParser<ChunkScorerConfig, RetrieverParserContext> CHUNK_SCORER_PARSER =
8181
new ConstructingObjectParser<>(CHUNK_RESCORER_FIELD.getPreferredName(), true, args -> {
82-
Integer numChunks = (Integer) args[0];
82+
Integer size = (Integer) args[0];
8383
@SuppressWarnings("unchecked")
8484
Map<String, Object> chunkingSettingsMap = (Map<String, Object>) args[1];
8585
ChunkingSettings chunkingSettings = ChunkScorerConfig.chunkingSettingsFromMap(chunkingSettingsMap);
86-
return new ChunkScorerConfig(numChunks, chunkingSettings);
86+
return new ChunkScorerConfig(size, chunkingSettings);
8787
});
8888

8989
static {
@@ -99,7 +99,7 @@ public class TextSimilarityRankRetrieverBuilder extends CompoundRetrieverBuilder
9999
PARSER.declareBoolean(optionalConstructorArg(), FAILURES_ALLOWED_FIELD);
100100
PARSER.declareObject(optionalConstructorArg(), CHUNK_SCORER_PARSER, CHUNK_RESCORER_FIELD);
101101
if (RERANK_RESCORE_CHUNKS.isEnabled()) {
102-
CHUNK_SCORER_PARSER.declareInt(optionalConstructorArg(), NUM_CHUNKS_FIELD);
102+
CHUNK_SCORER_PARSER.declareInt(optionalConstructorArg(), CHUNK_SIZE_FIELD);
103103
CHUNK_SCORER_PARSER.declareObjectOrNull(optionalConstructorArg(), (p, c) -> p.map(), null, CHUNKING_SETTINGS_FIELD);
104104
}
105105

@@ -156,8 +156,8 @@ public TextSimilarityRankRetrieverBuilder(
156156
if (retrieverSource.size() != 1) {
157157
throw new IllegalArgumentException("[" + getName() + "] retriever should have exactly one inner retriever");
158158
}
159-
if (chunkScorerConfig != null && chunkScorerConfig.numChunks() != null && chunkScorerConfig.numChunks() < 1) {
160-
throw new IllegalArgumentException("num_chunks must be greater than 0, was: " + chunkScorerConfig.numChunks());
159+
if (chunkScorerConfig != null && chunkScorerConfig.size() != null && chunkScorerConfig.size() < 1) {
160+
throw new IllegalArgumentException("size must be greater than 0, was: " + chunkScorerConfig.size());
161161
}
162162
this.inferenceId = inferenceId;
163163
this.inferenceText = inferenceText;
@@ -220,7 +220,7 @@ protected SearchSourceBuilder finalizeSourceBuilder(SearchSourceBuilder sourceBu
220220
minScore,
221221
failuresAllowed,
222222
chunkScorerConfig != null
223-
? new ChunkScorerConfig(chunkScorerConfig.numChunks, inferenceText, chunkScorerConfig.chunkingSettings())
223+
? new ChunkScorerConfig(chunkScorerConfig.size, inferenceText, chunkScorerConfig.chunkingSettings())
224224
: null
225225
)
226226
);
@@ -252,8 +252,8 @@ protected void doToXContent(XContentBuilder builder, Params params) throws IOExc
252252
}
253253
if (chunkScorerConfig != null) {
254254
builder.startObject(CHUNK_RESCORER_FIELD.getPreferredName());
255-
if (chunkScorerConfig.numChunks() != null) {
256-
builder.field(NUM_CHUNKS_FIELD.getPreferredName(), chunkScorerConfig.numChunks());
255+
if (chunkScorerConfig.size() != null) {
256+
builder.field(CHUNK_SIZE_FIELD.getPreferredName(), chunkScorerConfig.size());
257257
}
258258
if (chunkScorerConfig.chunkingSettings() != null) {
259259
builder.field(CHUNKING_SETTINGS_FIELD.getPreferredName(), chunkScorerConfig.chunkingSettings().asMap());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.io.IOException;
2424
import java.util.List;
2525

26-
import static org.elasticsearch.xpack.inference.rank.textsimilarity.ChunkScorerConfig.DEFAULT_NUM_CHUNKS;
26+
import static org.elasticsearch.xpack.inference.rank.textsimilarity.ChunkScorerConfig.DEFAULT_SIZE;
2727

2828
public class TextSimilarityRerankingRankFeaturePhaseRankShardContext extends RerankingRankFeaturePhaseRankShardContext {
2929

@@ -47,7 +47,7 @@ public RankShardResult doBuildRankFeatureShardResult(SearchHits hits, int shardI
4747
DocumentField docField = hit.field(field);
4848
if (docField != null) {
4949
if (chunkScorerConfig != null) {
50-
int numChunks = chunkScorerConfig.numChunks() != null ? chunkScorerConfig.numChunks() : DEFAULT_NUM_CHUNKS;
50+
int size = chunkScorerConfig.size() != null ? chunkScorerConfig.size() : DEFAULT_SIZE;
5151
List<Chunker.ChunkOffset> chunkOffsets = chunker.chunk(docField.getValue().toString(), chunkingSettings);
5252
List<String> chunks = chunkOffsets.stream()
5353
.map(offset -> { return docField.getValue().toString().substring(offset.start(), offset.end()); })
@@ -59,9 +59,9 @@ public RankShardResult doBuildRankFeatureShardResult(SearchHits hits, int shardI
5959
List<MemoryIndexChunkScorer.ScoredChunk> scoredChunks = scorer.scoreChunks(
6060
chunks,
6161
chunkScorerConfig.inferenceText(),
62-
numChunks
62+
size
6363
);
64-
bestChunks = scoredChunks.stream().map(MemoryIndexChunkScorer.ScoredChunk::content).limit(numChunks).toList();
64+
bestChunks = scoredChunks.stream().map(MemoryIndexChunkScorer.ScoredChunk::content).limit(size).toList();
6565
} catch (IOException e) {
6666
throw new IllegalStateException("Could not generate chunks for input to reranker", e);
6767
}

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/70_text_similarity_rank_retriever.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ setup:
522522
reason: rescore_chunks introduced in 9.2.0
523523

524524
- do:
525-
catch: /num_chunks must be greater than 0/
525+
catch: /size must be greater than 0/
526526
search:
527527
index: test-index
528528
body:
@@ -539,7 +539,7 @@ setup:
539539
inference_text: "How often does the moon hide the sun?"
540540
field: inference_text_field
541541
chunk_rescorer:
542-
num_chunks: 0
542+
size: 0
543543
size: 10
544544

545545
- match: { status: 400 }
@@ -570,7 +570,7 @@ setup:
570570
inference_text: "How often does the moon hide the sun?"
571571
field: text
572572
chunk_rescorer:
573-
num_chunks: 2
573+
size: 2
574574
size: 10
575575

576576
- match: { hits.total.value: 2 }
@@ -638,7 +638,7 @@ setup:
638638
inference_text: "how often does the moon hide the sun?"
639639
field: semantic_text_field
640640
chunk_rescorer:
641-
num_chunks: 2
641+
size: 2
642642
size: 10
643643

644644
- match: { hits.total.value: 2 }

0 commit comments

Comments
 (0)