Skip to content

Commit

Permalink
Account for 0 graph size when initializing HNSW graph (apache#13964)
Browse files Browse the repository at this point in the history
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 (apache#13447).

This change allows to account for missing graphs.
  • Loading branch information
mayya-sharipova authored Oct 31, 2024
1 parent 3041af7 commit 26e0737
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,23 @@ public ConcurrentHnswMerger(
@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);
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);
}
}

HnswGraph initializerGraph = ((HnswGraphProvider) initReader).getGraph(fieldInfo.name);
BitSet initializedNodes = new FixedBitSet(maxOrd);
int[] oldToNewOrdinalMap = getNewOrdMapping(mergedVectorValues, initializedNodes);

return new HnswConcurrentMergeBuilder(
taskExecutor,
numWorker,
scorerSupplier,
M,
beamWidth,
InitializedHnswGraphBuilder.initGraph(M, initializerGraph, oldToNewOrdinalMap, maxOrd),
initializedNodes);
taskExecutor, numWorker, scorerSupplier, M, beamWidth, graph, initializedNodes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ protected HnswBuilder createBuilder(KnnVectorValues mergedVectorValues, int maxO
}

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);
Expand Down

0 comments on commit 26e0737

Please sign in to comment.