@@ -456,6 +456,14 @@ public void testFallbackToExact() throws IOException {
456456
457457 // Falls back to exact search
458458 expectThrows (UnsupportedOperationException .class , () -> searcher .count (query ));
459+
460+ // When traversalSimilarity is -∞ without a filter, exact search should be used directly
461+ Query exactQuery =
462+ getThrowingVectorQuery (
463+ vectorField , queryVector , Float .NEGATIVE_INFINITY , Float .NEGATIVE_INFINITY , null );
464+
465+ // Falls back to exact search because traversalSimilarity is -∞
466+ expectThrows (UnsupportedOperationException .class , () -> searcher .count (exactQuery ));
459467 }
460468 }
461469
@@ -510,15 +518,13 @@ public void testTimeout() throws IOException {
510518 // This query is cacheable, explicitly prevent it
511519 searcher .setQueryCache (null );
512520
521+ // Use Math.nextUp(Float.NEGATIVE_INFINITY) to ensure approximate graph search is used,
522+ // since Float.NEGATIVE_INFINITY now triggers exact search which bypasses graph traversal
523+ float nearNegInf = Math .nextUp (Float .NEGATIVE_INFINITY );
524+
513525 Query query =
514- new CountingQuery (
515- getVectorQuery (
516- vectorField ,
517- queryVector ,
518- Float .NEGATIVE_INFINITY ,
519- Float .NEGATIVE_INFINITY ,
520- null ));
521- assertEquals (numDocs , searcher .count (query )); // Expect some results without timeout
526+ new CountingQuery (getVectorQuery (vectorField , queryVector , nearNegInf , nearNegInf , null ));
527+ assertEquals (numDocs , searcher .count (query )); // Expect all results without timeout
522528
523529 searcher .setTimeout (() -> true ); // Immediately timeout
524530 assertEquals (0 , searcher .count (query )); // Expect no results with the timeout
@@ -534,12 +540,7 @@ public void testTimeout() throws IOException {
534540 Query filter = IntField .newSetQuery (idField , getFiltered (numFiltered ));
535541 Query filteredQuery =
536542 new CountingQuery (
537- getVectorQuery (
538- vectorField ,
539- queryVector ,
540- Float .NEGATIVE_INFINITY ,
541- Float .NEGATIVE_INFINITY ,
542- filter ));
543+ getVectorQuery (vectorField , queryVector , nearNegInf , nearNegInf , filter ));
543544
544545 searcher .setTimeout (() -> false ); // Set a timeout which is never met
545546 assertEquals (numFiltered , searcher .count (filteredQuery ));
0 commit comments