diff --git a/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseQueryBuilder.java b/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseQueryBuilder.java index 2373ad060..1274107b7 100644 --- a/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseQueryBuilder.java +++ b/src/main/java/org/opensearch/neuralsearch/query/NeuralSparseQueryBuilder.java @@ -61,8 +61,10 @@ public class NeuralSparseQueryBuilder extends AbstractQueryBuilder firstInnerHit = getFirstInnerHit(searchResponseAsMap); assertEquals("1", firstInnerHit.get("_id")); - Map queryTokens = runSparseModelInference(modelId, TEST_QUERY_TEXT); - float expectedScore = 0f; - for (Map.Entry entry : queryTokens.entrySet()) { - if (testRankFeaturesDoc.containsKey(entry.getKey())) { - expectedScore += entry.getValue() * Math.min( - getFeatureFieldCompressedNumber(testRankFeaturesDoc.get(entry.getKey())), - maxTokenScore - ); - } - } + float expectedScore = computeExpectedScore(modelId, testRankFeaturesDoc, TEST_QUERY_TEXT); assertEquals(expectedScore, objectToFloat(firstInnerHit.get("_score")), DELTA); }