Skip to content

Commit e856c5a

Browse files
committed
fix diskann search flow
1 parent d95a494 commit e856c5a

4 files changed

Lines changed: 401 additions & 217 deletions

File tree

paimon-diskann/paimon-diskann-index/src/main/java/org/apache/paimon/diskann/index/DiskAnnVectorGlobalIndexReader.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

paimon-diskann/paimon-diskann-index/src/main/java/org/apache/paimon/diskann/index/FileIOGraphReader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ public int[] readNeighbors(int internalNodeId) {
203203

204204
// 3. Seek & read neighbor_cnt + neighbor_ids.
205205
try {
206+
System.out.println(
207+
"Reading neighbors for node " + internalNodeId + " at offset " + offset);
206208
input.seek(offset);
207209

208210
// Read neighbor count (4 bytes).

0 commit comments

Comments
 (0)