diff --git a/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskADCGraphIndex.java b/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskADCGraphIndex.java index b746d20d..b50f0941 100644 --- a/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskADCGraphIndex.java +++ b/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskADCGraphIndex.java @@ -92,7 +92,7 @@ public OnDiskADCGraphIndex(ReaderSupplier readerSupplier, long offset) * while preserving the original relative ordering in `graph`. That is, for all node ids i and j, * if i < j in `graph` then map[i] < map[j] in the returned map. */ - public static Map getSequentialRenumbering(GraphIndex graph) { + public static Map getSequentialRenumbering(GraphIndex graph) { try (var view = graph.getView()) { Int2IntHashMap oldToNewMap = new Int2IntHashMap(-1); int nextOrdinal = 0; @@ -234,7 +234,7 @@ public void close() throws IOException { * * If any nodes have been deleted, you must use the overload specifying `oldToNewOrdinals` instead. */ - public static void write(GraphIndex graph, RandomAccessVectorValues vectors, PQVectors pqVectors, DataOutput out) + public static void write(GraphIndex graph, RandomAccessVectorValues vectors, PQVectors pqVectors, DataOutput out) throws IOException { try (var view = graph.getView()) { @@ -257,7 +257,7 @@ public static void write(GraphIndex graph, RandomAccessVectorValues vectors, * compressed representations are embedded in the serialized graph to support accelerated ADC. * @param out the output to write to */ - public static void write(GraphIndex graph, + public static void write(GraphIndex graph, RandomAccessVectorValues vectors, Map oldToNewOrdinals, PQVectors pqVectors, diff --git a/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskGraphIndex.java b/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskGraphIndex.java index aca3313e..0e16ef42 100644 --- a/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskGraphIndex.java +++ b/jvector-base/src/main/java/io/github/jbellis/jvector/disk/OnDiskGraphIndex.java @@ -65,7 +65,7 @@ public OnDiskGraphIndex(ReaderSupplier readerSupplier, long offset) * while preserving the original relative ordering in `graph`. That is, for all node ids i and j, * if i < j in `graph` then map[i] < map[j] in the returned map. */ - public static Map getSequentialRenumbering(GraphIndex graph) { + public static Map getSequentialRenumbering(GraphIndex graph) { try (var view = graph.getView()) { Int2IntHashMap oldToNewMap = new Int2IntHashMap(-1); int nextOrdinal = 0; @@ -179,7 +179,7 @@ public void close() throws IOException { * * If any nodes have been deleted, you must use the overload specifying `oldToNewOrdinals` instead. */ - public static void write(GraphIndex graph, RandomAccessVectorValues vectors, DataOutput out) + public static void write(GraphIndex graph, RandomAccessVectorValues vectors, DataOutput out) throws IOException { try (var view = graph.getView()) { diff --git a/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndex.java b/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndex.java index 28f72e68..2a903854 100644 --- a/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndex.java +++ b/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndex.java @@ -119,7 +119,7 @@ default int getIdUpperBound() { } } - static String prettyPrint(GraphIndex graph) { + static String prettyPrint(GraphIndex graph) { StringBuilder sb = new StringBuilder(); sb.append(graph); sb.append("\n"); diff --git a/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndexBuilder.java b/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndexBuilder.java index 693d3152..060a7302 100644 --- a/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndexBuilder.java +++ b/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphIndexBuilder.java @@ -56,7 +56,7 @@ public class GraphIndexBuilder { private final VectorSimilarityFunction similarityFunction; private final float neighborOverflow; private final float alpha; - private final PoolingSupport> graphSearcher; + private final PoolingSupport graphSearcher; @VisibleForTesting final OnHeapGraphIndex graph; @@ -153,7 +153,7 @@ public GraphIndexBuilder( new OnHeapGraphIndex( M, (node, m) -> new ConcurrentNeighborSet(node, m, similarity, alpha)); // this view will never get closed, but it's okay because we know it's an OHGI view, which has a no-op close - this.graphSearcher = PoolingSupport.newThreadBased(() -> new GraphSearcher.Builder<>(graph.getView()).withConcurrentUpdates().build()); + this.graphSearcher = PoolingSupport.newThreadBased(() -> new GraphSearcher.Builder(graph.getView()).withConcurrentUpdates().build()); // in scratch we store candidates in reverse order: worse candidates are first this.naturalScratch = PoolingSupport.newThreadBased(() -> new NodeArray(Math.max(beamWidth, M + 1))); diff --git a/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphSearcher.java b/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphSearcher.java index 3a5f3fb1..1fea2d0b 100644 --- a/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphSearcher.java +++ b/jvector-base/src/main/java/io/github/jbellis/jvector/graph/GraphSearcher.java @@ -44,7 +44,7 @@ * Searches a graph to find nearest neighbors to a query vector. For more background on the * search algorithm, see {@link GraphIndex}. */ -public class GraphSearcher { +public class GraphSearcher { private final GraphIndex.View view; @@ -76,9 +76,9 @@ public class GraphSearcher { * Convenience function for simple one-off searches. It is caller's responsibility to make sure that it * is the unique owner of the vectors instance passed in here. */ - public static SearchResult search(VectorFloat targetVector, int topK, RandomAccessVectorValues vectors, VectorSimilarityFunction similarityFunction, GraphIndex graph, Bits acceptOrds) { + public static SearchResult search(VectorFloat targetVector, int topK, RandomAccessVectorValues vectors, VectorSimilarityFunction similarityFunction, GraphIndex graph, Bits acceptOrds) { try (var view = graph.getView()) { - var searcher = new GraphSearcher.Builder<>(view).withConcurrentUpdates().build(); + var searcher = new GraphSearcher.Builder(view).withConcurrentUpdates().build(); NodeSimilarity.ExactScoreFunction scoreFunction = i -> similarityFunction.compare(targetVector, vectors.vectorValue(i)); return searcher.search(scoreFunction, null, topK, acceptOrds); } catch (Exception e) { @@ -87,7 +87,7 @@ public static SearchResult search(VectorFloat targetVector, int topK, Ran } /** Builder */ - public static class Builder { + public static class Builder { private final GraphIndex.View view; private boolean concurrent; @@ -95,15 +95,15 @@ public Builder(GraphIndex.View view) { this.view = view; } - public Builder withConcurrentUpdates() { + public Builder withConcurrentUpdates() { this.concurrent = true; return this; } - public GraphSearcher build() { + public GraphSearcher build() { int size = view.getIdUpperBound(); BitSet bits = concurrent ? new GrowableBitSet(size) : new SparseFixedBitSet(size); - return new GraphSearcher<>(view, bits); + return new GraphSearcher(view, bits); } } diff --git a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/Bench.java b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/Bench.java index dc4035b2..59310f86 100644 --- a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/Bench.java +++ b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/Bench.java @@ -190,7 +190,7 @@ private static ResultSummary performQueries(DataSet ds, RandomAccessVectorValues sf = cv.approximateScoreFunctionFor(queryVector, ds.similarityFunction); } NodeSimilarity.Reranker rr = (j) -> ds.similarityFunction.compare(queryVector, view.getVector(j)); - sr = new GraphSearcher.Builder<>(view) + sr = new GraphSearcher.Builder(view) .build() .search(sf, rr, efSearch, Bits.ALL); } catch (Exception e) { diff --git a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/SiftSmall.java b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/SiftSmall.java index ee071e2c..870ade10 100644 --- a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/SiftSmall.java +++ b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/SiftSmall.java @@ -94,7 +94,7 @@ private static void testRecallInternal(GraphIndex graph, RandomAccessVectorValue var queryVector = queryVectors.get(i); SearchResult.NodeScore[] nn; var view = graph.getView(); - var searcher = new GraphSearcher.Builder<>(view).build(); + var searcher = new GraphSearcher.Builder(view).build(); if (compressedVectors == null) { NodeSimilarity.ExactScoreFunction sf = (j) -> VectorSimilarityFunction.EUCLIDEAN.compare(queryVector, ravv.vectorValue(j)); nn = searcher.search(sf, null, 100, Bits.ALL).getNodes(); diff --git a/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/Test2DThreshold.java b/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/Test2DThreshold.java index 820b5052..862cb0d3 100644 --- a/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/Test2DThreshold.java +++ b/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/Test2DThreshold.java @@ -53,7 +53,7 @@ public void testThreshold() throws IOException { var onHeapGraph = builder.build(); // test raw vectors - var searcher = new GraphSearcher.Builder<>(onHeapGraph.getView()).build(); + var searcher = new GraphSearcher.Builder(onHeapGraph.getView()).build(); for (int i = 0; i < 10; i++) { TestParams tp = createTestParams(vectors); @@ -75,7 +75,7 @@ public void testThreshold() throws IOException { { for (int i = 0; i < 10; i++) { TestParams tp = createTestParams(vectors); - searcher = new GraphSearcher.Builder<>(onDiskGraph.getView()).build(); + searcher = new GraphSearcher.Builder(onDiskGraph.getView()).build(); NodeSimilarity.Reranker reranker = (j) -> VectorSimilarityFunction.EUCLIDEAN.compare(tp.q, ravv.vectorValue(j)); var asf = cv.approximateScoreFunctionFor(tp.q, VectorSimilarityFunction.EUCLIDEAN); var result = searcher.search(asf, reranker, vectors.length, tp.th, Bits.ALL); diff --git a/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/TestVectorGraph.java b/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/TestVectorGraph.java index da6f539a..b3bbc16c 100644 --- a/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/TestVectorGraph.java +++ b/jvector-tests/src/test/java/io/github/jbellis/jvector/graph/TestVectorGraph.java @@ -135,7 +135,7 @@ public void testResume() { int initialTopK = 10; int resumeTopK = 15; var query = randomVector(dim); - var searcher = new GraphSearcher.Builder<>(graph.getView()).build(); + var searcher = new GraphSearcher.Builder(graph.getView()).build(); var initial = searcher.search((NodeSimilarity.ExactScoreFunction) i -> similarityFunction.compare(query, vectors.vectorValue(i)), null, initialTopK, acceptOrds); assertEquals(initialTopK, initial.getNodes().length);