mirror of https://github.com/apache/lucene.git
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:
parent
3041af7a94
commit
26e0737e40
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue