Skip to content

Commit

Permalink
close files when done with them
Browse files Browse the repository at this point in the history
  • Loading branch information
jbellis committed Sep 29, 2023
1 parent 369f517 commit f89e4c4
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ private static void testRecall(int M, int efConstruction, List<Boolean> diskOpti

var graphPath = testDirectory.resolve("graph" + M + efConstruction + ds.name);
try {
DataOutputStream outputStream = new DataOutputStream(new BufferedOutputStream(Files.newOutputStream(graphPath)));
OnDiskGraphIndex.write(onHeapGraph, floatVectors, outputStream);
outputStream.flush();
var onDiskGraph = new CachingGraphIndex(new OnDiskGraphIndex<>(ReaderSupplierFactory.open(graphPath), 0));

int queryRuns = 2;
for (int overquery : efSearchOptions) {
for (boolean useDisk : diskOptions) {
start = System.nanoTime();
var pqr = performQueries(ds, floatVectors, useDisk ? cv : null, useDisk ? onDiskGraph : onHeapGraph, topK, topK * overquery, queryRuns);
var recall = ((double) pqr.topKFound) / (queryRuns * ds.queryVectors.size() * topK);
System.out.format(" Query PQ=%b top %d/%d recall %.4f in %.2fs after %s nodes visited%n",
useDisk, topK, overquery, recall, (System.nanoTime() - start) / 1_000_000_000.0, pqr.nodesVisited);
try (var outputStream = new DataOutputStream(new BufferedOutputStream(Files.newOutputStream(graphPath)))) {
OnDiskGraphIndex.write(onHeapGraph, floatVectors, outputStream);
}
try (var onDiskGraph = new CachingGraphIndex(new OnDiskGraphIndex<>(ReaderSupplierFactory.open(graphPath), 0))) {
int queryRuns = 2;
for (int overquery : efSearchOptions) {
for (boolean useDisk : diskOptions) {
start = System.nanoTime();
var pqr = performQueries(ds, floatVectors, useDisk ? cv : null, useDisk ? onDiskGraph : onHeapGraph, topK, topK * overquery, queryRuns);
var recall = ((double) pqr.topKFound) / (queryRuns * ds.queryVectors.size() * topK);
System.out.format(" Query PQ=%b top %d/%d recall %.4f in %.2fs after %s nodes visited%n",
useDisk, topK, overquery, recall, (System.nanoTime() - start) / 1_000_000_000.0, pqr.nodesVisited);
}
}
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ private static void gridSearch(DataSet ds, List<Integer> mGrid, List<Integer> ef
start = System.nanoTime();
var quantizedVectors = pq.encodeAll(ds.baseVectors);
var compressedVectors = new CompressedVectors(pq, quantizedVectors);
System.out.format("PQ encoded %d[%.2f MB] in %.2fs,%n", ds.baseVectors.size(), (compressedVectors.memorySize()/1024f/1024f) , (System.nanoTime() - start) / 1_000_000_000.0);
System.out.format("PQ encoded %d vectors [%.2f MB] in %.2fs,%n", ds.baseVectors.size(), (compressedVectors.memorySize()/1024f/1024f) , (System.nanoTime() - start) / 1_000_000_000.0);

var testDirectory = Files.createTempDirectory("BenchGraphDir");

Expand Down

0 comments on commit f89e4c4

Please sign in to comment.