Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static class Builder extends FieldMapper.Builder {
protected final Parameter<String> inferenceId;
protected final Parameter<String> searchInferenceId;
protected final Parameter<MinimalServiceSettings> modelSettings;
protected final Parameter<SemanticTextIndexOptions> indexOptions;
protected final Parameter<SemanticIndexOptions> indexOptions;
protected final Parameter<ChunkingSettings> chunkingSettings;
protected final Parameter<Map<String, String>> meta;

Expand Down Expand Up @@ -268,7 +268,7 @@ protected Parameter<MinimalServiceSettings> configureModelSettingsParam() {
).acceptsNull().setMergeValidator(SemanticFieldMapper::canMergeModelSettings);
}

protected Parameter<SemanticTextIndexOptions> configureIndexOptionsParam() {
protected Parameter<SemanticIndexOptions> configureIndexOptionsParam() {
return buildIndexOptionsParam(SemanticFieldMapper::defaultIndexOptions, SemanticFieldMapper::defaultElementTypeToBfloat16);
}

Expand All @@ -279,8 +279,8 @@ protected Parameter<SemanticTextIndexOptions> 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<SemanticTextIndexOptions> buildIndexOptionsParam(
Function<MinimalServiceSettings, SemanticTextIndexOptions> defaultIndexOptionsResolver,
protected Parameter<SemanticIndexOptions> buildIndexOptionsParam(
Function<MinimalServiceSettings, SemanticIndexOptions> defaultIndexOptionsResolver,
Predicate<DenseVectorFieldMapper.ElementType> bfloat16Resolver
) {
return new Parameter<>(
Expand All @@ -296,13 +296,13 @@ protected Parameter<SemanticTextIndexOptions> 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();
Expand All @@ -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)
);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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"
);
Expand Down Expand Up @@ -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;

Expand All @@ -969,7 +969,7 @@ public SemanticFieldType(
String searchInferenceId,
MinimalServiceSettings modelSettings,
ChunkingSettings chunkingSettings,
SemanticTextIndexOptions indexOptions,
SemanticIndexOptions indexOptions,
ObjectMapper inferenceField,
boolean storesOriginalValuesInDocValues,
Map<String, String> meta
Expand Down Expand Up @@ -1010,7 +1010,7 @@ public ChunkingSettings getChunkingSettings() {
return chunkingSettings;
}

public SemanticTextIndexOptions getIndexOptions() {
public SemanticIndexOptions getIndexOptions() {
return indexOptions;
}

Expand Down Expand Up @@ -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,
Expand All @@ -1244,18 +1244,16 @@ protected static SemanticTextIndexOptions parseIndexOptionsFromMap(
throw new IllegalArgumentException("Too many index options provided, found [" + map.keySet() + "]");
}
Map.Entry<String, Object> entry = map.entrySet().iterator().next();
SemanticTextIndexOptions.SupportedIndexOptions indexOptions = SemanticTextIndexOptions.SupportedIndexOptions.fromValue(
entry.getKey()
);
SemanticIndexOptions.SupportedIndexOptions indexOptions = SemanticIndexOptions.SupportedIndexOptions.fromValue(entry.getKey());
@SuppressWarnings("unchecked")
Map<String, Object> indexOptionsMap = (Map<String, Object>) 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;
Expand All @@ -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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected String getDefaultInferenceId() {
}

@Override
protected Parameter<SemanticTextIndexOptions> configureIndexOptionsParam() {
protected Parameter<SemanticIndexOptions> configureIndexOptionsParam() {
return buildIndexOptionsParam(
resolvedModelSettings -> defaultIndexOptions(indexVersionCreated, resolvedModelSettings),
elementType -> defaultElementTypeToBfloat16(indexVersionCreated, elementType)
Expand Down Expand Up @@ -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) {
Expand All @@ -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 ["
Expand All @@ -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 ["
Expand Down Expand Up @@ -620,7 +620,7 @@ public SemanticTextFieldType(
String searchInferenceId,
MinimalServiceSettings modelSettings,
ChunkingSettings chunkingSettings,
SemanticTextIndexOptions indexOptions,
SemanticIndexOptions indexOptions,
ObjectMapper inferenceField,
boolean useLegacyFormat,
boolean storesOriginalValuesInDocValues,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
);
}
Expand All @@ -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;
Expand Down
Loading
Loading