@@ -46,7 +46,6 @@ public class TestRerankKnnFloatVectorQuery extends LuceneTestCase {
4646 VectorSimilarityFunction .COSINE ;
4747 private Directory directory ;
4848 private IndexWriterConfig config ;
49- private static final int NUM_VECTORS = 1000 ;
5049 private static final int VECTOR_DIMENSION = 128 ;
5150
5251 @ Before
@@ -66,15 +65,22 @@ public void testTwoPhaseKnnVectorQuery() throws Exception {
6665
6766 Random random = random ();
6867
68+ int numVectors = atLeast (1000 );
69+
6970 // Step 1: Index random vectors in quantized format
7071 try (IndexWriter writer = new IndexWriter (directory , config )) {
71- for (int i = 0 ; i < NUM_VECTORS ; i ++) {
72+ for (int i = 0 ; i < numVectors ; i ++) {
7273 float [] vector = randomFloatVector (VECTOR_DIMENSION , random );
7374 Document doc = new Document ();
7475 doc .add (new IntField ("id" , i , Field .Store .YES ));
7576 doc .add (new KnnFloatVectorField (FIELD , vector , VECTOR_SIMILARITY_FUNCTION ));
7677 writer .addDocument (doc );
7778 vectors .put (i , vector );
79+
80+ // flush to create multiple segments
81+ if (random .nextInt (10 ) == 0 ) {
82+ writer .flush ();
83+ }
7884 }
7985 }
8086
@@ -93,10 +99,11 @@ public void testTwoPhaseKnnVectorQuery() throws Exception {
9399 // Step 3: Verify that TopDocs scores match similarity with unquantized vectors
94100 for (ScoreDoc scoreDoc : topDocs .scoreDocs ) {
95101 Document retrievedDoc = searcher .storedFields ().document (scoreDoc .doc );
96- float [] docVector = vectors .get (retrievedDoc .getField ("id" ).numericValue ().intValue ());
102+ int id = retrievedDoc .getField ("id" ).numericValue ().intValue ();
103+ float [] docVector = vectors .get (id );
97104 float expectedScore = VECTOR_SIMILARITY_FUNCTION .compare (targetVector , docVector );
98105 Assert .assertEquals (
99- "Score does not match expected similarity for docId : " + scoreDoc .doc ,
106+ "Score does not match expected similarity for doc ord : " + scoreDoc .doc + ", id: " + id ,
100107 expectedScore ,
101108 scoreDoc .score ,
102109 1e-5 );
0 commit comments