Account for 0 graph size when initializing HNSW graph (#13964)

When initializing a joint graph from one of the segments' graphs,
 we always assume that a segment's graph is present. But later we want
 to explore an option where some segments will not have graphs (#13447).

This change allows to account for missing graphs.
This commit is contained in:
Mayya Sharipova 2024-10-31 10:22:30 -04:00 committed by GitHub
parent 3041af7a94
commit 26e0737e40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 20 deletions

View File

@ -48,28 +48,23 @@ public class ConcurrentHnswMerger extends IncrementalHnswGraphMerger {
@Override
protected HnswBuilder createBuilder(KnnVectorValues mergedVectorValues, int maxOrd)
throws IOException {
OnHeapHnswGraph graph;
BitSet initializedNodes = null;
if (initReader == null) {
return new HnswConcurrentMergeBuilder(
taskExecutor,
numWorker,
scorerSupplier,
M,
beamWidth,
new OnHeapHnswGraph(M, maxOrd),
null);
}
graph = new OnHeapHnswGraph(M, maxOrd);
} else {
HnswGraph initializerGraph = ((HnswGraphProvider) initReader).getGraph(fieldInfo.name);
BitSet initializedNodes = new FixedBitSet(maxOrd);
if (initializerGraph.size() == 0) {
graph = new OnHeapHnswGraph(M, maxOrd);
} else {
initializedNodes = new FixedBitSet(maxOrd);
int[] oldToNewOrdinalMap = getNewOrdMapping(mergedVectorValues, initializedNodes);
graph =
InitializedHnswGraphBuilder.initGraph(M, initializerGraph, oldToNewOrdinalMap, maxOrd);
}
}
return new HnswConcurrentMergeBuilder(
taskExecutor,
numWorker,
scorerSupplier,
M,
beamWidth,
InitializedHnswGraphBuilder.initGraph(M, initializerGraph, oldToNewOrdinalMap, maxOrd),
initializedNodes);
taskExecutor, numWorker, scorerSupplier, M, beamWidth, graph, initializedNodes);
}
}

View File

@ -121,6 +121,10 @@ public class IncrementalHnswGraphMerger implements HnswGraphMerger {
}
HnswGraph initializerGraph = ((HnswGraphProvider) initReader).getGraph(fieldInfo.name);
if (initializerGraph.size() == 0) {
return HnswGraphBuilder.create(
scorerSupplier, M, beamWidth, HnswGraphBuilder.randSeed, maxOrd);
}
BitSet initializedNodes = new FixedBitSet(maxOrd);
int[] oldToNewOrdinalMap = getNewOrdMapping(mergedVectorValues, initializedNodes);