@@ -336,10 +336,26 @@ private void loadIndexAt(int position) throws IOException {
336336 new FileIOVectorReader (vectorStream , meta .dim (), meta .maxDegree ());
337337
338338 // 3. Load PQ files into memory for in-memory approximate distance computation.
339- // Beam search uses PQ-reconstructed vectors; only top-K candidates are
340- // re-ranked with full-precision vectors from disk.
339+ // PQ is mandatory — beam search uses PQ brute-force scan followed by
340+ // full-precision reranking from disk.
341341 byte [] pqPivots = loadCompanionFile (ioMeta , meta .pqPivotsFileName ());
342342 byte [] pqCompressed = loadCompanionFile (ioMeta , meta .pqCompressedFileName ());
343+ if (pqPivots == null || pqPivots .length == 0 ) {
344+ throw new IOException (
345+ "PQ pivots file is missing or empty for index at position "
346+ + position
347+ + ". PQ is required for DiskANN search. "
348+ + "Pivots file: "
349+ + meta .pqPivotsFileName ());
350+ }
351+ if (pqCompressed == null || pqCompressed .length == 0 ) {
352+ throw new IOException (
353+ "PQ compressed file is missing or empty for index at position "
354+ + position
355+ + ". PQ is required for DiskANN search. "
356+ + "Compressed file: "
357+ + meta .pqCompressedFileName ());
358+ }
343359
344360 // 4. Create DiskANN native searcher with on-demand graph + vector access + PQ.
345361 handle =
@@ -402,8 +418,8 @@ public void close() throws IOException {
402418 /**
403419 * Load a companion file (e.g. PQ pivots/compressed) relative to the index file.
404420 *
405- * @return the file contents as byte[], or null if the file name is empty or the file does not
406- * exist .
421+ * @return the file contents as byte[], or null if the file name is null/ empty.
422+ * @throws IOException if the file cannot be read .
407423 */
408424 private byte [] loadCompanionFile (GlobalIndexIOMeta indexIOMeta , String fileName )
409425 throws IOException {
@@ -422,9 +438,6 @@ private byte[] loadCompanionFile(GlobalIndexIOMeta indexIOMeta, String fileName)
422438 }
423439 byte [] data = baos .toByteArray ();
424440 return data .length > 0 ? data : null ;
425- } catch (Exception e ) {
426- // PQ files are optional — if missing, fall back to full-precision search.
427- return null ;
428441 }
429442 }
430443
0 commit comments