Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
import io.github.jbellis.jvector.graph.disk.feature.Feature;
import io.github.jbellis.jvector.graph.disk.feature.FeatureId;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -46,6 +51,7 @@ class NodeRecordTask implements Callable<List<NodeRecordTask.Result>> {
private final int recordSize;
private final long baseOffset; // Base file offset for L0 (offsets calculated per-ordinal)
private final ByteBuffer buffer;
private final Path filePath;

/**
* Result of building a node record.
Expand All @@ -71,7 +77,8 @@ static class Result {
Map<FeatureId, IntFunction<Feature.State>> featureStateSuppliers,
int recordSize,
long baseOffset,
ByteBuffer buffer) {
ByteBuffer buffer,
Path filePath) {
this.startOrdinal = startOrdinal;
this.endOrdinal = endOrdinal;
this.ordinalMapper = ordinalMapper;
Expand All @@ -82,6 +89,7 @@ static class Result {
this.recordSize = recordSize;
this.baseOffset = baseOffset;
this.buffer = buffer;
this.filePath = filePath;
}

@Override
Expand Down Expand Up @@ -125,16 +133,28 @@ public List<Result> call() throws Exception {
}

// Write inline features
long featureOffset = fileOffset + Integer.BYTES; // After the ordinal
for (var feature : inlineFeatures) {
var supplier = featureStateSuppliers.get(feature.id());
if (supplier == null) {
// Write zeros for missing supplier
for (int i = 0; i < feature.featureSize(); i++) {
writer.writeByte(0);
// Read existing data from file to preserve what was written by writeInline()
try (var channel = FileChannel.open(filePath, StandardOpenOption.READ)) {
ByteBuffer readBuffer = ByteBuffer.allocate(feature.featureSize());
int bytesRead = channel.read(readBuffer, featureOffset);
if (bytesRead != feature.featureSize()) {
throw new IOException(String.format(
"Expected to read %d bytes but got %d at offset %d",
feature.featureSize(), bytesRead, featureOffset));
}
readBuffer.flip();
writer.write(readBuffer.array(), 0, feature.featureSize());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} else {
feature.writeInline(writer, supplier.apply(originalOrdinal));
}
featureOffset += feature.featureSize();
}

// Write neighbors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public void writeL0Records(OrdinalMapper ordinalMapper,
featureStateSuppliers,
recordSize,
baseOffset, // Base offset (task calculates per-ordinal offsets)
buffer
buffer,
filePath
);

return task.call();
Expand Down
8 changes: 4 additions & 4 deletions jvector-examples/yaml-configs/autoDefault.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 6

dataset: cohere-english-v3-100k
dataset: default

construction:
outDegree: [32]
efConstruction: [100]
neighborOverflow: [1.2f]
addHierarchy: [Yes]
addHierarchy: [Yes, No]
refineFinalGraph: [Yes]
fusedGraph: [No]
compression:
Expand All @@ -18,12 +18,12 @@ construction:
centerData: No
anisotropicThreshold: -1.0 # optional parameter. By default, anisotropicThreshold=-1 (i.e., no anisotropy)
reranking:
- NVQ
- FP
useSavedIndexIfExists: Yes

search:
topKOverquery:
10: [1.0]
10: [1.0, 2.0, 5.0]
useSearchPruning: [Yes]
compression:
- type: PQ
Expand Down
4 changes: 2 additions & 2 deletions jvector-examples/yaml-configs/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ construction:
neighborOverflow: [1.2f]
addHierarchy: [Yes]
refineFinalGraph: [Yes]
fusedGraph: [No]
fusedGraph: [Yes, No]
compression:
- type: PQ
parameters:
Expand All @@ -18,7 +18,7 @@ construction:
centerData: No
anisotropicThreshold: -1.0 # optional parameter. By default, anisotropicThreshold=-1 (i.e., no anisotropy)
reranking:
- NVQ
- FP
useSavedIndexIfExists: Yes

search:
Expand Down