-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added validations for score combination weights in Hybrid Search (#265)…
… (#268) * Added strong check on number of weights equals number of sub-queries Signed-off-by: Martin Gaievski <[email protected]> (cherry picked from commit 685d5d6) Co-authored-by: Martin Gaievski <[email protected]>
- 2.11
- (#268)
- 2.12
- (#268)
- 2.13
- (#268)
- 2.14
- (#268)
- 2.15
- (#268)
- 2.16
- (#268)
- 2.17
- (#268)
- 2.18
- (#268)
- 2.x
- (#268)
- backport/backport-1009-to-2.x
- (#268)
- backport/backport-1014-to-2.x
- (#268)
- backport/backport-1026-to-2.x
- (#268)
- backport/backport-1034-to-2.x
- (#268)
- backport/backport-496-to-2.11
- (#268)
- backport/backport-565-to-2.x
- (#268)
- backport/backport-579-to-2.x
- (#268)
- backport/backport-769-to-2.x
- (#268)
- backport/backport-777-to-2.x
- (#268)
- backport/backport-781-to-2.x
- (#268)
- backport/backport-795-to-2.x
- (#268)
- backport/backport-800-to-2.15
- (#268)
- backport/backport-800-to-2.x
- (#268)
- backport/backport-811-to-2.x
- (#268)
- backport/backport-814-to-2.x
- (#268)
- backport/backport-820-to-2.x
- (#268)
- backport/backport-821-to-2.x
- (#268)
- backport/backport-823-to-2.x
- (#268)
- backport/backport-827-to-2.x
- (#268)
- backport/backport-834-to-2.x
- (#268)
- backport/backport-841-to-2.16
- (#268)
- backport/backport-841-to-2.x
- (#268)
- backport/backport-851-to-2.x
- (#268)
- backport/backport-852-to-2.x
- (#873, #268)
- backport/backport-855-to-2.x
- (#268)
- backport/backport-861-to-2.x
- (#268)
- backport/backport-867-to-2.17
- (#268)
- backport/backport-867-to-2.x
- (#268)
- backport/backport-877-to-2.17
- (#268)
- backport/backport-877-to-2.x
- (#268)
- backport/backport-882-to-2.17
- (#268)
- backport/backport-882-to-2.x
- (#268)
- backport/backport-885-to-2.17
- (#268)
- backport/backport-892-to-2.x
- (#268)
- backport/backport-898-to-2.x
- (#268)
- backport/backport-900-to-2.x
- (#268)
- backport/backport-907-to-2.x
- (#268)
- backport/backport-913-to-2.x
- (#268)
- backport/backport-917-to-2.x
- (#268)
- backport/backport-924-to-2.17
- (#268)
- backport/backport-927-to-2.x
- (#268)
- backport/backport-928-to-2.x
- (#268)
- backport/backport-932-to-2.18
- (#268)
- backport/backport-932-to-2.x
- (#268)
- backport/backport-953-to-2.x
- (#268)
- backport/backport-956-to-2.18
- (#268)
- backport/backport-956-to-2.x
- (#268)
- backport/backport-960-to-2.18
- (#268)
- backport/backport-966-to-2.x
- (#268)
- backport/backport-975-to-2.x
- (#268)
- backport/backport-977-to-2.x
- (#268)
- backport/backport-980-to-2.x
- (#268)
- backport/backport-984-to-2.x
- (#268)
- backport/backport-988-to-2.x
- (#268)
- backport/backport-998-to-2.x
- (#268)
- create-pull-request/2.11.2-SNAPSHOT
- (#268)
- create-pull-request/2.12.1-SNAPSHOT
- (#268)
- create-pull-request/2.13.1-SNAPSHOT
- (#268)
- create-pull-request/2.14.1-SNAPSHOT
- (#268)
- create-pull-request/2.15.1-SNAPSHOT
- (#807, #268)
- create-pull-request/2.16.1-SNAPSHOT
- (#864, #268)
- create-pull-request/2.17.2-SNAPSHOT
- (#923, #268)
- create-pull-request/2.18.1-SNAPSHOT
- (#982, #268)
1 parent
e564d4d
commit 40479e9
Showing
12 changed files
with
231 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...est/java/org/opensearch/neuralsearch/processor/combination/ScoreCombinationUtilTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.processor.combination; | ||
|
||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.opensearch.neuralsearch.query.OpenSearchQueryTestCase; | ||
|
||
public class ScoreCombinationUtilTests extends OpenSearchQueryTestCase { | ||
|
||
public void testCombinationWeights_whenEmptyInputPassed_thenCreateEmptyWeightCollection() { | ||
ScoreCombinationUtil scoreCombinationUtil = new ScoreCombinationUtil(); | ||
List<Float> weights = scoreCombinationUtil.getWeights(Map.of()); | ||
assertNotNull(weights); | ||
assertTrue(weights.isEmpty()); | ||
} | ||
|
||
public void testCombinationWeights_whenWeightsArePassed_thenSuccessful() { | ||
ScoreCombinationUtil scoreCombinationUtil = new ScoreCombinationUtil(); | ||
List<Float> weights = scoreCombinationUtil.getWeights(Map.of("weights", List.of(0.4, 0.6))); | ||
assertNotNull(weights); | ||
assertEquals(2, weights.size()); | ||
assertTrue(weights.containsAll(List.of(0.4f, 0.6f))); | ||
} | ||
|
||
public void testCombinationWeights_whenInvalidWeightsArePassed_thenFail() { | ||
ScoreCombinationUtil scoreCombinationUtil = new ScoreCombinationUtil(); | ||
|
||
IllegalArgumentException exception1 = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> scoreCombinationUtil.getWeights(Map.of("weights", List.of(2.4))) | ||
); | ||
assertTrue(exception1.getMessage().contains("all weights must be in range")); | ||
|
||
IllegalArgumentException exception2 = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> scoreCombinationUtil.getWeights(Map.of("weights", List.of(0.4, 0.5, 0.6))) | ||
); | ||
assertTrue(exception2.getMessage().contains("sum of weights for combination must be equal to 1.0")); | ||
} | ||
|
||
public void testWeightsValidation_whenNumberOfScoresDifferentFromNumberOfWeights_thenFail() { | ||
ScoreCombinationUtil scoreCombinationUtil = new ScoreCombinationUtil(); | ||
IllegalArgumentException exception1 = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> scoreCombinationUtil.validateIfWeightsMatchScores(new float[] { 0.6f, 0.5f }, List.of(0.4f, 0.2f, 0.4f)) | ||
); | ||
org.hamcrest.MatcherAssert.assertThat( | ||
exception1.getMessage(), | ||
allOf( | ||
containsString("number of weights"), | ||
containsString("must match number of sub-queries"), | ||
containsString("in hybrid query") | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters