From 79baf82e063b00b67850913ebcf515e61ebeb85b Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Mon, 2 Dec 2024 12:31:56 -0800 Subject: [PATCH] Validate method parameters only after version 2_17_0 k-NN introduced validation to prevent index creation api to accept method paramters that are used by approximate k-NN search algorithm. For ex: create index api accepts model_id, or, method params even if knn index setting was not true before 2.17. However, for index that were created before 2.17 and upgraded to 2.17, will prevent cluster to parse those previously accepted index mapping. Hence, k-NN will allow those paramters for indices that were created before 2.17, but doesn't support those parameters starting 2.17. Signed-off-by: Vijayan Balasubramanian --- .../knn/index/mapper/KNNVectorFieldMapper.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java b/src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java index 6e5138a56..b541be823 100644 --- a/src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java +++ b/src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java @@ -182,6 +182,8 @@ public static class Builder extends ParametrizedFieldMapper.Builder { @Setter @Getter private OriginalMappingParameters originalParameters; + @Setter + private boolean isKnnIndex; public Builder( String name, @@ -195,6 +197,7 @@ public Builder( this.indexCreatedVersion = indexCreatedVersion; this.knnMethodConfigContext = knnMethodConfigContext; this.originalParameters = originalParameters; + this.isKnnIndex = true; } @Override @@ -250,7 +253,7 @@ public KNNVectorFieldMapper build(BuilderContext context) { ); } - if (originalParameters.getResolvedKnnMethodContext() == null) { + if (originalParameters.getResolvedKnnMethodContext() == null || isKnnIndex == false) { return FlatVectorFieldMapper.createFieldMapper( buildFullName(context), name, @@ -362,10 +365,14 @@ public Mapper.Builder parse(String name, Map node, ParserCont String.format(Locale.ROOT, "Method and model can not be both specified in the mapping: %s", name) ); } - // Check for flat configuration if (isKNNDisabled(parserContext.getSettings())) { - validateFromFlat(builder); + builder.setKnnIndex(false); + if(parserContext.indexVersionCreated().onOrAfter(Version.V_2_17_0)) { + // on and after 2_17_0 we validate to makes sure that mapping doesn't contain parameters that are + // specific to approximate knn search algorithms + validateFromFlat(builder); + } } else if (builder.modelId.get() != null) { validateFromModel(builder); } else {