Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
67b7623
Add index_options parameter to semantic_text field mapping
kderusso Jan 8, 2025
d822301
Cleanup & tests
kderusso Jan 10, 2025
251d22c
Update docs
kderusso Jan 10, 2025
8724cce
Update docs/changelog/119967.yaml
kderusso Jan 10, 2025
6445a44
Merge branch 'main' into kderusso/semantic-text-index-options
kderusso Jan 10, 2025
26de9d3
Merge branch 'main' into kderusso/semantic-text-index-options
kderusso Jan 10, 2025
948d596
Addressed some PR feedbak
kderusso Jan 13, 2025
860ebc4
Update yaml tests
kderusso Jan 14, 2025
07284f5
Refactoring
kderusso Jan 14, 2025
3c1f6e1
Cleanup
kderusso Jan 14, 2025
b4f45ea
Merge main into kderusso/semantic-text-index-options
kderusso Jan 15, 2025
5d2f48b
Fix some tests
kderusso Jan 15, 2025
47b4e23
Hack in inferring text_embedding task type from index options
kderusso Jan 16, 2025
6f72f00
[CI] Auto commit changes from spotless
Jan 16, 2025
1602b09
Fix error inferring model settings
kderusso Jan 17, 2025
c7f99c1
Merge branch 'main' into kderusso/semantic-text-index-options
kderusso Jan 17, 2025
d9db3b4
Update docs
kderusso Jan 17, 2025
4151cca
Update tests
kderusso Jan 17, 2025
d96dadc
Update docs/reference/mapping/types/semantic-text.asciidoc
kderusso Jan 21, 2025
701dab5
Address some minor PR feedback
kderusso Jan 21, 2025
453f132
Remove partial model_settings with inferred task type
kderusso Jan 21, 2025
e7744a7
Cleanup
kderusso Jan 21, 2025
14fde82
Remove unnecessary changes
kderusso Jan 21, 2025
53ab0ac
Merge from main
kderusso Mar 31, 2025
59bde7d
Fix errors from merge
kderusso Mar 31, 2025
0ce700e
[CI] Auto commit changes from spotless
Mar 31, 2025
73f7017
Cleanup
kderusso Mar 31, 2025
0ab598c
Checkpoint, saving changes before merge
kderusso Apr 4, 2025
560d6c2
Merge from main
kderusso Apr 4, 2025
498e6c9
Update parsing
kderusso Apr 4, 2025
228b308
[CI] Auto commit changes from spotless
Apr 4, 2025
5ebb84c
Stash changes
kderusso Apr 7, 2025
8ea0167
Merge from main
kderusso Apr 15, 2025
e41022e
Fix compile errors
kderusso Apr 15, 2025
959b1d3
[CI] Auto commit changes from spotless
Apr 15, 2025
8701954
Cleanup error
kderusso Apr 17, 2025
fe63309
fix test
kderusso Apr 17, 2025
8db6942
fix test
kderusso Apr 17, 2025
7affc70
Fix another test
kderusso Apr 18, 2025
df06595
A bit of cleanup
kderusso Apr 18, 2025
5bf9d2f
Merge from main
kderusso Apr 18, 2025
34b2153
Fix tests
kderusso Apr 18, 2025
be4136b
Spotless
kderusso Apr 18, 2025
216f8bc
Respect index options if set over defaults
kderusso Apr 18, 2025
651fede
Cleanup
kderusso Apr 18, 2025
3abdc75
[CI] Auto commit changes from spotless
Apr 18, 2025
27b4f9e
Support updating to compatible versions, add some cleanup and validation
kderusso Apr 18, 2025
9fb403b
Merge from main
kderusso Apr 30, 2025
7b4d424
Remove test that can't be done here - needs to be unit test
kderusso Apr 30, 2025
4b11083
Add validation
kderusso Apr 30, 2025
d65c011
Cleanup
kderusso Apr 30, 2025
4f933fc
Fix some yaml tests
kderusso May 2, 2025
07829e8
Merge from main
kderusso Jun 3, 2025
1d524b2
[CI] Auto commit changes from spotless
Jun 3, 2025
f9127eb
Happy path early index validation works now; edge cases surrounding d…
kderusso Jun 4, 2025
9912426
Always emit index options, even when using defaults
kderusso Jun 6, 2025
dca3e54
Minor cleanup
kderusso Jun 6, 2025
7a5a29a
Fix test compilation failures
kderusso Jun 9, 2025
279d4c2
Fix some tests
kderusso Jun 9, 2025
a452d8e
Continue to iterate on test failures
kderusso Jun 10, 2025
9a0ca94
Remove index options from inference field metadata as it is only need…
kderusso Jun 11, 2025
3e1c941
Fix some tests
kderusso Jun 11, 2025
e9bfdc8
Remove transport version, no longer needed
kderusso Jun 11, 2025
40ed2fd
Fix yaml tests
kderusso Jun 11, 2025
78bf4a2
Add tests
kderusso Jun 12, 2025
2cc4191
Merge main
kderusso Jun 12, 2025
c909699
IndexOptions don't need to implement Writeable
kderusso Jun 12, 2025
64b787f
[CI] Auto commit changes from spotless
Jun 12, 2025
bad0585
Refactor - move SemanticTextIndexOptions
kderusso Jun 12, 2025
3036adf
Remove writeable
kderusso Jun 12, 2025
66d65b5
Move index_options parsing to semantic text field mapper
kderusso Jun 13, 2025
2152926
Cleanup
kderusso Jun 13, 2025
26393a5
Fix test compilation issue
kderusso Jun 13, 2025
9390356
Cleanup
kderusso Jun 13, 2025
a1aaffc
Remove whitespace
kderusso Jun 13, 2025
f6d58a1
Remove writeables from index options
kderusso Jun 13, 2025
2ef8b1d
Disable merging null options?
kderusso Jun 13, 2025
b044184
Add docs
kderusso Jun 13, 2025
aa12294
[CI] Auto commit changes from spotless
Jun 13, 2025
1c4104a
Revert "Disable merging null options?"
kderusso Jun 13, 2025
1886969
Merge update from main
kderusso Jun 16, 2025
7c23a7c
Remove default serialization
kderusso Jun 16, 2025
aac9ab7
Merge from main
kderusso Jun 16, 2025
b08e2a1
Include default index option type to defaults
kderusso Jun 16, 2025
9e247c9
[CI] Auto commit changes from spotless
Jun 16, 2025
3be5eda
Go back to allowing null updateS
kderusso Jun 16, 2025
c94955e
Cleanup
kderusso Jun 16, 2025
e993671
Fix validation error
kderusso Jun 16, 2025
b843047
Revert "Include default index option type to defaults"
kderusso Jun 16, 2025
aedfafe
Update tests
kderusso Jun 16, 2025
062eeac
Revert "Update tests"
kderusso Jun 16, 2025
65a3d02
Better fix for null inputs
kderusso Jun 16, 2025
fa22c56
Merge branch 'main' into kderusso/semantic-text-index-options
kderusso Jun 17, 2025
57bd949
Remove redundant merge validation
kderusso Jun 17, 2025
2db090c
Merge branch 'main' into kderusso/semantic-text-index-options
kderusso Jun 17, 2025
a6c04a5
Merge branch 'main' into kderusso/semantic-text-index-options
kderusso Jun 17, 2025
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
5 changes: 5 additions & 0 deletions docs/changelog/119967.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 119967
summary: Add `index_options` to `semantic_text` field mappings
area: Mapping
type: enhancement
issues: [ ]
8 changes: 8 additions & 0 deletions docs/reference/mapping/types/semantic-text.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ You can update this parameter by using the <<indices-put-mapping, Update mapping
Use the <<put-inference-api>> to create the endpoint.
If not specified, the {infer} endpoint defined by `inference_id` will be used at both index and query time.

`index_options`::
(Optional, string) Specifies configurable index options for indexing documents.
For dense vector models, the configuration of `index_options` uses the defined <<dense-vector-index-options>> configuration and defaults for dense vectors.
There are currently no supported index options for sparse models.

WARNING: Index options are not validated against inference IDs at index creation time.
If index options are specified for a sparse vector model they will be ignored.

[discrete]
[[infer-endpoint-validation]]
==== {infer-cap} endpoint validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
Expand Down Expand Up @@ -284,6 +285,11 @@ public Builder elementType(ElementType elementType) {
return this;
}

public Builder indexOptions(IndexOptions indexOptions) {
this.indexOptions.setValue(indexOptions);
return this;
}

@Override
public DenseVectorFieldMapper build(MapperBuilderContext context) {
// Validate again here because the dimensions or element type could have been set programmatically,
Expand Down Expand Up @@ -1182,7 +1188,7 @@ public final String toString() {
public abstract VectorSimilarityFunction vectorSimilarityFunction(IndexVersion indexVersion, ElementType elementType);
}

abstract static class IndexOptions implements ToXContent {
public abstract static class IndexOptions implements ToXContent {
final VectorIndexType type;

IndexOptions(VectorIndexType type) {
Expand Down Expand Up @@ -1230,7 +1236,7 @@ public final int hashCode() {
}
}

private enum VectorIndexType {
public enum VectorIndexType {
HNSW("hnsw", false) {
@Override
public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOptionsMap) {
Expand All @@ -1257,6 +1263,11 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return true;
}

@Override
public Set<String> allowedOptions() {
return Set.of("m", "ef_construction");
}
},
INT8_HNSW("int8_hnsw", true) {
@Override
Expand Down Expand Up @@ -1289,6 +1300,11 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return true;
}

@Override
public Set<String> allowedOptions() {
return Set.of("m", "ef_construction", "confidence_interval");
}
},
INT4_HNSW("int4_hnsw", true) {
public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOptionsMap) {
Expand Down Expand Up @@ -1320,6 +1336,11 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return dims % 2 == 0;
}

@Override
public Set<String> allowedOptions() {
return Set.of("m", "ef_construction", "confidence_interval");
}
},
FLAT("flat", false) {
@Override
Expand All @@ -1337,6 +1358,11 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return true;
}

@Override
public Set<String> allowedOptions() {
return Set.of();
}
},
INT8_FLAT("int8_flat", true) {
@Override
Expand All @@ -1359,6 +1385,11 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return true;
}

@Override
public Set<String> allowedOptions() {
return Set.of("confidence_interval");
}
},
INT4_FLAT("int4_flat", true) {
@Override
Expand All @@ -1381,6 +1412,11 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return dims % 2 == 0;
}

@Override
public Set<String> allowedOptions() {
return Set.of("confidence_interval");
}
},
BBQ_HNSW("bbq_hnsw", true) {
@Override
Expand Down Expand Up @@ -1408,6 +1444,11 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return dims >= BBQ_MIN_DIMS;
}

@Override
public Set<String> allowedOptions() {
return Set.of("m", "ef_construction");
}
},
BBQ_FLAT("bbq_flat", true) {
@Override
Expand All @@ -1425,9 +1466,14 @@ public boolean supportsElementType(ElementType elementType) {
public boolean supportsDimension(int dims) {
return dims >= BBQ_MIN_DIMS;
}

@Override
public Set<String> allowedOptions() {
return Set.of();
}
};

static Optional<VectorIndexType> fromString(String type) {
public static Optional<VectorIndexType> fromString(String type) {
return Stream.of(VectorIndexType.values()).filter(vectorIndexType -> vectorIndexType.name.equals(type)).findFirst();
}

Expand All @@ -1439,12 +1485,14 @@ static Optional<VectorIndexType> fromString(String type) {
this.quantized = quantized;
}

abstract IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOptionsMap);
public abstract IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOptionsMap);

public abstract boolean supportsElementType(ElementType elementType);

public abstract boolean supportsDimension(int dims);

public abstract Set<String> allowedOptions();

public boolean isQuantized() {
return quantized;
}
Expand Down Expand Up @@ -2321,7 +2369,7 @@ public FieldMapper.Builder getMergeBuilder() {
return new Builder(leafName(), indexCreatedVersion).init(this);
}

private static IndexOptions parseIndexOptions(String fieldName, Object propNode) {
public static IndexOptions parseIndexOptions(String fieldName, Object propNode) {
@SuppressWarnings("unchecked")
Map<String, ?> indexOptionsMap = (Map<String, ?>) propNode;
Object typeNode = indexOptionsMap.remove("type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Set;

import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.SEMANTIC_TEXT_INDEX_OPTIONS;
import static org.elasticsearch.xpack.inference.queries.SemanticKnnVectorQueryRewriteInterceptor.SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED;
import static org.elasticsearch.xpack.inference.queries.SemanticMatchQueryRewriteInterceptor.SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED;
import static org.elasticsearch.xpack.inference.queries.SemanticSparseVectorQueryRewriteInterceptor.SEMANTIC_SPARSE_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED;
Expand Down Expand Up @@ -52,7 +53,8 @@ public Set<NodeFeature> getTestFeatures() {
SEMANTIC_MATCH_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
SEMANTIC_SPARSE_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
SemanticInferenceMetadataFieldsMapper.EXPLICIT_NULL_FIXES,
SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED
SEMANTIC_KNN_VECTOR_QUERY_REWRITE_INTERCEPTION_SUPPORTED,
SEMANTIC_TEXT_INDEX_OPTIONS
);
}
}
Loading