@@ -304,6 +304,11 @@ public Builder elementType(ElementType elementType) {
304304 return this ;
305305 }
306306
307+ public Builder indexOptions (IndexOptions indexOptions ) {
308+ this .indexOptions .setValue (indexOptions );
309+ return this ;
310+ }
311+
307312 @ Override
308313 public DenseVectorFieldMapper build (MapperBuilderContext context ) {
309314 // Validate again here because the dimensions or element type could have been set programmatically,
@@ -1202,7 +1207,7 @@ public final String toString() {
12021207 public abstract VectorSimilarityFunction vectorSimilarityFunction (IndexVersion indexVersion , ElementType elementType );
12031208 }
12041209
1205- abstract static class IndexOptions implements ToXContent {
1210+ public abstract static class IndexOptions implements ToXContent {
12061211 final VectorIndexType type ;
12071212
12081213 IndexOptions (VectorIndexType type ) {
@@ -1211,21 +1216,36 @@ abstract static class IndexOptions implements ToXContent {
12111216
12121217 abstract KnnVectorsFormat getVectorsFormat (ElementType elementType );
12131218
1214- final void validateElementType (ElementType elementType ) {
1215- if (type .supportsElementType (elementType ) == false ) {
1219+ public boolean validate (ElementType elementType , int dim , boolean throwOnError ) {
1220+ return validateElementType (elementType , throwOnError ) && validateDimension (dim , throwOnError );
1221+ }
1222+
1223+ public boolean validateElementType (ElementType elementType ) {
1224+ return validateElementType (elementType , true );
1225+ }
1226+
1227+ final boolean validateElementType (ElementType elementType , boolean throwOnError ) {
1228+ boolean validElementType = type .supportsElementType (elementType );
1229+ if (throwOnError && validElementType == false ) {
12161230 throw new IllegalArgumentException (
12171231 "[element_type] cannot be [" + elementType .toString () + "] when using index type [" + type + "]"
12181232 );
12191233 }
1234+ return validElementType ;
12201235 }
12211236
12221237 abstract boolean updatableTo (IndexOptions update );
12231238
1224- public void validateDimension (int dim ) {
1225- if (type .supportsDimension (dim )) {
1226- return ;
1239+ public boolean validateDimension (int dim ) {
1240+ return validateDimension (dim , true );
1241+ }
1242+
1243+ public boolean validateDimension (int dim , boolean throwOnError ) {
1244+ boolean supportsDimension = type .supportsDimension (dim );
1245+ if (throwOnError && supportsDimension == false ) {
1246+ throw new IllegalArgumentException (type .name + " only supports even dimensions; provided=" + dim );
12271247 }
1228- throw new IllegalArgumentException ( type . name + " only supports even dimensions; provided=" + dim ) ;
1248+ return supportsDimension ;
12291249 }
12301250
12311251 abstract boolean doEquals (IndexOptions other );
@@ -1734,12 +1754,12 @@ boolean updatableTo(IndexOptions update) {
17341754
17351755 }
17361756
1737- static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1757+ public static class Int8HnswIndexOptions extends QuantizedIndexOptions {
17381758 private final int m ;
17391759 private final int efConstruction ;
17401760 private final Float confidenceInterval ;
17411761
1742- Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
1762+ public Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
17431763 super (VectorIndexType .INT8_HNSW , rescoreVector );
17441764 this .m = m ;
17451765 this .efConstruction = efConstruction ;
@@ -1877,11 +1897,11 @@ public String toString() {
18771897 }
18781898 }
18791899
1880- static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1900+ public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
18811901 private final int m ;
18821902 private final int efConstruction ;
18831903
1884- BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
1904+ public BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
18851905 super (VectorIndexType .BBQ_HNSW , rescoreVector );
18861906 this .m = m ;
18871907 this .efConstruction = efConstruction ;
@@ -1923,11 +1943,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19231943 }
19241944
19251945 @ Override
1926- public void validateDimension (int dim ) {
1927- if (type .supportsDimension (dim )) {
1928- return ;
1946+ public boolean validateDimension (int dim , boolean throwOnError ) {
1947+ boolean supportsDimension = type .supportsDimension (dim );
1948+ if (throwOnError && supportsDimension == false ) {
1949+ throw new IllegalArgumentException (
1950+ type .name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
1951+ );
19291952 }
1930- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
1953+ return supportsDimension ;
19311954 }
19321955 }
19331956
@@ -1971,15 +1994,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19711994 }
19721995
19731996 @ Override
1974- public void validateDimension (int dim ) {
1975- if (type .supportsDimension (dim )) {
1976- return ;
1997+ public boolean validateDimension (int dim , boolean throwOnError ) {
1998+ boolean supportsDimension = type .supportsDimension (dim );
1999+ if (throwOnError && supportsDimension == false ) {
2000+ throw new IllegalArgumentException (
2001+ type .name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
2002+ );
19772003 }
1978- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
2004+ return supportsDimension ;
19792005 }
2006+
19802007 }
19812008
1982- record RescoreVector (float oversample ) implements ToXContentObject {
2009+ public record RescoreVector (float oversample ) implements ToXContentObject {
19832010 static final String NAME = "rescore_vector" ;
19842011 static final String OVERSAMPLE = "oversample" ;
19852012
@@ -2299,7 +2326,7 @@ ElementType getElementType() {
22992326 return elementType ;
23002327 }
23012328
2302- IndexOptions getIndexOptions () {
2329+ public IndexOptions getIndexOptions () {
23032330 return indexOptions ;
23042331 }
23052332 }
0 commit comments