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

View File

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