Fix KnnQueryTestCase

Both testEuclidean and testExplain have vectors that result
in equal scores. Since we no longer tie break on vector ordinal
as it doesn't make sense when building the graph, the vectors returned
might be slightly different. This commit fixes the flaky nature of the
test.
This commit is contained in:
Benjamin Trent 2023-11-07 07:55:28 -05:00
parent e1ce1d692c
commit 34d858fbbb
1 changed files with 14 additions and 7 deletions

View File

@ -281,12 +281,19 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase {
DocIdSetIterator it = scorer.iterator();
assertEquals(3, it.cost());
assertEquals(2, it.nextDoc());
assertEquals(1 / 2f, scorer.score(), 0);
assertEquals(4, it.advance(4));
assertEquals(1 / 6f, scorer.score(), 0);
assertEquals(NO_MORE_DOCS, it.advance(5));
int firstDoc = it.nextDoc();
if (firstDoc == 1) {
assertEquals(1 / 6f, scorer.score(), 0);
assertEquals(3, it.advance(3));
assertEquals(1 / 2f, scorer.score(), 0);
assertEquals(NO_MORE_DOCS, it.advance(4));
} else {
assertEquals(2, firstDoc);
assertEquals(1 / 2f, scorer.score(), 0);
assertEquals(4, it.advance(4));
assertEquals(1 / 6f, scorer.score(), 0);
assertEquals(NO_MORE_DOCS, it.advance(5));
}
expectThrows(ArrayIndexOutOfBoundsException.class, scorer::score);
}
}
@ -384,7 +391,7 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase {
assertEquals(0, matched.getDetails().length);
assertEquals("within top 3 docs", matched.getDescription());
Explanation nomatch = searcher.explain(query, 1);
Explanation nomatch = searcher.explain(query, 5);
assertFalse(nomatch.isMatch());
assertEquals(0f, nomatch.getValue());
assertEquals(0, matched.getDetails().length);