Skip to content

Commit a9c7512

Browse files
committed
PR Feedback
1 parent 8cf287b commit a9c7512

File tree

8 files changed

+23
-32
lines changed

8 files changed

+23
-32
lines changed

x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestDenseInferenceServiceExtension.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,14 @@ private List<ChunkedInference> makeChunkedResults(List<ChunkInferenceInput> inpu
180180
var results = new ArrayList<ChunkedInference>();
181181
for (ChunkInferenceInput input : inputs) {
182182
List<ChunkedInput> chunkedInput = chunkInputs(input);
183-
List<TextEmbeddingFloatResults.Chunk> chunks = new ArrayList<>(
184-
chunkedInput.stream()
185-
.map(
186-
c -> new TextEmbeddingFloatResults.Chunk(
187-
makeResults(List.of(c.input()), serviceSettings).embeddings().get(0),
188-
new ChunkedInference.TextOffset(c.startOffset(), c.endOffset())
189-
)
183+
List<TextEmbeddingFloatResults.Chunk> chunks = chunkedInput.stream()
184+
.map(
185+
c -> new TextEmbeddingFloatResults.Chunk(
186+
makeResults(List.of(c.input()), serviceSettings).embeddings().get(0),
187+
new ChunkedInference.TextOffset(c.startOffset(), c.endOffset())
190188
)
191-
.toList()
192-
);
189+
)
190+
.toList();
193191
ChunkedInferenceEmbedding chunkedInferenceEmbedding = new ChunkedInferenceEmbedding(chunks);
194192
results.add(chunkedInferenceEmbedding);
195193
}

x-pack/plugin/inference/qa/test-service-plugin/src/main/java/org/elasticsearch/xpack/inference/mock/TestSparseInferenceServiceExtension.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,15 @@ private SparseEmbeddingResults makeResults(List<String> input) {
170170
private List<ChunkedInference> makeChunkedResults(List<ChunkInferenceInput> inputs) {
171171
List<ChunkedInference> results = new ArrayList<>();
172172
for (ChunkInferenceInput chunkInferenceInput : inputs) {
173-
String input = chunkInferenceInput.input();
174173
List<ChunkedInput> chunkedInput = chunkInputs(chunkInferenceInput);
175-
List<SparseEmbeddingResults.Chunk> chunks = new ArrayList<>(chunkedInput.stream().map(c -> {
174+
List<SparseEmbeddingResults.Chunk> chunks = chunkedInput.stream().map(c -> {
176175
var tokens = new ArrayList<WeightedToken>();
177176
for (int i = 0; i < 5; i++) {
178177
tokens.add(new WeightedToken("feature_" + i, generateEmbedding(c.input(), i)));
179178
}
180179
var embeddings = new SparseEmbeddingResults.Embedding(tokens, false);
181180
return new SparseEmbeddingResults.Chunk(embeddings, new ChunkedInference.TextOffset(c.startOffset(), c.endOffset()));
182-
}).toList());
181+
}).toList();
183182
ChunkedInferenceEmbedding chunkedInferenceEmbedding = new ChunkedInferenceEmbedding(chunks);
184183
results.add(chunkedInferenceEmbedding);
185184
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/chunking/EmbeddingRequestChunker.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ public String chunkText() {
4848

4949
public record BatchRequest(List<Request> requests) {
5050
public List<String> inputs() {
51-
return requests.stream()
52-
.map(r -> new ChunkInferenceInput(r.chunkText(), r.inputs().getFirst().chunkingSettings()))
53-
.map(ChunkInferenceInput::input)
54-
.collect(Collectors.toList());
51+
return requests.stream().map(Request::chunkText).collect(Collectors.toList());
5552
}
5653
}
5754

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,14 @@ private void validateServiceSettings(MinimalServiceSettings settings) {
317317
* @return A mapper with the copied settings applied
318318
*/
319319
private SemanticTextFieldMapper copySettings(SemanticTextFieldMapper mapper, MapperMergeContext mapperMergeContext) {
320-
SemanticTextFieldMapper returnedMapper;
321-
Builder builder = from(mapper);
320+
SemanticTextFieldMapper returnedMapper = mapper;
322321
if (mapper.fieldType().getModelSettings() == null) {
322+
Builder builder = from(mapper);
323323
builder.setModelSettings(modelSettings.getValue());
324+
returnedMapper = builder.build(mapperMergeContext.getMapperBuilderContext());
324325
}
325-
builder.setChunkingSettings(mapper.fieldType().getChunkingSettings());
326-
return builder.build(mapperMergeContext.getMapperBuilderContext());
326+
327+
return returnedMapper;
327328
}
328329
}
329330

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/SingleInputSenderExecutableActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testOneInputIsValid() {
6464

6565
public void testMoreThanOneInput() {
6666
var badInput = mock(EmbeddingsInput.class);
67-
var input = List.of(new ChunkInferenceInput("one", null), new ChunkInferenceInput("two", null));
67+
var input = List.of(new ChunkInferenceInput("one"), new ChunkInferenceInput("two"));
6868
when(badInput.getInputs()).thenReturn(input);
6969
when(badInput.inputSize()).thenReturn(input.size());
7070
var actualException = new AtomicReference<Exception>();

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/queries/SemanticQueryBuilderTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import org.elasticsearch.xpack.core.ml.search.WeightedToken;
6161
import org.elasticsearch.xpack.inference.InferencePlugin;
6262
import org.elasticsearch.xpack.inference.mapper.SemanticTextField;
63-
import org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests;
6463
import org.junit.Before;
6564
import org.junit.BeforeClass;
6665

@@ -370,12 +369,7 @@ private static SourceToParse buildSemanticTextFieldWithInferenceResults(
370369
useLegacyFormat,
371370
SEMANTIC_TEXT_FIELD,
372371
null,
373-
new SemanticTextField.InferenceResult(
374-
INFERENCE_ID,
375-
modelSettings,
376-
SemanticTextFieldTests.generateRandomChunkingSettings(),
377-
Map.of(SEMANTIC_TEXT_FIELD, List.of())
378-
),
372+
new SemanticTextField.InferenceResult(INFERENCE_ID, modelSettings, null, Map.of(SEMANTIC_TEXT_FIELD, List.of())),
379373
XContentType.JSON
380374
);
381375

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/25_semantic_text_field_mapping_chunking.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,14 @@ setup:
274274
fields:
275275
inference_field:
276276
type: "semantic"
277-
number_of_fragments: 2
277+
number_of_fragments: 3
278278

279279
- match: { hits.total.value: 1 }
280280
- match: { hits.hits.0._id: "doc_4" }
281-
- length: { hits.hits.0.highlight.inference_field: 2 }
281+
- length: { hits.hits.0.highlight.inference_field: 3 }
282282
- match: { hits.hits.0.highlight.inference_field.0: "Elasticsearch is an open source, distributed, RESTful, search engine which" }
283283
- match: { hits.hits.0.highlight.inference_field.1: " which is built on top of Lucene internally and enjoys" }
284+
- match: { hits.hits.0.highlight.inference_field.2: " enjoys all the features it provides." }
284285

285286
---
286287
"We respect multiple semantic_text fields with different chunking configurations":

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/25_semantic_text_field_mapping_chunking_bwc.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,14 @@ setup:
286286
fields:
287287
inference_field:
288288
type: "semantic"
289-
number_of_fragments: 2
289+
number_of_fragments: 3
290290

291291
- match: { hits.total.value: 1 }
292292
- match: { hits.hits.0._id: "doc_4" }
293-
- length: { hits.hits.0.highlight.inference_field: 2 }
293+
- length: { hits.hits.0.highlight.inference_field: 3 }
294294
- match: { hits.hits.0.highlight.inference_field.0: "Elasticsearch is an open source, distributed, RESTful, search engine which" }
295295
- match: { hits.hits.0.highlight.inference_field.1: " which is built on top of Lucene internally and enjoys" }
296+
- match: { hits.hits.0.highlight.inference_field.2: " enjoys all the features it provides." }
296297

297298
---
298299
"We respect multiple semantic_text fields with different chunking configurations":

0 commit comments

Comments
 (0)