@@ -290,6 +290,11 @@ public Builder elementType(ElementType elementType) {
290290 return this ;
291291 }
292292
293+ public Builder indexOptions (IndexOptions indexOptions ) {
294+ this .indexOptions .setValue (indexOptions );
295+ return this ;
296+ }
297+
293298 @ Override
294299 public DenseVectorFieldMapper build (MapperBuilderContext context ) {
295300 // Validate again here because the dimensions or element type could have been set programmatically,
@@ -1221,7 +1226,7 @@ public final String toString() {
12211226 public abstract VectorSimilarityFunction vectorSimilarityFunction (IndexVersion indexVersion , ElementType elementType );
12221227 }
12231228
1224- abstract static class IndexOptions implements ToXContent {
1229+ public abstract static class IndexOptions implements ToXContent {
12251230 final VectorIndexType type ;
12261231
12271232 IndexOptions (VectorIndexType type ) {
@@ -1230,21 +1235,36 @@ abstract static class IndexOptions implements ToXContent {
12301235
12311236 abstract KnnVectorsFormat getVectorsFormat (ElementType elementType );
12321237
1233- final void validateElementType (ElementType elementType ) {
1234- if (type .supportsElementType (elementType ) == false ) {
1238+ public boolean validate (ElementType elementType , int dim , boolean throwOnError ) {
1239+ return validateElementType (elementType , throwOnError ) && validateDimension (dim , throwOnError );
1240+ }
1241+
1242+ public boolean validateElementType (ElementType elementType ) {
1243+ return validateElementType (elementType , true );
1244+ }
1245+
1246+ final boolean validateElementType (ElementType elementType , boolean throwOnError ) {
1247+ boolean validElementType = type .supportsElementType (elementType );
1248+ if (throwOnError && validElementType == false ) {
12351249 throw new IllegalArgumentException (
12361250 "[element_type] cannot be [" + elementType .toString () + "] when using index type [" + type + "]"
12371251 );
12381252 }
1253+ return validElementType ;
12391254 }
12401255
12411256 abstract boolean updatableTo (IndexOptions update );
12421257
1243- public void validateDimension (int dim ) {
1244- if (type .supportsDimension (dim )) {
1245- return ;
1258+ public boolean validateDimension (int dim ) {
1259+ return validateDimension (dim , true );
1260+ }
1261+
1262+ public boolean validateDimension (int dim , boolean throwOnError ) {
1263+ boolean supportsDimension = type .supportsDimension (dim );
1264+ if (throwOnError && supportsDimension == false ) {
1265+ throw new IllegalArgumentException (type .name + " only supports even dimensions; provided=" + dim );
12461266 }
1247- throw new IllegalArgumentException ( type . name + " only supports even dimensions; provided=" + dim ) ;
1267+ return supportsDimension ;
12481268 }
12491269
12501270 abstract boolean doEquals (IndexOptions other );
@@ -1747,12 +1767,12 @@ boolean updatableTo(IndexOptions update) {
17471767
17481768 }
17491769
1750- static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1770+ public static class Int8HnswIndexOptions extends QuantizedIndexOptions {
17511771 private final int m ;
17521772 private final int efConstruction ;
17531773 private final Float confidenceInterval ;
17541774
1755- Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
1775+ public Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
17561776 super (VectorIndexType .INT8_HNSW , rescoreVector );
17571777 this .m = m ;
17581778 this .efConstruction = efConstruction ;
@@ -1890,11 +1910,11 @@ public String toString() {
18901910 }
18911911 }
18921912
1893- static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1913+ public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
18941914 private final int m ;
18951915 private final int efConstruction ;
18961916
1897- BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
1917+ public BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
18981918 super (VectorIndexType .BBQ_HNSW , rescoreVector );
18991919 this .m = m ;
19001920 this .efConstruction = efConstruction ;
@@ -1936,11 +1956,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19361956 }
19371957
19381958 @ Override
1939- public void validateDimension (int dim ) {
1940- if (type .supportsDimension (dim )) {
1941- return ;
1959+ public boolean validateDimension (int dim , boolean throwOnError ) {
1960+ boolean supportsDimension = type .supportsDimension (dim );
1961+ if (throwOnError && supportsDimension == false ) {
1962+ throw new IllegalArgumentException (
1963+ type .name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
1964+ );
19421965 }
1943- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
1966+ return supportsDimension ;
19441967 }
19451968 }
19461969
@@ -1984,15 +2007,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19842007 }
19852008
19862009 @ Override
1987- public void validateDimension (int dim ) {
1988- if (type .supportsDimension (dim )) {
1989- return ;
2010+ public boolean validateDimension (int dim , boolean throwOnError ) {
2011+ boolean supportsDimension = type .supportsDimension (dim );
2012+ if (throwOnError && supportsDimension == false ) {
2013+ throw new IllegalArgumentException (
2014+ type .name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
2015+ );
19902016 }
1991- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
2017+ return supportsDimension ;
19922018 }
2019+
19932020 }
19942021
1995- record RescoreVector (float oversample ) implements ToXContentObject {
2022+ public record RescoreVector (float oversample ) implements ToXContentObject {
19962023 static final String NAME = "rescore_vector" ;
19972024 static final String OVERSAMPLE = "oversample" ;
19982025
@@ -2311,6 +2338,10 @@ int getVectorDimensions() {
23112338 ElementType getElementType () {
23122339 return elementType ;
23132340 }
2341+
2342+ public IndexOptions getIndexOptions () {
2343+ return indexOptions ;
2344+ }
23142345 }
23152346
23162347 private final IndexOptions indexOptions ;
0 commit comments