From 98fa41468607261a1e96efbed40e077bbc32f6e2 Mon Sep 17 00:00:00 2001 From: Martin Gaievski Date: Wed, 9 Oct 2024 16:48:25 -0700 Subject: [PATCH] Fixed unit test for neural query after recent knn change in rescore context Signed-off-by: Martin Gaievski --- .../neuralsearch/query/NeuralQueryBuilderTests.java | 7 ++++++- .../java/org/opensearch/neuralsearch/util/TestUtils.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java b/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java index e0c51e106..6d8e810f3 100644 --- a/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java +++ b/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java @@ -16,6 +16,7 @@ import static org.opensearch.knn.index.query.KNNQueryBuilder.MIN_SCORE_FIELD; import static org.opensearch.knn.index.query.KNNQueryBuilder.RESCORE_FIELD; import static org.opensearch.knn.index.query.KNNQueryBuilder.RESCORE_OVERSAMPLE_FIELD; +import static org.opensearch.neuralsearch.util.TestUtils.DELTA_FOR_FLOATS_ASSERTION; import static org.opensearch.neuralsearch.util.TestUtils.xContentBuilderToMap; import static org.opensearch.neuralsearch.query.NeuralQueryBuilder.K_FIELD; import static org.opensearch.neuralsearch.query.NeuralQueryBuilder.MODEL_ID_FIELD; @@ -183,7 +184,11 @@ public void testFromXContent_withRescoreContext_thenBuildSuccessfully() { assertEquals(QUERY_TEXT, neuralQueryBuilder.queryText()); assertEquals(MODEL_ID, neuralQueryBuilder.modelId()); assertEquals(K, neuralQueryBuilder.k()); - assertEquals(RescoreContext.getDefault(), neuralQueryBuilder.rescoreContext()); + assertEquals( + RescoreContext.getDefault().getOversampleFactor(), + neuralQueryBuilder.rescoreContext().getOversampleFactor(), + DELTA_FOR_FLOATS_ASSERTION + ); assertNull(neuralQueryBuilder.methodParameters()); } diff --git a/src/testFixtures/java/org/opensearch/neuralsearch/util/TestUtils.java b/src/testFixtures/java/org/opensearch/neuralsearch/util/TestUtils.java index bc016aae2..ab041c440 100644 --- a/src/testFixtures/java/org/opensearch/neuralsearch/util/TestUtils.java +++ b/src/testFixtures/java/org/opensearch/neuralsearch/util/TestUtils.java @@ -39,6 +39,7 @@ public class TestUtils { public static final String RELATION_EQUAL_TO = "eq"; public static final float DELTA_FOR_SCORE_ASSERTION = 0.001f; + public static final float DELTA_FOR_FLOATS_ASSERTION = 0.001f; public static final String RESTART_UPGRADE_OLD_CLUSTER = "tests.is_old_cluster"; public static final String BWC_VERSION = "tests.plugin_bwc_version"; public static final String NEURAL_SEARCH_BWC_PREFIX = "neuralsearch-bwc-";