@@ -295,6 +295,11 @@ public Builder elementType(ElementType elementType) {
295295 return this ;
296296 }
297297
298+ public Builder indexOptions (IndexOptions indexOptions ) {
299+ this .indexOptions .setValue (indexOptions );
300+ return this ;
301+ }
302+
298303 @ Override
299304 public DenseVectorFieldMapper build (MapperBuilderContext context ) {
300305 // Validate again here because the dimensions or element type could have been set programmatically,
@@ -1226,7 +1231,7 @@ public final String toString() {
12261231 public abstract VectorSimilarityFunction vectorSimilarityFunction (IndexVersion indexVersion , ElementType elementType );
12271232 }
12281233
1229- abstract static class IndexOptions implements ToXContent {
1234+ public abstract static class IndexOptions implements ToXContent {
12301235 final VectorIndexType type ;
12311236
12321237 IndexOptions (VectorIndexType type ) {
@@ -1235,21 +1240,36 @@ abstract static class IndexOptions implements ToXContent {
12351240
12361241 abstract KnnVectorsFormat getVectorsFormat (ElementType elementType );
12371242
1238- final void validateElementType (ElementType elementType ) {
1239- if (type .supportsElementType (elementType ) == false ) {
1243+ public boolean validate (ElementType elementType , int dim , boolean throwOnError ) {
1244+ return validateElementType (elementType , throwOnError ) && validateDimension (dim , throwOnError );
1245+ }
1246+
1247+ public boolean validateElementType (ElementType elementType ) {
1248+ return validateElementType (elementType , true );
1249+ }
1250+
1251+ final boolean validateElementType (ElementType elementType , boolean throwOnError ) {
1252+ boolean validElementType = type .supportsElementType (elementType );
1253+ if (throwOnError && validElementType == false ) {
12401254 throw new IllegalArgumentException (
12411255 "[element_type] cannot be [" + elementType .toString () + "] when using index type [" + type + "]"
12421256 );
12431257 }
1258+ return validElementType ;
12441259 }
12451260
12461261 abstract boolean updatableTo (IndexOptions update );
12471262
1248- public void validateDimension (int dim ) {
1249- if (type .supportsDimension (dim )) {
1250- return ;
1263+ public boolean validateDimension (int dim ) {
1264+ return validateDimension (dim , true );
1265+ }
1266+
1267+ public boolean validateDimension (int dim , boolean throwOnError ) {
1268+ boolean supportsDimension = type .supportsDimension (dim );
1269+ if (throwOnError && supportsDimension == false ) {
1270+ throw new IllegalArgumentException (type .name + " only supports even dimensions; provided=" + dim );
12511271 }
1252- throw new IllegalArgumentException ( type . name + " only supports even dimensions; provided=" + dim ) ;
1272+ return supportsDimension ;
12531273 }
12541274
12551275 abstract boolean doEquals (IndexOptions other );
@@ -1758,12 +1778,12 @@ boolean updatableTo(IndexOptions update) {
17581778
17591779 }
17601780
1761- static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1781+ public static class Int8HnswIndexOptions extends QuantizedIndexOptions {
17621782 private final int m ;
17631783 private final int efConstruction ;
17641784 private final Float confidenceInterval ;
17651785
1766- Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
1786+ public Int8HnswIndexOptions (int m , int efConstruction , Float confidenceInterval , RescoreVector rescoreVector ) {
17671787 super (VectorIndexType .INT8_HNSW , rescoreVector );
17681788 this .m = m ;
17691789 this .efConstruction = efConstruction ;
@@ -1901,11 +1921,11 @@ public String toString() {
19011921 }
19021922 }
19031923
1904- static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1924+ public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
19051925 private final int m ;
19061926 private final int efConstruction ;
19071927
1908- BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
1928+ public BBQHnswIndexOptions (int m , int efConstruction , RescoreVector rescoreVector ) {
19091929 super (VectorIndexType .BBQ_HNSW , rescoreVector );
19101930 this .m = m ;
19111931 this .efConstruction = efConstruction ;
@@ -1947,11 +1967,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19471967 }
19481968
19491969 @ Override
1950- public void validateDimension (int dim ) {
1951- if (type .supportsDimension (dim )) {
1952- return ;
1970+ public boolean validateDimension (int dim , boolean throwOnError ) {
1971+ boolean supportsDimension = type .supportsDimension (dim );
1972+ if (throwOnError && supportsDimension == false ) {
1973+ throw new IllegalArgumentException (
1974+ type .name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
1975+ );
19531976 }
1954- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
1977+ return supportsDimension ;
19551978 }
19561979 }
19571980
@@ -1995,15 +2018,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19952018 }
19962019
19972020 @ Override
1998- public void validateDimension (int dim ) {
1999- if (type .supportsDimension (dim )) {
2000- return ;
2021+ public boolean validateDimension (int dim , boolean throwOnError ) {
2022+ boolean supportsDimension = type .supportsDimension (dim );
2023+ if (throwOnError && supportsDimension == false ) {
2024+ throw new IllegalArgumentException (
2025+ type .name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
2026+ );
20012027 }
2002- throw new IllegalArgumentException ( type . name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim ) ;
2028+ return supportsDimension ;
20032029 }
2030+
20042031 }
20052032
2006- record RescoreVector (float oversample ) implements ToXContentObject {
2033+ public record RescoreVector (float oversample ) implements ToXContentObject {
20072034 static final String NAME = "rescore_vector" ;
20082035 static final String OVERSAMPLE = "oversample" ;
20092036
@@ -2323,7 +2350,7 @@ ElementType getElementType() {
23232350 return elementType ;
23242351 }
23252352
2326- IndexOptions getIndexOptions () {
2353+ public IndexOptions getIndexOptions () {
23272354 return indexOptions ;
23282355 }
23292356 }
0 commit comments