@@ -372,31 +372,34 @@ public void writeTypeAndParametersTo(ObjectNode objectNode) throws IOException {
372
372
}
373
373
374
374
if (knnSimilarity != KnnSimilarity .DEFAULT ) {
375
- Assert .isTrue (index , "knn similarity can only be specified when \" index\" is true." );
375
+ Assert .isTrue (index , "knn similarity can only be specified when ' index' is true." );
376
376
objectNode .put (FIELD_PARAM_SIMILARITY , knnSimilarity .getSimilarity ());
377
377
}
378
378
379
379
if (knnIndexOptions != null ) {
380
- Assert .isTrue (index , "knn similarity can only be specified when \" index\" is true." );
380
+ Assert .isTrue (index , "knn index options can only be specified when ' index' is true." );
381
381
ObjectNode indexOptionsNode = objectNode .putObject (FIELD_PARAM_INDEX_OPTIONS );
382
- if (knnIndexOptions .type () != KnnAlgorithmType .DEFAULT ) {
383
- indexOptionsNode .put (FIELD_PARAM_TYPE , knnIndexOptions .type ().getType ());
382
+ KnnAlgorithmType algoType = knnIndexOptions .type ();
383
+ if (algoType != KnnAlgorithmType .DEFAULT ) {
384
+ if (algoType == KnnAlgorithmType .INT8_HNSW || algoType == KnnAlgorithmType .INT8_FLAT ) {
385
+ Assert .isTrue (!FieldElementType .BYTE .equals (elementType ),
386
+ "'element_type' can only be float when using vector quantization." );
387
+ }
388
+ indexOptionsNode .put (FIELD_PARAM_TYPE , algoType .getType ());
384
389
}
385
390
if (knnIndexOptions .m () >= 0 ) {
386
- Assert .isTrue (knnIndexOptions .type () == KnnAlgorithmType .HNSW
387
- || knnIndexOptions .type () == KnnAlgorithmType .INT8_HNSW ,
391
+ Assert .isTrue (algoType == KnnAlgorithmType .HNSW || algoType == KnnAlgorithmType .INT8_HNSW ,
388
392
"knn 'm' parameter can only be applicable to hnsw and int8_hnsw index types." );
389
393
indexOptionsNode .put (FIELD_PARAM_M , knnIndexOptions .m ());
390
394
}
391
395
if (knnIndexOptions .efConstruction () >= 0 ) {
392
- Assert .isTrue (knnIndexOptions .type () == KnnAlgorithmType .HNSW
393
- || knnIndexOptions .type () == KnnAlgorithmType .INT8_HNSW ,
396
+ Assert .isTrue (algoType == KnnAlgorithmType .HNSW || algoType == KnnAlgorithmType .INT8_HNSW ,
394
397
"knn 'ef_construction' can only be applicable to hnsw and int8_hnsw index types." );
395
398
indexOptionsNode .put (FIELD_PARAM_EF_CONSTRUCTION , knnIndexOptions .efConstruction ());
396
399
}
397
400
if (knnIndexOptions .confidenceInterval () >= 0 ) {
398
- Assert .isTrue (knnIndexOptions . type () == KnnAlgorithmType .INT8_HNSW
399
- || knnIndexOptions . type () == KnnAlgorithmType .INT8_FLAT ,
401
+ Assert .isTrue (algoType == KnnAlgorithmType .INT8_HNSW
402
+ || algoType == KnnAlgorithmType .INT8_FLAT ,
400
403
"knn 'confidence_interval' can only be applicable to int8_hnsw and int8_flat index types." );
401
404
indexOptionsNode .put (FIELD_PARAM_CONFIDENCE_INTERVAL , knnIndexOptions .confidenceInterval ());
402
405
}
0 commit comments