diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticFieldMapper.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticFieldMapper.java index 80d8d3efe11c3..671b27eb553f3 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticFieldMapper.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticFieldMapper.java @@ -157,7 +157,7 @@ public static class Builder extends FieldMapper.Builder { protected final Parameter inferenceId; protected final Parameter searchInferenceId; protected final Parameter modelSettings; - protected final Parameter indexOptions; + protected final Parameter indexOptions; protected final Parameter chunkingSettings; protected final Parameter> meta; @@ -268,7 +268,7 @@ protected Parameter configureModelSettingsParam() { ).acceptsNull().setMergeValidator(SemanticFieldMapper::canMergeModelSettings); } - protected Parameter configureIndexOptionsParam() { + protected Parameter configureIndexOptionsParam() { return buildIndexOptionsParam(SemanticFieldMapper::defaultIndexOptions, SemanticFieldMapper::defaultElementTypeToBfloat16); } @@ -279,8 +279,8 @@ protected Parameter configureIndexOptionsParam() { * configured, and {@code bfloat16Resolver} decides whether an unconfigured {@code element_type} should default * to {@code bfloat16} when explicit dense_vector index options are set. */ - protected Parameter buildIndexOptionsParam( - Function defaultIndexOptionsResolver, + protected Parameter buildIndexOptionsParam( + Function defaultIndexOptionsResolver, Predicate bfloat16Resolver ) { return new Parameter<>( @@ -296,13 +296,13 @@ protected Parameter buildIndexOptionsParam( ) { @Override protected void toXContent(XContentBuilder builder, boolean includeDefaults) throws IOException { - SemanticTextIndexOptions value = getValue(); + SemanticIndexOptions value = getValue(); if (includeDefaults || isConfigured()) { MinimalServiceSettings resolvedModelSettings = getResolvedModelSettings(null, false); if (value == null) { // Default value, serialize resolved defaults value = defaultIndexOptionsResolver.apply(resolvedModelSettings); - } else if (value.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR) { + } else if (value.type() == SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR) { ExtendedDenseVectorIndexOptions innerIndexOptions = getExtendedDenseVectorIndexOptions(value); DenseVectorFieldMapper.ElementType elementTypeOverride = innerIndexOptions.getElementType(); DenseVectorFieldMapper.DenseVectorIndexOptions dvio = innerIndexOptions.getBaseIndexOptions(); @@ -314,8 +314,8 @@ protected void toXContent(XContentBuilder builder, boolean includeDefaults) thro if (includeDefaults && elementTypeOverride == null && bfloat16Resolver.test(resolvedModelSettings.elementType())) { - value = new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + value = new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, new ExtendedDenseVectorIndexOptions(dvio, DenseVectorFieldMapper.ElementType.BFLOAT16) ); } @@ -547,7 +547,7 @@ protected void validateTaskType(MinimalServiceSettings modelSettings) { } protected void validateIndexOptions(MinimalServiceSettings modelSettings) { - SemanticTextIndexOptions indexOptions = this.indexOptions.get(); + SemanticIndexOptions indexOptions = this.indexOptions.get(); String inferenceId = this.inferenceId.get(); if (indexOptions == null) { @@ -556,7 +556,7 @@ protected void validateIndexOptions(MinimalServiceSettings modelSettings) { throw new IllegalArgumentException( "Model settings must be set to validate index options for inference ID [" + inferenceId + "]" ); - } else if (indexOptions.type() != SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR) { + } else if (indexOptions.type() != SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR) { throw new IllegalArgumentException( "[" + contentType() + "] field [" + leafName() + "] does not support [" + indexOptions.type() + "] index options" ); @@ -959,7 +959,7 @@ public static class SemanticFieldType extends SimpleMappedFieldType { protected final String searchInferenceId; protected final MinimalServiceSettings modelSettings; protected final ChunkingSettings chunkingSettings; - protected final SemanticTextIndexOptions indexOptions; + protected final SemanticIndexOptions indexOptions; protected final ObjectMapper inferenceField; protected final boolean storesOriginalValuesInDocValues; @@ -969,7 +969,7 @@ public SemanticFieldType( String searchInferenceId, MinimalServiceSettings modelSettings, ChunkingSettings chunkingSettings, - SemanticTextIndexOptions indexOptions, + SemanticIndexOptions indexOptions, ObjectMapper inferenceField, boolean storesOriginalValuesInDocValues, Map meta @@ -1010,7 +1010,7 @@ public ChunkingSettings getChunkingSettings() { return chunkingSettings; } - public SemanticTextIndexOptions getIndexOptions() { + public SemanticIndexOptions getIndexOptions() { return indexOptions; } @@ -1229,7 +1229,7 @@ public static boolean canMergeModelSettings(MinimalServiceSettings previous, Min return false; } - protected static SemanticTextIndexOptions parseIndexOptionsFromMap( + protected static SemanticIndexOptions parseIndexOptionsFromMap( String fieldName, Object node, IndexVersion indexVersion, @@ -1244,18 +1244,16 @@ protected static SemanticTextIndexOptions parseIndexOptionsFromMap( throw new IllegalArgumentException("Too many index options provided, found [" + map.keySet() + "]"); } Map.Entry entry = map.entrySet().iterator().next(); - SemanticTextIndexOptions.SupportedIndexOptions indexOptions = SemanticTextIndexOptions.SupportedIndexOptions.fromValue( - entry.getKey() - ); + SemanticIndexOptions.SupportedIndexOptions indexOptions = SemanticIndexOptions.SupportedIndexOptions.fromValue(entry.getKey()); @SuppressWarnings("unchecked") Map indexOptionsMap = (Map) entry.getValue(); - return new SemanticTextIndexOptions( + return new SemanticIndexOptions( indexOptions, indexOptions.parseIndexOptions(fieldName, indexOptionsMap, indexVersion, experimentalFeaturesEnabled) ); } - protected static ExtendedDenseVectorIndexOptions getExtendedDenseVectorIndexOptions(SemanticTextIndexOptions indexOptions) { + protected static ExtendedDenseVectorIndexOptions getExtendedDenseVectorIndexOptions(SemanticIndexOptions indexOptions) { IndexOptions innerIndexOptions = indexOptions.indexOptions(); if (innerIndexOptions instanceof ExtendedDenseVectorIndexOptions edvio) { return edvio; @@ -1268,10 +1266,10 @@ private static boolean defaultElementTypeToBfloat16(DenseVectorFieldMapper.Eleme return modelElementType == DenseVectorFieldMapper.ElementType.FLOAT; } - private static SemanticTextIndexOptions defaultIndexOptions(MinimalServiceSettings modelSettings) { + private static SemanticIndexOptions defaultIndexOptions(MinimalServiceSettings modelSettings) { if (modelSettings != null && defaultElementTypeToBfloat16(modelSettings.elementType())) { - return new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + return new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, new ExtendedDenseVectorIndexOptions(null, DenseVectorFieldMapper.ElementType.BFLOAT16) ); } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextIndexOptions.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticIndexOptions.java similarity index 92% rename from x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextIndexOptions.java rename to x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticIndexOptions.java index d1dcaab717a45..b411f28196325 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextIndexOptions.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticIndexOptions.java @@ -23,22 +23,22 @@ import java.util.Objects; /** - * Represents index options for a semantic_text field. - * We represent semantic_text index_options as nested within their respective type. For example: + * Represents index options for a semantic or semantic_text field. + * We represent these index_options as nested within their respective type. For example: * "index_options": { * "dense_vector": { * "type": "bbq_hnsw * } * } */ -public class SemanticTextIndexOptions implements ToXContent { +public class SemanticIndexOptions implements ToXContent { private static final String TYPE_FIELD = "type"; private final SupportedIndexOptions type; private final IndexOptions indexOptions; - public SemanticTextIndexOptions(SupportedIndexOptions type, IndexOptions indexOptions) { + public SemanticIndexOptions(SupportedIndexOptions type, IndexOptions indexOptions) { this.type = type; this.indexOptions = indexOptions; } @@ -61,8 +61,8 @@ public boolean equals(Object other) { return false; } - SemanticTextIndexOptions otherSemanticTextIndexOptions = (SemanticTextIndexOptions) other; - return type == otherSemanticTextIndexOptions.type && Objects.equals(indexOptions, otherSemanticTextIndexOptions.indexOptions); + SemanticIndexOptions otherSemanticIndexOptions = (SemanticIndexOptions) other; + return type == otherSemanticIndexOptions.type && Objects.equals(indexOptions, otherSemanticIndexOptions.indexOptions); } @Override diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java index 771a271b74bbf..428ea5817ea70 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java @@ -250,7 +250,7 @@ protected String getDefaultInferenceId() { } @Override - protected Parameter configureIndexOptionsParam() { + protected Parameter configureIndexOptionsParam() { return buildIndexOptionsParam( resolvedModelSettings -> defaultIndexOptions(indexVersionCreated, resolvedModelSettings), elementType -> defaultElementTypeToBfloat16(indexVersionCreated, elementType) @@ -374,7 +374,7 @@ protected void validateTaskType(MinimalServiceSettings modelSettings) { @Override protected void validateIndexOptions(MinimalServiceSettings modelSettings) { - SemanticTextIndexOptions indexOptions = this.indexOptions.get(); + SemanticIndexOptions indexOptions = this.indexOptions.get(); String inferenceId = this.inferenceId.get(); if (indexOptions == null) { @@ -387,7 +387,7 @@ protected void validateIndexOptions(MinimalServiceSettings modelSettings) { ); } - if (indexOptions.type() == SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR) { + if (indexOptions.type() == SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR) { if (modelSettings.taskType() != SPARSE_EMBEDDING) { throw new IllegalArgumentException( "Invalid task type for index options, required [" @@ -400,7 +400,7 @@ protected void validateIndexOptions(MinimalServiceSettings modelSettings) { return; } - if (indexOptions.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR) { + if (indexOptions.type() == SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR) { if (modelSettings.taskType() != TEXT_EMBEDDING && modelSettings.taskType() != EMBEDDING) { throw new IllegalArgumentException( "Invalid task type for index options, required [" @@ -620,7 +620,7 @@ public SemanticTextFieldType( String searchInferenceId, MinimalServiceSettings modelSettings, ChunkingSettings chunkingSettings, - SemanticTextIndexOptions indexOptions, + SemanticIndexOptions indexOptions, ObjectMapper inferenceField, boolean useLegacyFormat, boolean storesOriginalValuesInDocValues, @@ -693,7 +693,7 @@ public BlockLoader blockLoader(BlockLoaderContext blContext) { private static void configureSparseVectorMapperBuilder( IndexVersion indexVersionCreated, SparseVectorFieldMapper.Builder sparseVectorMapperBuilder, - SemanticTextIndexOptions indexOptions + SemanticIndexOptions indexOptions ) { if (indexOptions != null) { SparseVectorFieldMapper.SparseVectorIndexOptions sparseVectorIndexOptions = @@ -748,7 +748,7 @@ public static DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswDense return new DenseVectorFieldMapper.BBQHnswIndexOptions(m, efConstruction, false, rescoreVector, -1); } - static SemanticTextIndexOptions defaultIndexOptions(IndexVersion indexVersionCreated, MinimalServiceSettings modelSettings) { + static SemanticIndexOptions defaultIndexOptions(IndexVersion indexVersionCreated, MinimalServiceSettings modelSettings) { if (modelSettings == null) { return null; } @@ -764,8 +764,8 @@ static SemanticTextIndexOptions defaultIndexOptions(IndexVersion indexVersionCre return denseVectorIndexOptions == null && elementType == null ? null - : new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + : new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, new ExtendedDenseVectorIndexOptions(denseVectorIndexOptions, elementType) ); } @@ -776,7 +776,7 @@ static SemanticTextIndexOptions defaultIndexOptions(IndexVersion indexVersionCre return sparseVectorIndexOptions == null ? null - : new SemanticTextIndexOptions(SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, sparseVectorIndexOptions); + : new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, sparseVectorIndexOptions); } return null; diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java index b10c78aea33f8..17009f1b74b06 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java @@ -829,12 +829,12 @@ public void testInvalidInferenceEndpoints() { } } - private SemanticTextIndexOptions getDefaultSparseVectorIndexOptionsForMapper(MapperService mapperService) { + private SemanticIndexOptions getDefaultSparseVectorIndexOptionsForMapper(MapperService mapperService) { var mapperIndexVersion = mapperService.getIndexSettings().getIndexVersionCreated(); var defaultSparseVectorIndexOptions = SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(mapperIndexVersion); return defaultSparseVectorIndexOptions == null ? null - : new SemanticTextIndexOptions(SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, defaultSparseVectorIndexOptions); + : new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, defaultSparseVectorIndexOptions); } public void testInvalidTaskTypes() { @@ -902,9 +902,9 @@ public void testMultiFieldsSupport() throws IOException { IndexVersion indexVersion = SparseVectorFieldMapperTests.getIndexOptionsCompatibleIndexVersion(); SparseVectorFieldMapper.SparseVectorIndexOptions expectedIndexOptions = SparseVectorFieldMapper.SparseVectorIndexOptions .getDefaultIndexOptions(indexVersion); - SemanticTextIndexOptions semanticTextIndexOptions = expectedIndexOptions == null + SemanticIndexOptions semanticIndexOptions = expectedIndexOptions == null ? null - : new SemanticTextIndexOptions(SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, expectedIndexOptions); + : new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, expectedIndexOptions); var mapperService = createMapperServiceWithIndexVersion(fieldMapping(b -> { b.field("type", "text"); b.startObject("fields"); @@ -917,7 +917,7 @@ public void testMultiFieldsSupport() throws IOException { b.endObject(); b.endObject(); }), useLegacyFormat, indexVersion); - assertSemanticTextField(mapperService, "field.semantic", true, null, semanticTextIndexOptions); + assertSemanticTextField(mapperService, "field.semantic", true, null, semanticIndexOptions); mapperService = createMapperServiceWithIndexVersion(fieldMapping(b -> { b.field("type", "semantic_text"); @@ -931,7 +931,7 @@ public void testMultiFieldsSupport() throws IOException { b.endObject(); b.endObject(); }), useLegacyFormat, indexVersion); - assertSemanticTextField(mapperService, "field", true, null, semanticTextIndexOptions); + assertSemanticTextField(mapperService, "field", true, null, semanticIndexOptions); mapperService = createMapperServiceWithIndexVersion(fieldMapping(b -> { b.field("type", "semantic_text"); @@ -949,8 +949,8 @@ public void testMultiFieldsSupport() throws IOException { b.endObject(); b.endObject(); }), useLegacyFormat, indexVersion); - assertSemanticTextField(mapperService, "field", true, null, semanticTextIndexOptions); - assertSemanticTextField(mapperService, "field.semantic", true, null, semanticTextIndexOptions); + assertSemanticTextField(mapperService, "field", true, null, semanticIndexOptions); + assertSemanticTextField(mapperService, "field.semantic", true, null, semanticIndexOptions); Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> { b.field("type", "semantic_text"); @@ -1028,7 +1028,7 @@ public void testUpdateInferenceId_GivenModelSettings() throws IOException { givenModelSettings(oldInferenceId, previousModelSettings); final MapperService mapperService = mapperServiceForFieldWithModelSettings(fieldName, oldInferenceId, previousModelSettings); - final SemanticTextIndexOptions currentIndexOptions = extractCurrentIndexOptions(mapperService, fieldName); + final SemanticIndexOptions currentIndexOptions = extractCurrentIndexOptions(mapperService, fieldName); assertInferenceEndpoints(mapperService, fieldName, oldInferenceId, oldInferenceId); assertSemanticTextField(mapperService, fieldName, true, null, currentIndexOptions); assertEmbeddingsFieldMapperMatchesModel(mapperService, fieldName, oldModel); @@ -1091,17 +1091,14 @@ public void testUpdateInferenceId_GivenModelSettings() throws IOException { } } - private static SemanticTextIndexOptions extractCurrentIndexOptions(MapperService mapperService, String fieldName) { - SemanticTextIndexOptions currentIndexOptions = null; + private static SemanticIndexOptions extractCurrentIndexOptions(MapperService mapperService, String fieldName) { + SemanticIndexOptions currentIndexOptions = null; SemanticTextFieldMapper sfm = getSemanticFieldMapper(mapperService, fieldName); FieldMapper embeddingsMapper = sfm.fieldType().getEmbeddingsField(); if (embeddingsMapper instanceof DenseVectorFieldMapper dvm) { IndexOptions denseIndexOptions = dvm.fieldType().getIndexOptions(); if (denseIndexOptions != null) { - currentIndexOptions = new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, - denseIndexOptions - ); + currentIndexOptions = new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, denseIndexOptions); } } @@ -1414,7 +1411,7 @@ public void testSparseVectorIndexOptionsValidationAndMapping() throws IOExceptio var sparseVectorIndexOptions = SparseVectorFieldTypeTests.randomSparseVectorIndexOptions(); var expectedIndexOptions = sparseVectorIndexOptions == null ? null - : new SemanticTextIndexOptions(SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, sparseVectorIndexOptions); + : new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, sparseVectorIndexOptions); // should not throw an exception MapperService mapper = createMapperServiceWithIndexVersion(mapping(b -> { @@ -1453,7 +1450,7 @@ public void testSparseVectorMappingUpdate() throws IOException { IndexVersionUtils.getPreviousVersion(IndexVersions.SEMANTIC_TEXT_LEGACY_FORMAT_FORBIDDEN) ) : SparseVectorFieldMapperTests.getIndexOptionsCompatibleIndexVersion(); - final SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions(TaskType.SPARSE_EMBEDDING); + final SemanticIndexOptions indexOptions = randomSemanticIndexOptions(TaskType.SPARSE_EMBEDDING); String fieldName = "field"; MapperService mapperService = createMapperServiceWithIndexVersion( @@ -1462,17 +1459,17 @@ public void testSparseVectorMappingUpdate() throws IOException { indexVersion ); var expectedIndexOptions = (indexOptions == null) - ? new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, + ? new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion) ) : indexOptions; assertSemanticTextField(mapperService, fieldName, false, chunkingSettings, expectedIndexOptions); - final SemanticTextIndexOptions newIndexOptions = randomSemanticTextIndexOptions(TaskType.SPARSE_EMBEDDING); + final SemanticIndexOptions newIndexOptions = randomSemanticIndexOptions(TaskType.SPARSE_EMBEDDING); expectedIndexOptions = (newIndexOptions == null) - ? new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, + ? new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion) ) : newIndexOptions; @@ -1545,7 +1542,7 @@ private static void assertSemanticTextField( String fieldName, boolean expectedModelSettings, ChunkingSettings expectedChunkingSettings, - SemanticTextIndexOptions expectedIndexOptions + SemanticIndexOptions expectedIndexOptions ) { IndexVersion indexVersion = mapperService.getIndexSettings().getIndexVersionCreated(); SemanticTextFieldMapper semanticFieldMapper = getSemanticFieldMapper(mapperService, fieldName); @@ -1688,7 +1685,7 @@ public void testSuccessfulParse() throws IOException { }); ChunkingSettings chunkingSettings = null; // Some chunking settings configs can produce different Lucene docs counts - SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions(taskType); + SemanticIndexOptions indexOptions = randomSemanticIndexOptions(taskType); XContentBuilder mapping = mapping(b -> { addSemanticTextMapping( b, @@ -1709,8 +1706,8 @@ public void testSuccessfulParse() throws IOException { }); var expectedIndexOptions = (indexOptions == null) - ? new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, + ? new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion) ) : indexOptions; @@ -2000,7 +1997,7 @@ public void testSettingAndUpdatingChunkingSettings() throws IOException { ); final ChunkingSettings chunkingSettings = generateRandomChunkingSettings(false); - final SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions(TaskType.SPARSE_EMBEDDING); + final SemanticIndexOptions indexOptions = randomSemanticIndexOptions(TaskType.SPARSE_EMBEDDING); String fieldName = "field"; MapperService mapperService = createMapperService( @@ -2027,7 +2024,7 @@ public void testModelSettingsRequiredWithChunks() throws IOException { ); ChunkingSettings chunkingSettings = generateRandomChunkingSettings(false); - SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions(taskType); + SemanticIndexOptions indexOptions = randomSemanticIndexOptions(taskType); SemanticTextField randomSemanticText = randomSemanticText( useLegacyFormat, "field", @@ -2287,15 +2284,15 @@ public void testMappingWithEndpointMetadata() throws IOException { assertThat(parsedMapper.fieldType().getModelSettings().endpointMetadata(), equalTo(EndpointMetadata.EMPTY_INSTANCE)); } - private static SemanticTextIndexOptions defaultDenseVectorSemanticIndexOptions( + private static SemanticIndexOptions defaultDenseVectorSemanticIndexOptions( IndexVersion indexVersionCreated, License.OperationMode operationMode, Integer dims, DenseVectorFieldMapper.ElementType elementType, boolean experimentalFeaturesEnabled ) { - return new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + return new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, defaultDenseVectorIndexOptions( indexVersionCreated, operationMode == License.OperationMode.ENTERPRISE, @@ -2314,16 +2311,13 @@ private static DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswDens return new DenseVectorFieldMapper.BBQHnswIndexOptions(m, efConstruction, false, rescoreVector, -1); } - private static SemanticTextIndexOptions defaultBbqHnswSemanticTextIndexOptions() { - return new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, - defaultBbqHnswDenseVectorIndexOptions() - ); + private static SemanticIndexOptions defaultBbqHnswSemanticIndexOptions() { + return new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, defaultBbqHnswDenseVectorIndexOptions()); } - private static SemanticTextIndexOptions defaultSparseVectorIndexOptions(IndexVersion indexVersion) { - return new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, + private static SemanticIndexOptions defaultSparseVectorIndexOptions(IndexVersion indexVersion) { + return new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion) ); } @@ -2364,7 +2358,7 @@ public void testDefaultIndexOptions() throws IOException { } } - private SemanticTextIndexOptions getExpectedDefaultIndexOptions( + private SemanticIndexOptions getExpectedDefaultIndexOptions( TaskType taskType, DenseVectorFieldMapper.ElementType elementType, Integer dimensions, @@ -2378,7 +2372,7 @@ private SemanticTextIndexOptions getExpectedDefaultIndexOptions( if (floatFamilyElementType && SemanticTextFieldMapper.setExplicitIndexOptionsForSemanticText(indexVersion) && dimensions >= DenseVectorFieldMapper.BBQ_MIN_DIMS) { - yield defaultBbqHnswSemanticTextIndexOptions(); + yield defaultBbqHnswSemanticIndexOptions(); } else if (floatFamilyElementType) { yield defaultDenseVectorSemanticIndexOptions( indexVersion, @@ -2421,8 +2415,8 @@ public void testSpecifiedDenseVectorIndexOptions() throws IOException { "field", true, null, - new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, new DenseVectorFieldMapper.Int4HnswIndexOptions(20, 90, false, null, -1) ) ); @@ -2448,8 +2442,8 @@ public void testSpecifiedDenseVectorIndexOptions() throws IOException { "field", true, null, - new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, new DenseVectorFieldMapper.Int4HnswIndexOptions(16, 100, false, null, -1) ) ); @@ -2524,7 +2518,7 @@ public void testSetElementTypeInDenseVectorIndexOptions() throws IOException { b.endObject(); }), useLegacyFormat, indexVersion); - SemanticTextIndexOptions expectedDefaultIndexOptions = getExpectedDefaultIndexOptions( + SemanticIndexOptions expectedDefaultIndexOptions = getExpectedDefaultIndexOptions( TaskType.TEXT_EMBEDDING, DenseVectorFieldMapper.ElementType.FLOAT, 100, @@ -2540,8 +2534,8 @@ public void testSetElementTypeInDenseVectorIndexOptions() throws IOException { "field", true, null, - new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, new ExtendedDenseVectorIndexOptions(expectedDenseVectorIndexOptions, DenseVectorFieldMapper.ElementType.FLOAT) ) ); @@ -2571,8 +2565,8 @@ public void testSetElementTypeInDenseVectorIndexOptions() throws IOException { "field", true, null, - new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, + new SemanticIndexOptions( + SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, new ExtendedDenseVectorIndexOptions( new DenseVectorFieldMapper.Int4HnswIndexOptions(20, 90, false, null, -1), DenseVectorFieldMapper.ElementType.FLOAT @@ -2637,7 +2631,7 @@ public void testSpecificSparseVectorIndexOptions() throws IOException { "field", true, null, - new SemanticTextIndexOptions(SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, testIndexOptions) + new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, testIndexOptions) ); } } @@ -2725,25 +2719,22 @@ public void testSupportedIndexVersions() throws IOException { } } - public static SemanticTextIndexOptions randomSemanticTextIndexOptions() { + public static SemanticIndexOptions randomSemanticIndexOptions() { TaskType taskType = randomFrom(TaskType.SPARSE_EMBEDDING, TaskType.TEXT_EMBEDDING); - return randomSemanticTextIndexOptions(taskType); + return randomSemanticIndexOptions(taskType); } - public static SemanticTextIndexOptions randomSemanticTextIndexOptions(TaskType taskType) { + public static SemanticIndexOptions randomSemanticIndexOptions(TaskType taskType) { if (taskType == TaskType.TEXT_EMBEDDING) { return randomBoolean() ? null - : new SemanticTextIndexOptions(SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR, randomIndexOptionsAll()); + : new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.DENSE_VECTOR, randomIndexOptionsAll()); } if (taskType == TaskType.SPARSE_EMBEDDING) { return randomBoolean() ? null - : new SemanticTextIndexOptions( - SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, - randomSparseVectorIndexOptions(false) - ); + : new SemanticIndexOptions(SemanticIndexOptions.SupportedIndexOptions.SPARSE_VECTOR, randomSparseVectorIndexOptions(false)); } return null; @@ -2752,9 +2743,9 @@ public static SemanticTextIndexOptions randomSemanticTextIndexOptions(TaskType t private static DenseVectorFieldMapper.ElementType getExpectedElementType( IndexVersion indexVersion, DenseVectorFieldMapper.ElementType modelElementType, - @Nullable SemanticTextIndexOptions semanticTextIndexOptions + @Nullable SemanticIndexOptions semanticIndexOptions ) { - if (semanticTextIndexOptions != null && semanticTextIndexOptions.indexOptions() instanceof ExtendedDenseVectorIndexOptions edvio) { + if (semanticIndexOptions != null && semanticIndexOptions.indexOptions() instanceof ExtendedDenseVectorIndexOptions edvio) { if (edvio.getElementType() != null) { return edvio.getElementType(); } @@ -2779,7 +2770,7 @@ private static void addSemanticTextMapping( String inferenceId, String searchInferenceId, ChunkingSettings chunkingSettings, - SemanticTextIndexOptions indexOptions + SemanticIndexOptions indexOptions ) throws IOException { mappingBuilder.startObject(fieldName); mappingBuilder.field("type", SemanticTextFieldMapper.CONTENT_TYPE);