Skip to content

Commit 2b47ef1

Browse files
committed
rebase on main
2 parents ae03ef7 + a66fd91 commit 2b47ef1

File tree

70 files changed

+957
-866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+957
-866
lines changed

.github/workflows/unit-tests.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ jobs:
8383
paths: |
8484
**/target/surefire-reports/TEST-*.xml
8585
86+
# Upload Surefire test results as an artifact
87+
- name: Upload Surefire Test Results
88+
uses: actions/upload-artifact@v4
89+
if: always() # ensures upload happens even if tests fail
90+
with:
91+
name: surefire-results--${{ matrix.isa }}-${{ matrix.jdk }}
92+
path: "**/target/surefire-reports/**"
8693

8794
build:
8895
concurrency:
@@ -120,5 +127,14 @@ jobs:
120127
with:
121128
paths: |
122129
**/target/surefire-reports/TEST-*.xml
130+
# Upload Surefire test results as an artifact
131+
- name: Upload Surefire Test Results
132+
uses: actions/upload-artifact@v4
133+
if: always() # ensures upload happens even if tests fail
134+
with:
135+
name: surefire-results--${{ matrix.os }}-${{ matrix.jdk }}
136+
path: "**/target/surefire-reports/**"
137+
138+
123139

124140

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ target/
22
local/
33
.mvn/wrapper/maven-wrapper.jar
44
.java-version
5+
.bob/
56

67
### Bench caches
78
pq_cache/
@@ -14,6 +15,12 @@ replay_pid*
1415
.idea
1516
*.iml
1617

18+
### Eclipse/JDTLS ###
19+
.settings/
20+
.classpath
21+
.project
22+
.factorypath
23+
1724
### VS Code ###
1825
.vscode/
1926

benchmarks-jmh/src/main/java/io/github/jbellis/jvector/bench/IndexConstructionWithStaticSetBenchmark.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*/
1616
package io.github.jbellis.jvector.bench;
1717

18-
import io.github.jbellis.jvector.example.SiftSmall;
1918
import io.github.jbellis.jvector.example.util.SiftLoader;
2019
import io.github.jbellis.jvector.graph.*;
2120
import io.github.jbellis.jvector.graph.similarity.BuildScoreProvider;
22-
import io.github.jbellis.jvector.util.Bits;
2321
import io.github.jbellis.jvector.vector.VectorSimilarityFunction;
2422
import io.github.jbellis.jvector.vector.types.VectorFloat;
2523
import org.openjdk.jmh.annotations.*;

benchmarks-jmh/src/main/java/io/github/jbellis/jvector/bench/PQDistanceCalculationBenchmark.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ public void diversityCalculation(Blackhole blackhole) {
130130
blackhole.consume(totalSimilarity);
131131
}
132132

133+
@Benchmark
134+
public void diversityCalculationScoreProvider(Blackhole blackhole) {
135+
float totalSimilarity = 0;
136+
137+
for (int q = 0; q < queryCount; q++) {
138+
for (int i = 0; i < vectorCount; i++) {
139+
final ScoreFunction sf = buildScoreProvider.diversityScoreFunctionFor(i);
140+
float similarity = sf.similarityTo(q);
141+
totalSimilarity += similarity;
142+
}
143+
}
144+
145+
blackhole.consume(totalSimilarity);
146+
}
147+
133148
private VectorFloat<?> createRandomVector(int dimension) {
134149
VectorFloat<?> vector = VECTOR_TYPE_SUPPORT.createFloatVector(dimension);
135150
for (int i = 0; i < dimension; i++) {

benchmarks-jmh/src/main/java/io/github/jbellis/jvector/bench/StaticSetVectorsBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.github.jbellis.jvector.bench;
1717

18-
import io.github.jbellis.jvector.example.SiftSmall;
18+
import io.github.jbellis.jvector.example.benchmarks.datasets.SiftSmall;
1919
import io.github.jbellis.jvector.example.util.SiftLoader;
2020
import io.github.jbellis.jvector.graph.*;
2121
import io.github.jbellis.jvector.graph.similarity.BuildScoreProvider;

jvector-base/src/main/java/io/github/jbellis/jvector/disk/ByteBufferIndexWriter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ public void writeFloat(float v) {
233233
buffer.putFloat(v);
234234
}
235235

236+
@Override
237+
public void writeFloats(float[] floats, int offset, int count) throws IOException {
238+
buffer.asFloatBuffer().put(floats, offset, count);
239+
}
240+
236241
@Override
237242
public void writeDouble(double v) {
238243
buffer.putDouble(v);
@@ -264,7 +269,7 @@ public void writeUTF(String s) throws IOException {
264269
if (utflen > 65535) {
265270
throw new IOException("encoded string too long: " + utflen + " bytes");
266271
}
267-
272+
268273
buffer.putShort((short) utflen);
269274
buffer.put(bytes);
270275
}

jvector-base/src/main/java/io/github/jbellis/jvector/disk/IndexWriter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.io.Closeable;
2020
import java.io.DataOutput;
2121
import java.io.IOException;
22+
import java.nio.ByteBuffer;
23+
import java.nio.ByteOrder;
2224

2325
/**
2426
* Interface for writing index data.
@@ -30,4 +32,12 @@ public interface IndexWriter extends DataOutput, Closeable {
3032
* @throws IOException if an I/O error occurs
3133
*/
3234
long position() throws IOException;
35+
36+
default void writeFloats(float[] floats, int offset, int count) throws IOException {
37+
ByteBuffer bb = ByteBuffer.allocate(count * Float.BYTES);
38+
// DataOutput specifies BIG_ENDIAN for float
39+
bb.order(ByteOrder.BIG_ENDIAN).asFloatBuffer().put(floats, offset, count);
40+
bb.rewind();
41+
write(bb.array());
42+
}
3343
}

jvector-base/src/main/java/io/github/jbellis/jvector/disk/SimpleMappedReader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.RandomAccessFile;
2323
import java.lang.reflect.Field;
24+
import java.nio.ByteOrder;
2425
import java.nio.MappedByteBuffer;
2526
import java.nio.channels.FileChannel;
2627
import java.nio.file.Path;
@@ -73,6 +74,7 @@ public Supplier(Path path) throws IOException {
7374
throw new RuntimeException("SimpleMappedReader doesn't support files above 2GB");
7475
}
7576
this.buffer = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, raf.length());
77+
this.buffer.order(ByteOrder.BIG_ENDIAN);
7678
this.buffer.load();
7779
}
7880
}

jvector-base/src/main/java/io/github/jbellis/jvector/graph/disk/OnDiskGraphIndex.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,20 @@ public long ramBytesUsed() {
402402
List<Int2ObjectHashMap<int[]>> inMemoryNeighborsLocal = inMemoryNeighbors.get();
403403

404404
long inMemoryNeighborsBytes = RamUsageEstimator.NUM_BYTES_OBJECT_REF;
405-
for (Int2ObjectHashMap<int[]> neighbors : inMemoryNeighborsLocal) {
406-
inMemoryNeighborsBytes += neighbors.values().stream().mapToLong(is -> Integer.BYTES * (long) is.length).sum();
407-
inMemoryNeighborsBytes += RamUsageEstimator.NUM_BYTES_OBJECT_REF;
405+
if (inMemoryNeighborsLocal != null) {
406+
for (Int2ObjectHashMap<int[]> neighbors : inMemoryNeighborsLocal) {
407+
if (neighbors != null) {
408+
inMemoryNeighborsBytes += neighbors.values().stream().mapToLong(is -> Integer.BYTES * (long) is.length).sum();
409+
}
410+
inMemoryNeighborsBytes += RamUsageEstimator.NUM_BYTES_OBJECT_REF;
411+
}
412+
}
413+
414+
Int2ObjectHashMap<FusedFeature.InlineSource> inMemoryFeaturesLocal = inMemoryFeatures.get();
415+
long inMemoryFeaturesBytes = 0;
416+
if (inMemoryFeaturesLocal != null) {
417+
inMemoryFeaturesBytes = inMemoryFeaturesLocal.values().stream().mapToLong(is -> Integer.BYTES * is.ramBytesUsed()).sum();
408418
}
409-
long inMemoryFeaturesBytes = inMemoryFeatures.get().values().stream().mapToLong(is -> Integer.BYTES * is.ramBytesUsed()).sum();
410419
inMemoryFeaturesBytes += RamUsageEstimator.NUM_BYTES_OBJECT_REF;
411420

412421
return Long.BYTES + 6 * Integer.BYTES + RamUsageEstimator.NUM_BYTES_OBJECT_REF

jvector-base/src/main/java/io/github/jbellis/jvector/graph/disk/feature/Feature.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package io.github.jbellis.jvector.graph.disk.feature;
1818

19-
import java.io.DataOutput;
19+
import io.github.jbellis.jvector.disk.IndexWriter;
20+
2021
import java.io.IOException;
2122
import java.util.EnumMap;
2223
import java.util.function.IntFunction;
@@ -35,9 +36,9 @@ default boolean isFused() {
3536

3637
int featureSize();
3738

38-
void writeHeader(DataOutput out) throws IOException;
39+
void writeHeader(IndexWriter out) throws IOException;
3940

40-
default void writeInline(DataOutput out, State state) throws IOException {
41+
default void writeInline(IndexWriter out, State state) throws IOException {
4142
// default no-op
4243
}
4344

0 commit comments

Comments
 (0)