Skip to content

Commit 86bf750

Browse files
Minor code refactoring for explain (opensearch-project#2669)
Signed-off-by: Neetika Singhal <neetiks@amazon.com>
1 parent 5aec855 commit 86bf750

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/main/java/org/opensearch/knn/index/query/KNNWeight.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public Explanation explain(LeafReaderContext context, int doc, float score) {
128128
knnQuery.setExplain(true);
129129
try {
130130
final KNNScorer knnScorer = getOrCreateKnnScorer(context);
131+
// calculate score only when its 0 as for disk-based search,
132+
// score will be passed from the caller and there is no need to re-compute the score
131133
if (score == 0) {
132134
score = getKnnScore(knnScorer, doc);
133135
}

src/test/java/org/opensearch/knn/index/ExplainIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
public class ExplainIT extends KNNRestTestCase {
4444

4545
@SneakyThrows
46-
public void testAnnSearch() {
46+
public void testExplain_whenDefault_thenANNSearch() {
4747
int dimension = 128;
4848
int numDocs = 100;
4949
createDefaultKnnIndex(dimension);
@@ -63,7 +63,7 @@ public void testAnnSearch() {
6363
}
6464

6565
@SneakyThrows
66-
public void testANNWithExactSearch() {
66+
public void testExplain_whenFilterIdLessThanK_thenANNWithExactSearch() {
6767
createDefaultKnnIndex(2);
6868
indexTestData(INDEX_NAME, FIELD_NAME, 2, 2);
6969

@@ -90,7 +90,7 @@ public void testANNWithExactSearch() {
9090
}
9191

9292
@SneakyThrows
93-
public void testRadialWithANNSearch() {
93+
public void testExplain_whenDefaultWithDist_thenRadialWithANNSearch() {
9494
int dimension = 128;
9595
int numDocs = 100;
9696
createDefaultKnnIndex(dimension);
@@ -125,7 +125,7 @@ public void testRadialWithANNSearch() {
125125
}
126126

127127
@SneakyThrows
128-
public void testRadialWithExactSearch() {
128+
public void testExplain_whenFilerQueryWithDist_thenRadialWithExactSearch() {
129129
setupKNNIndexForFilterQuery();
130130

131131
final float[] queryVector = new float[] { 3.3f, 3.0f, 5.0f };
@@ -159,7 +159,7 @@ public void testRadialWithExactSearch() {
159159
}
160160

161161
@SneakyThrows
162-
public void testDiskBasedSearchWithDefaultRescoring() {
162+
public void testExplain_whenDefaultDiskBasedSearch_thenRescoringEnabled() {
163163
int dimension = 16;
164164
float[] queryVector = new float[] {
165165
1.0f,
@@ -217,7 +217,7 @@ public void testDiskBasedSearchWithDefaultRescoring() {
217217
}
218218

219219
@SneakyThrows
220-
public void testDiskBasedSearchWithRescoringDisabled() {
220+
public void testExplain_whenDiskBasedSearchRescoringDisabled_thenSucceed() {
221221
int dimension = 16;
222222
float[] queryVector = new float[] {
223223
1.0f,

0 commit comments

Comments
 (0)