Skip to content

Commit 18488b8

Browse files
authored
Fix for bug causing tests to use FP vectors in search (#645)
* fix for bug causing tests to use FP vectors in search * adding safeguards and logging
1 parent b219a2d commit 18488b8

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

  • jvector-examples/src/main/java/io/github/jbellis/jvector/example

jvector-examples/src/main/java/io/github/jbellis/jvector/example/Grid.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ static void runOneGraph(OnDiskGraphIndexCache cache,
307307
CompressedVectors cv;
308308
if (featureSetForIndex.contains(FeatureId.FUSED_PQ)) {
309309
cv = null;
310+
System.out.format("%s: configured to use FUSED PQ, skipping vector compression%n", ds.getName());
310311
} else {
311312
constructionMetrics.resetSearch(); // per (index, cpSupplier) config
312313

@@ -316,11 +317,17 @@ static void runOneGraph(OnDiskGraphIndexCache cache,
316317

317318
if (compressor == null) {
318319
cv = null;
320+
System.out.format("%s: No search compressor configured, FULL PRECISION vectors will be used for search%n", ds.getName());
319321
} else {
320322
long start = System.nanoTime();
321323
cv = constructionMetrics.search(searchQuantType)
322324
.timeEncode(() -> compressor.encodeAll(ds.getBaseRavv()));
323325
double encodingTimeS = (System.nanoTime() - start) / 1_000_000_000.0;
326+
if (cv == null) {
327+
throw new IllegalStateException(String.format(
328+
"Compressor '%s' was provided but failed to encode vectors for dataset '%s'. " +
329+
"Aborting to prevent false recall results.", compressor, ds.getName()));
330+
}
324331
System.out.format("%s: %s encoded %d vectors [%.2f MB] in %.2fs%n", ds.getName(), compressor, ds.getBaseVectors().size(), (cv.ramBytesUsed() / 1024f / 1024f), encodingTimeS);
325332
}
326333
}
@@ -838,8 +845,29 @@ public static List<BenchResult> runAllAndCollectResults(
838845

839846
var compressor = getCompressor(buildCompressor, ds);
840847
var searchCompressorObj = getCompressor(searchCompressor, ds);
841-
CompressedVectors cvArg = (searchCompressorObj instanceof CompressedVectors) ? (CompressedVectors) searchCompressorObj : null;
842-
848+
// Encode vectors for reranking if a compressor is provided
849+
CompressedVectors cvArg;
850+
if (features.contains(FeatureId.FUSED_PQ)) {
851+
cvArg = null;
852+
System.out.format("%s: configured to use FUSED PQ, skipping vector compression%n", ds.getName());
853+
} else {
854+
if (searchCompressorObj == null) {
855+
cvArg = null;
856+
System.out.format("%s: No search compressor configured, " +
857+
"FULL PRECISION vectors will be used for search%n", ds.getName());
858+
} else {
859+
cvArg = searchCompressorObj.encodeAll(ds.getBaseRavv());
860+
if (cvArg == null) {
861+
throw new IllegalStateException(String.format(
862+
"Compressor '%s' was provided but failed to encode vectors for dataset '%s'. " +
863+
"Aborting to prevent false recall results.",
864+
searchCompressorObj, ds.getName()));
865+
}
866+
System.out.format("%s: %s encoded %d vectors [%.2f MB] for search%n",
867+
ds.getName(), searchCompressorObj, ds.getBaseVectors().size(),
868+
(cvArg.ramBytesUsed() / 1024f / 1024f));
869+
}
870+
}
843871
// If cache is disabled, we use the (tmp) testDirectory as the output
844872
Path outputDir = cache.isEnabled() ? cache.cacheDir().toAbsolutePath() : testDirectory;
845873

0 commit comments

Comments
 (0)