From cdfa4caec9833e55cd08a108e440c5f13a7d2dcf Mon Sep 17 00:00:00 2001 From: conggguan Date: Thu, 25 Apr 2024 18:06:16 +0800 Subject: [PATCH] Change the version check to current to pass bwc test. Signed-off-by: conggguan --- .../neuralsearch/query/NeuralSparseTwoPhaseParameters.java | 6 +++--- .../neuralsearch/search/util/NeuralSparseTwoPhaseUtil.java | 6 +++--- .../neuralsearch/util/NeuralSearchClusterUtil.java | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseTwoPhaseParameters.java b/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseTwoPhaseParameters.java index c645b0efd..ede0c9538 100644 --- a/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseTwoPhaseParameters.java +++ b/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseTwoPhaseParameters.java @@ -51,8 +51,7 @@ public class NeuralSparseTwoPhaseParameters implements Writeable { static final ParseField PRUNING_RATIO = new ParseField("pruning_ratio"); @VisibleForTesting static final ParseField ENABLED = new ParseField("enabled"); - private static final Version MINIMAL_SUPPORTED_VERSION_TWO_PHASE_SEARCH = Version.V_2_14_0; - + private static final Version MINIMAL_SUPPORTED_VERSION_TWO_PHASE_SEARCH = Version.CURRENT; private Float window_size_expansion; private Float pruning_ratio; private Boolean enabled; @@ -82,6 +81,7 @@ public static void initialize(final ClusterService clusterService, final Setting ); clusterService.getClusterSettings() .addSettingsUpdateConsumer(NeuralSearchSettings.NEURAL_SPARSE_TWO_PHASE_MAX_WINDOW_SIZE, it -> MAX_WINDOW_SIZE = it); + } public static NeuralSparseTwoPhaseParameters getDefaultSettings() { @@ -202,6 +202,6 @@ public static boolean isEnabled(final NeuralSparseTwoPhaseParameters neuralSpars * @return True if cluster are on support, false if it doesn't. */ public static boolean isClusterOnOrAfterMinReqVersionForTwoPhaseSearchSupport() { - return NeuralSearchClusterUtil.instance().getClusterMinVersion().onOrAfter(MINIMAL_SUPPORTED_VERSION_TWO_PHASE_SEARCH); + return NeuralSearchClusterUtil.instance().getClusterMaxVersion() != NeuralSearchClusterUtil.instance().getClusterMinVersion(); } } diff --git a/src/main/java/org/opensearch/neuralsearch/search/util/NeuralSparseTwoPhaseUtil.java b/src/main/java/org/opensearch/neuralsearch/search/util/NeuralSparseTwoPhaseUtil.java index af970a0fc..3490e15b2 100644 --- a/src/main/java/org/opensearch/neuralsearch/search/util/NeuralSparseTwoPhaseUtil.java +++ b/src/main/java/org/opensearch/neuralsearch/search/util/NeuralSparseTwoPhaseUtil.java @@ -36,14 +36,14 @@ public class NeuralSparseTwoPhaseUtil { */ public static void addRescoreContextFromNeuralSparseQuery(final Query query, final SearchContext searchContext) { Map neuralSparseQuery2Weight = new HashMap<>(); - // Store all neuralSparse query and it's global weight in neuralSparseQuery2Weight, and get the max windowSizeExpansion of them.. + // Store all neuralSparse query with global weight in neuralSparseQuery2Weight, and get the max windowSizeExpansion of them. float windowSizeExpansion = populateQueryWeightsMapAndGetWindowSizeExpansion(query, neuralSparseQuery2Weight, 1.0f, 1.0f); Query twoPhaseQuery = getNestedTwoPhaseQueryFromNeuralSparseQuerySet(neuralSparseQuery2Weight); if (twoPhaseQuery == null) return; // Set the valid neural_sparse query's current query to it's highScoreTokenQuery. neuralSparseQuery2Weight.keySet().forEach(NeuralSparseQuery::setCurrentQueryToHighScoreTokenQuery); // Add two phase to searchContext's rescore list. - addTwoPhaseQuery2RescoreContext(searchContext, windowSizeExpansion, twoPhaseQuery); + addTwoPhaseQueryRescoreContext(searchContext, windowSizeExpansion, twoPhaseQuery); } private static float populateQueryWeightsMapAndGetWindowSizeExpansion( @@ -83,7 +83,7 @@ private static float getOriginQueryWeightAfterRescore(final List .reduce(1.0f, (a, b) -> a * b); } - private static void addTwoPhaseQuery2RescoreContext( + private static void addTwoPhaseQueryRescoreContext( final SearchContext searchContext, final float windowSizeExpansion, Query twoPhaseQuery diff --git a/src/main/java/org/opensearch/neuralsearch/util/NeuralSearchClusterUtil.java b/src/main/java/org/opensearch/neuralsearch/util/NeuralSearchClusterUtil.java index d7d77b823..aa7f5f527 100644 --- a/src/main/java/org/opensearch/neuralsearch/util/NeuralSearchClusterUtil.java +++ b/src/main/java/org/opensearch/neuralsearch/util/NeuralSearchClusterUtil.java @@ -48,4 +48,11 @@ public Version getClusterMinVersion() { return this.clusterService.state().getNodes().getMinNodeVersion(); } + /** + * Return maximal OpenSearch version based on all nodes currently discoverable in the cluster + * @return the version of the node with the youngest version in the cluster + */ + public Version getClusterMaxVersion() { + return this.clusterService.state().getNodes().getMaxNodeVersion(); + } }