diff --git a/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java b/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java index 0b59b9e8a3..dc85a1724e 100644 --- a/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java +++ b/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java @@ -534,10 +534,9 @@ protected Query doToQuery(QueryShardContext context) { final String method = methodComponentContext != null ? methodComponentContext.getName() : null; if (StringUtils.isNotBlank(method)) { final EngineSpecificMethodContext engineSpecificMethodContext = knnEngine.getMethodContext(method); - KNNEngine finalKnnEngine = knnEngine; - QueryContext methodContext = () -> (vectorQueryType.isRadialSearch() && KNNEngine.LUCENE.equals(finalKnnEngine)) == false; + QueryContext queryContext = new QueryContext(vectorQueryType); ValidationException validationException = validateParameters( - engineSpecificMethodContext.supportedMethodParameters(methodContext), + engineSpecificMethodContext.supportedMethodParameters(queryContext), (Map) methodParameters ); if (validationException != null) { diff --git a/src/main/java/org/opensearch/knn/index/util/LuceneHNSWContext.java b/src/main/java/org/opensearch/knn/index/util/LuceneHNSWContext.java index 468ee62392..d9b6ba1c39 100644 --- a/src/main/java/org/opensearch/knn/index/util/LuceneHNSWContext.java +++ b/src/main/java/org/opensearch/knn/index/util/LuceneHNSWContext.java @@ -26,11 +26,11 @@ public class LuceneHNSWContext implements EngineSpecificMethodContext { @Override public Map> supportedMethodParameters(QueryContext ctx) { - if (ctx.is_ef_search_parameter_supported()) { - // Return the supported method parameters for non-radial cases - return supportedMethodParameters; + if (ctx.queryType.isRadialSearch()) { + // return empty map if radial search is true + return Collections.emptyMap(); } - // return empty map if radial search is true - return Collections.emptyMap(); + // Return the supported method parameters for non-radial cases + return supportedMethodParameters; } } diff --git a/src/main/java/org/opensearch/knn/index/util/QueryContext.java b/src/main/java/org/opensearch/knn/index/util/QueryContext.java index 932e9ab36e..6bb4958146 100644 --- a/src/main/java/org/opensearch/knn/index/util/QueryContext.java +++ b/src/main/java/org/opensearch/knn/index/util/QueryContext.java @@ -11,9 +11,13 @@ package org.opensearch.knn.index.util; +import lombok.AllArgsConstructor; +import org.opensearch.knn.index.VectorQueryType; + /** - * Context interface for query-specific information. + * Context class for query-specific information. */ -public interface QueryContext { - boolean is_ef_search_parameter_supported(); +@AllArgsConstructor +public class QueryContext { + VectorQueryType queryType; } diff --git a/src/test/java/org/opensearch/knn/index/util/AbstractKNNLibraryTests.java b/src/test/java/org/opensearch/knn/index/util/AbstractKNNLibraryTests.java index c40171305c..8e5ae24f9e 100644 --- a/src/test/java/org/opensearch/knn/index/util/AbstractKNNLibraryTests.java +++ b/src/test/java/org/opensearch/knn/index/util/AbstractKNNLibraryTests.java @@ -75,7 +75,7 @@ public ValidationException validate(KNNMethodContext knnMethodContext) { public void testEngineSpecificMethods() { String methodName1 = "test-method-1"; - QueryContext engineSpecificMethodContext = () -> false; + QueryContext engineSpecificMethodContext = new QueryContext(VectorQueryType.K); EngineSpecificMethodContext context = ctx -> ImmutableMap.of( "myparameter", new Parameter.BooleanParameter("myparameter", null, value -> true)