Skip to content

Commit 9a0ca94

Browse files
committed
Remove index options from inference field metadata as it is only needed at field creation time
1 parent a452d8e commit 9a0ca94

File tree

15 files changed

+58
-156
lines changed

15 files changed

+58
-156
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import static org.elasticsearch.TransportVersions.SEMANTIC_TEXT_CHUNKING_CONFIG;
3030
import static org.elasticsearch.TransportVersions.SEMANTIC_TEXT_CHUNKING_CONFIG_8_19;
31-
import static org.elasticsearch.TransportVersions.SEMANTIC_TEXT_INDEX_OPTIONS;
3231

3332
/**
3433
* Contains inference field data for fields.
@@ -42,39 +41,29 @@ public final class InferenceFieldMetadata implements SimpleDiffable<InferenceFie
4241
private static final String SEARCH_INFERENCE_ID_FIELD = "search_inference_id";
4342
private static final String SOURCE_FIELDS_FIELD = "source_fields";
4443
static final String CHUNKING_SETTINGS_FIELD = "chunking_settings";
45-
static final String INDEX_OPTIONS_FIELD = "index_options";
4644

4745
private final String name;
4846
private final String inferenceId;
4947
private final String searchInferenceId;
5048
private final String[] sourceFields;
5149
private final Map<String, Object> chunkingSettings;
52-
private final SemanticTextIndexOptions indexOptions;
5350

54-
public InferenceFieldMetadata(
55-
String name,
56-
String inferenceId,
57-
String[] sourceFields,
58-
Map<String, Object> chunkingSettings,
59-
SemanticTextIndexOptions indexOptions
60-
) {
61-
this(name, inferenceId, inferenceId, sourceFields, chunkingSettings, indexOptions);
51+
public InferenceFieldMetadata(String name, String inferenceId, String[] sourceFields, Map<String, Object> chunkingSettings) {
52+
this(name, inferenceId, inferenceId, sourceFields, chunkingSettings);
6253
}
6354

6455
public InferenceFieldMetadata(
6556
String name,
6657
String inferenceId,
6758
String searchInferenceId,
6859
String[] sourceFields,
69-
Map<String, Object> chunkingSettings,
70-
SemanticTextIndexOptions indexOptions
60+
Map<String, Object> chunkingSettings
7161
) {
7262
this.name = Objects.requireNonNull(name);
7363
this.inferenceId = Objects.requireNonNull(inferenceId);
7464
this.searchInferenceId = Objects.requireNonNull(searchInferenceId);
7565
this.sourceFields = Objects.requireNonNull(sourceFields);
7666
this.chunkingSettings = chunkingSettings != null ? Map.copyOf(chunkingSettings) : null;
77-
this.indexOptions = indexOptions;
7867
}
7968

8069
public InferenceFieldMetadata(StreamInput input) throws IOException {
@@ -92,11 +81,6 @@ public InferenceFieldMetadata(StreamInput input) throws IOException {
9281
} else {
9382
this.chunkingSettings = null;
9483
}
95-
if (input.getTransportVersion().onOrAfter(SEMANTIC_TEXT_INDEX_OPTIONS)) {
96-
this.indexOptions = input.readOptionalWriteable(SemanticTextIndexOptions::new);
97-
} else {
98-
this.indexOptions = null;
99-
}
10084
}
10185

10286
@Override
@@ -111,9 +95,6 @@ public void writeTo(StreamOutput out) throws IOException {
11195
|| out.getTransportVersion().isPatchFrom(SEMANTIC_TEXT_CHUNKING_CONFIG_8_19)) {
11296
out.writeGenericMap(chunkingSettings);
11397
}
114-
if (out.getTransportVersion().onOrAfter(SEMANTIC_TEXT_INDEX_OPTIONS)) {
115-
out.writeOptionalWriteable(indexOptions);
116-
}
11798
}
11899

119100
@Override
@@ -160,10 +141,6 @@ public Map<String, Object> getChunkingSettings() {
160141
return chunkingSettings;
161142
}
162143

163-
public SemanticTextIndexOptions getIndexOptions() {
164-
return indexOptions;
165-
}
166-
167144
public static Diff<InferenceFieldMetadata> readDiffFrom(StreamInput in) throws IOException {
168145
return SimpleDiffable.readDiffFrom(InferenceFieldMetadata::new, in);
169146
}
@@ -194,7 +171,6 @@ public static InferenceFieldMetadata fromXContent(XContentParser parser) throws
194171
String inferenceId = null;
195172
String searchInferenceId = null;
196173
Map<String, Object> chunkingSettings = null;
197-
SemanticTextIndexOptions indexOptions = null;
198174
List<String> inputFields = new ArrayList<>();
199175
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
200176
if (token == XContentParser.Token.FIELD_NAME) {
@@ -217,8 +193,6 @@ public static InferenceFieldMetadata fromXContent(XContentParser parser) throws
217193
}
218194
} else if (CHUNKING_SETTINGS_FIELD.equals(currentFieldName)) {
219195
chunkingSettings = parser.map();
220-
} else if (INDEX_OPTIONS_FIELD.equals(currentFieldName)) {
221-
indexOptions = null; // TODO implement parsing
222196
} else if (token.isValue()) {
223197
// Ignore other fields
224198
} else {
@@ -230,8 +204,7 @@ public static InferenceFieldMetadata fromXContent(XContentParser parser) throws
230204
inferenceId,
231205
searchInferenceId == null ? inferenceId : searchInferenceId,
232206
inputFields.toArray(String[]::new),
233-
chunkingSettings,
234-
indexOptions
207+
chunkingSettings
235208
);
236209
}
237210
}

server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,7 @@ private static InferenceFieldMetadata randomInferenceFieldMetadata(String name)
728728
randomIdentifier(),
729729
randomIdentifier(),
730730
randomSet(1, 5, ESTestCase::randomIdentifier).toArray(String[]::new),
731-
InferenceFieldMetadataTests.generateRandomChunkingSettings(),
732-
InferenceFieldMetadataTests.randomSemanticTextIndexOptions()
731+
InferenceFieldMetadataTests.generateRandomChunkingSettings()
733732
);
734733
}
735734

server/src/test/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadataTests.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1313
import org.elasticsearch.common.io.stream.StreamInput;
14-
import org.elasticsearch.inference.TaskType;
1514
import org.elasticsearch.test.AbstractXContentTestCase;
1615
import org.elasticsearch.xcontent.XContentParser;
1716

@@ -20,7 +19,6 @@
2019
import java.util.function.Predicate;
2120

2221
import static org.elasticsearch.cluster.metadata.InferenceFieldMetadata.CHUNKING_SETTINGS_FIELD;
23-
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldTypeTests.randomIndexOptionsAll;
2422
import static org.hamcrest.Matchers.equalTo;
2523

2624
public class InferenceFieldMetadataTests extends AbstractXContentTestCase<InferenceFieldMetadata> {
@@ -70,8 +68,7 @@ private static InferenceFieldMetadata createTestItem() {
7068
String searchInferenceId = randomIdentifier();
7169
String[] inputFields = generateRandomStringArray(5, 10, false, false);
7270
Map<String, Object> chunkingSettings = generateRandomChunkingSettings();
73-
SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions();
74-
return new InferenceFieldMetadata(name, inferenceId, searchInferenceId, inputFields, chunkingSettings, indexOptions);
71+
return new InferenceFieldMetadata(name, inferenceId, searchInferenceId, inputFields, chunkingSettings);
7572
}
7673

7774
public static Map<String, Object> generateRandomChunkingSettings() {
@@ -81,22 +78,6 @@ public static Map<String, Object> generateRandomChunkingSettings() {
8178
return randomBoolean() ? generateRandomWordBoundaryChunkingSettings() : generateRandomSentenceBoundaryChunkingSettings();
8279
}
8380

84-
public static SemanticTextIndexOptions randomSemanticTextIndexOptions() {
85-
TaskType taskType = randomFrom(TaskType.SPARSE_EMBEDDING, TaskType.TEXT_EMBEDDING);
86-
return randomSemanticTextIndexOptions(taskType);
87-
}
88-
89-
public static SemanticTextIndexOptions randomSemanticTextIndexOptions(TaskType taskType) {
90-
91-
if (taskType == TaskType.TEXT_EMBEDDING) {
92-
return randomBoolean()
93-
? null
94-
: new SemanticTextIndexOptions(SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, randomIndexOptionsAll());
95-
}
96-
97-
return null;
98-
}
99-
10081
private static Map<String, Object> generateRandomWordBoundaryChunkingSettings() {
10182
return Map.of("strategy", "word_boundary", "max_chunk_size", randomIntBetween(20, 100), "overlap", randomIntBetween(1, 50));
10283
}
@@ -115,19 +96,16 @@ private static Map<String, Object> generateRandomSentenceBoundaryChunkingSetting
11596
public void testNullCtorArgsThrowException() {
11697
assertThrows(
11798
NullPointerException.class,
118-
() -> new InferenceFieldMetadata(null, "inferenceId", "searchInferenceId", new String[0], Map.of(), null)
119-
);
120-
assertThrows(
121-
NullPointerException.class,
122-
() -> new InferenceFieldMetadata("name", null, "searchInferenceId", new String[0], Map.of(), null)
99+
() -> new InferenceFieldMetadata(null, "inferenceId", "searchInferenceId", new String[0], Map.of())
123100
);
124101
assertThrows(
125102
NullPointerException.class,
126-
() -> new InferenceFieldMetadata("name", "inferenceId", null, new String[0], Map.of(), null)
103+
() -> new InferenceFieldMetadata("name", null, "searchInferenceId", new String[0], Map.of())
127104
);
105+
assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", "inferenceId", null, new String[0], Map.of()));
128106
assertThrows(
129107
NullPointerException.class,
130-
() -> new InferenceFieldMetadata("name", "inferenceId", "searchInferenceId", null, Map.of(), null)
108+
() -> new InferenceFieldMetadata("name", "inferenceId", "searchInferenceId", null, Map.of())
131109
);
132110
}
133111
}

server/src/test/java/org/elasticsearch/index/mapper/MappingLookupInferenceFieldMapperTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.cluster.metadata.InferenceFieldMetadata;
1414
import org.elasticsearch.cluster.metadata.InferenceFieldMetadataTests;
1515
import org.elasticsearch.index.query.SearchExecutionContext;
16-
import org.elasticsearch.inference.TaskType;
1716
import org.elasticsearch.plugins.MapperPlugin;
1817
import org.elasticsearch.plugins.Plugin;
1918

@@ -109,8 +108,7 @@ public InferenceFieldMetadata getMetadata(Set<String> sourcePaths) {
109108
INFERENCE_ID,
110109
SEARCH_INFERENCE_ID,
111110
sourcePaths.toArray(new String[0]),
112-
InferenceFieldMetadataTests.generateRandomChunkingSettings(),
113-
InferenceFieldMetadataTests.randomSemanticTextIndexOptions(TaskType.TEXT_EMBEDDING)
111+
InferenceFieldMetadataTests.generateRandomChunkingSettings()
114112
);
115113
}
116114

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ private void applyInferenceResponses(BulkItemRequest item, FieldInferenceRespons
696696
inferenceFieldMetadata.getInferenceId(),
697697
model != null ? new MinimalServiceSettings(model) : null,
698698
ChunkingSettingsBuilder.fromMap(inferenceFieldMetadata.getChunkingSettings(), false),
699-
inferenceFieldMetadata.getIndexOptions(),
700699
chunkMap
701700
),
702701
indexRequest.getContentType()

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public record InferenceResult(
8080
String inferenceId,
8181
MinimalServiceSettings modelSettings,
8282
ChunkingSettings chunkingSettings,
83-
SemanticTextIndexOptions indexOptions,
8483
Map<String, List<Chunk>> chunks
8584
) {}
8685

@@ -181,9 +180,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
181180
if (inference.chunkingSettings != null) {
182181
builder.field(CHUNKING_SETTINGS_FIELD, inference.chunkingSettings);
183182
}
184-
if (inference.indexOptions != null) {
185-
builder.field(INDEX_OPTIONS_FIELD, inference.indexOptions);
186-
}
187183

188184
if (useLegacyFormat) {
189185
builder.startArray(CHUNKS_FIELD);
@@ -254,13 +250,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
254250
Map<String, Object> chunkingSettings = (Map<String, Object>) args[2];
255251
SemanticTextIndexOptions indexOptions = (SemanticTextIndexOptions) args[3];
256252
Map<String, List<Chunk>> chunks = (Map<String, List<Chunk>>) args[4];
257-
return new InferenceResult(
258-
inferenceId,
259-
modelSettings,
260-
ChunkingSettingsBuilder.fromMap(chunkingSettings, false),
261-
indexOptions,
262-
chunks
263-
);
253+
return new InferenceResult(inferenceId, modelSettings, ChunkingSettingsBuilder.fromMap(chunkingSettings, false), chunks);
264254
}
265255
);
266256

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,16 +673,8 @@ public InferenceFieldMetadata getMetadata(Set<String> sourcePaths) {
673673
Arrays.sort(copyFields);
674674
ChunkingSettings fieldTypeChunkingSettings = fieldType().getChunkingSettings();
675675
Map<String, Object> asMap = fieldTypeChunkingSettings != null ? fieldTypeChunkingSettings.asMap() : null;
676-
SemanticTextIndexOptions indexOptions = fieldType().getIndexOptions();
677-
678-
return new InferenceFieldMetadata(
679-
fullPath(),
680-
fieldType().getInferenceId(),
681-
fieldType().getSearchInferenceId(),
682-
copyFields,
683-
asMap,
684-
indexOptions
685-
);
676+
677+
return new InferenceFieldMetadata(fullPath(), fieldType().getInferenceId(), fieldType().getSearchInferenceId(), copyFields, asMap);
686678
}
687679

688680
@Override
@@ -1048,7 +1040,7 @@ public List<Object> fetchValues(Source source, int doc, List<Object> ignoredValu
10481040
useLegacyFormat,
10491041
name(),
10501042
null,
1051-
new SemanticTextField.InferenceResult(inferenceId, modelSettings, chunkingSettings, indexOptions, chunkMap),
1043+
new SemanticTextField.InferenceResult(inferenceId, modelSettings, chunkingSettings, chunkMap),
10521044
source.sourceContentType()
10531045
)
10541046
);

x-pack/plugin/inference/src/test/java/org/elasticsearch/index/query/SemanticKnnVectorQueryRewriteInterceptorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void cleanup() {
5656
public void testKnnQueryWithVectorBuilderIsInterceptedAndRewritten() throws IOException {
5757
Map<String, InferenceFieldMetadata> inferenceFields = Map.of(
5858
FIELD_NAME,
59-
new InferenceFieldMetadata(index.getName(), INFERENCE_ID, new String[] { FIELD_NAME }, null, null)
59+
new InferenceFieldMetadata(index.getName(), INFERENCE_ID, new String[] { FIELD_NAME }, null)
6060
);
6161
QueryRewriteContext context = createQueryRewriteContext(inferenceFields);
6262
QueryVectorBuilder queryVectorBuilder = new TextEmbeddingQueryVectorBuilder(INFERENCE_ID, QUERY);
@@ -67,7 +67,7 @@ public void testKnnQueryWithVectorBuilderIsInterceptedAndRewritten() throws IOEx
6767
public void testKnnWithQueryBuilderWithoutInferenceIdIsInterceptedAndRewritten() throws IOException {
6868
Map<String, InferenceFieldMetadata> inferenceFields = Map.of(
6969
FIELD_NAME,
70-
new InferenceFieldMetadata(index.getName(), INFERENCE_ID, new String[] { FIELD_NAME }, null, null)
70+
new InferenceFieldMetadata(index.getName(), INFERENCE_ID, new String[] { FIELD_NAME }, null)
7171
);
7272
QueryRewriteContext context = createQueryRewriteContext(inferenceFields);
7373
QueryVectorBuilder queryVectorBuilder = new TextEmbeddingQueryVectorBuilder(null, QUERY);

x-pack/plugin/inference/src/test/java/org/elasticsearch/index/query/SemanticMatchQueryRewriteInterceptorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void cleanup() {
5252
public void testMatchQueryOnInferenceFieldIsInterceptedAndRewrittenToSemanticQuery() throws IOException {
5353
Map<String, InferenceFieldMetadata> inferenceFields = Map.of(
5454
FIELD_NAME,
55-
new InferenceFieldMetadata(index.getName(), "inferenceId", new String[] { FIELD_NAME }, null, null)
55+
new InferenceFieldMetadata(index.getName(), "inferenceId", new String[] { FIELD_NAME }, null)
5656
);
5757
QueryRewriteContext context = createQueryRewriteContext(inferenceFields);
5858
QueryBuilder original = createTestQueryBuilder();

x-pack/plugin/inference/src/test/java/org/elasticsearch/index/query/SemanticSparseVectorQueryRewriteInterceptorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void cleanup() {
5454
public void testSparseVectorQueryOnInferenceFieldIsInterceptedAndRewritten() throws IOException {
5555
Map<String, InferenceFieldMetadata> inferenceFields = Map.of(
5656
FIELD_NAME,
57-
new InferenceFieldMetadata(index.getName(), "inferenceId", new String[] { FIELD_NAME }, null, null)
57+
new InferenceFieldMetadata(index.getName(), "inferenceId", new String[] { FIELD_NAME }, null)
5858
);
5959
QueryRewriteContext context = createQueryRewriteContext(inferenceFields);
6060
QueryBuilder original = new SparseVectorQueryBuilder(FIELD_NAME, INFERENCE_ID, QUERY);
@@ -78,7 +78,7 @@ public void testSparseVectorQueryOnInferenceFieldIsInterceptedAndRewritten() thr
7878
public void testSparseVectorQueryOnInferenceFieldWithoutInferenceIdIsInterceptedAndRewritten() throws IOException {
7979
Map<String, InferenceFieldMetadata> inferenceFields = Map.of(
8080
FIELD_NAME,
81-
new InferenceFieldMetadata(index.getName(), "inferenceId", new String[] { FIELD_NAME }, null, null)
81+
new InferenceFieldMetadata(index.getName(), "inferenceId", new String[] { FIELD_NAME }, null)
8282
);
8383
QueryRewriteContext context = createQueryRewriteContext(inferenceFields);
8484
QueryBuilder original = new SparseVectorQueryBuilder(FIELD_NAME, null, QUERY);

0 commit comments

Comments
 (0)