@@ -849,7 +849,10 @@ private void testSearch(Path indexPath, Path queryPath, int queryStartIndex, Pat
849849 dir .setPreload ((x , ctx ) -> x .endsWith (".vec" ) || x .endsWith (".veq" ));
850850 try (DirectoryReader reader = DirectoryReader .open (dir )) {
851851 IndexSearcher searcher = new IndexSearcher (reader );
852- numDocs = reader .maxDoc ();
852+ int indexNumDocs = reader .maxDoc ();
853+ if (numDocs != indexNumDocs ) {
854+ throw new IllegalStateException ("index size mismatch, expected " + numDocs + " but index has " + indexNumDocs );
855+ }
853856 // warm up
854857 for (int i = 0 ; i < numQueryVectors ; i ++) {
855858 if (vectorEncoding .equals (VectorEncoding .BYTE )) {
@@ -989,8 +992,8 @@ private float checkResults(int[][] results, int[][] nn) {
989992 int totalMatches = 0 ;
990993 int totalResults = results .length * topK ;
991994 for (int i = 0 ; i < results .length ; i ++) {
992- // System.out.println(Arrays.toString(nn[i]));
993- // System.out.println(Arrays.toString(results[i].scoreDocs ));
995+ // System.out.println("compare " + Arrays.toString(nn[i]) + " to " );
996+ // System.out.println(Arrays.toString(results[i]));
994997 totalMatches += compareNN (nn [i ], results [i ]);
995998 }
996999 return totalMatches / (float ) totalResults ;
@@ -1088,6 +1091,9 @@ private int[][] computeExactNNByte(Path docPath, Path queryPath, int queryStartI
10881091 List <ComputeNNByteTask > tasks = new ArrayList <>();
10891092 try (Directory dir = FSDirectory .open (indexPath );
10901093 DirectoryReader reader = DirectoryReader .open (dir )) {
1094+ if (reader .maxDoc () != numDocs ) {
1095+ throw new IllegalStateException ("index size mismatch, expected " + numDocs + " but index has " + reader .maxDoc ());
1096+ }
10911097 try (FileChannel qIn = getVectorFileChannel (queryPath , dim , vectorEncoding , !quiet )) {
10921098 VectorReaderByte queryReader = (VectorReaderByte ) VectorReader .create (qIn , dim , VectorEncoding .BYTE , queryStartIndex );
10931099 for (int i = 0 ; i < numQueryVectors ; i ++) {
@@ -1145,6 +1151,9 @@ private int[][] computeExactNN(Path queryPath, int queryStartIndex)
11451151 try (Directory dir = FSDirectory .open (indexPath );
11461152 DirectoryReader reader = DirectoryReader .open (dir )) {
11471153 log ("now compute brute-force KNN hits for " + numQueryVectors + " query vectors from \" " + queryPath + "\" starting at query index " + queryStartIndex + "\n " );
1154+ if (reader .maxDoc () != numDocs ) {
1155+ throw new IllegalStateException ("index size mismatch, expected " + numDocs + " but index has " + reader .maxDoc ());
1156+ }
11481157 if (parentJoin ) {
11491158 CheckJoinIndex .check (reader , ParentJoinBenchmarkQuery .parentsFilter );
11501159 }
0 commit comments