@@ -290,6 +290,11 @@ public Builder elementType(ElementType elementType) {
290
290
return this ;
291
291
}
292
292
293
+ public Builder indexOptions (IndexOptions indexOptions ) {
294
+ this .indexOptions .setValue (indexOptions );
295
+ return this ;
296
+ }
297
+
293
298
@ Override
294
299
public DenseVectorFieldMapper build (MapperBuilderContext context ) {
295
300
// Validate again here because the dimensions or element type could have been set programmatically,
@@ -1221,7 +1226,7 @@ public final String toString() {
1221
1226
public abstract VectorSimilarityFunction vectorSimilarityFunction (IndexVersion indexVersion , ElementType elementType );
1222
1227
}
1223
1228
1224
- abstract static class IndexOptions implements ToXContent {
1229
+ public abstract static class IndexOptions implements ToXContent {
1225
1230
final VectorIndexType type ;
1226
1231
1227
1232
IndexOptions (VectorIndexType type ) {
@@ -1230,21 +1235,36 @@ abstract static class IndexOptions implements ToXContent {
1230
1235
1231
1236
abstract KnnVectorsFormat getVectorsFormat (ElementType elementType );
1232
1237
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 ) {
1235
1249
throw new IllegalArgumentException (
1236
1250
"[element_type] cannot be [" + elementType .toString () + "] when using index type [" + type + "]"
1237
1251
);
1238
1252
}
1253
+ return validElementType ;
1239
1254
}
1240
1255
1241
1256
abstract boolean updatableTo (IndexOptions update );
1242
1257
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 );
1246
1266
}
1247
- throw new IllegalArgumentException ( type . name + " only supports even dimensions; provided=" + dim ) ;
1267
+ return supportsDimension ;
1248
1268
}
1249
1269
1250
1270
abstract boolean doEquals (IndexOptions other );
@@ -1747,12 +1767,12 @@ boolean updatableTo(IndexOptions update) {
1747
1767
1748
1768
}
1749
1769
1750
- static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1770
+ public static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1751
1771
private final int m ;
1752
1772
private final int efConstruction ;
1753
1773
private final Float confidenceInterval ;
1754
1774
1755
- Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
1775
+ public Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
1756
1776
super (VectorIndexType .INT8_HNSW , rescoreVector );
1757
1777
this .m = m ;
1758
1778
this .efConstruction = efConstruction ;
@@ -1890,11 +1910,11 @@ public String toString() {
1890
1910
}
1891
1911
}
1892
1912
1893
- static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1913
+ public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1894
1914
private final int m ;
1895
1915
private final int efConstruction ;
1896
1916
1897
- BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
1917
+ public BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
1898
1918
super (VectorIndexType .BBQ_HNSW , rescoreVector );
1899
1919
this .m = m ;
1900
1920
this .efConstruction = efConstruction ;
@@ -1936,11 +1956,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
1936
1956
}
1937
1957
1938
1958
@ 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
+ );
1942
1965
}
1943
- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
1966
+ return supportsDimension ;
1944
1967
}
1945
1968
}
1946
1969
@@ -1984,15 +2007,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
1984
2007
}
1985
2008
1986
2009
@ 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
+ );
1990
2016
}
1991
- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
2017
+ return supportsDimension ;
1992
2018
}
2019
+
1993
2020
}
1994
2021
1995
- record RescoreVector (float oversample ) implements ToXContentObject {
2022
+ public record RescoreVector (float oversample ) implements ToXContentObject {
1996
2023
static final String NAME = "rescore_vector" ;
1997
2024
static final String OVERSAMPLE = "oversample" ;
1998
2025
@@ -2311,6 +2338,10 @@ int getVectorDimensions() {
2311
2338
ElementType getElementType () {
2312
2339
return elementType ;
2313
2340
}
2341
+
2342
+ public IndexOptions getIndexOptions () {
2343
+ return indexOptions ;
2344
+ }
2314
2345
}
2315
2346
2316
2347
private final IndexOptions indexOptions ;
0 commit comments