Skip to content

Commit 8a0a968

Browse files
committed
Remove HnswGraphMerger, clean classes
1 parent 0489e7f commit 8a0a968

File tree

4 files changed

+4
-127
lines changed

4 files changed

+4
-127
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/ES910HnswVectorsWriter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer;
4848
import org.apache.lucene.util.packed.DirectMonotonicWriter;
4949
import org.elasticsearch.index.codec.vectors.es910.hnsw.HnswGraphBuilder;
50-
import org.elasticsearch.index.codec.vectors.es910.hnsw.HnswGraphMerger;
5150
import org.elasticsearch.index.codec.vectors.es910.hnsw.IncrementalHnswGraphMerger;
5251
import org.elasticsearch.index.codec.vectors.es910.hnsw.NeighborArray;
5352
import org.elasticsearch.index.codec.vectors.es910.hnsw.OnHeapHnswGraph;
@@ -354,7 +353,7 @@ public void mergeOneField(FieldInfo fieldInfo, MergeState mergeState) throws IOE
354353
int[][] vectorIndexNodeOffsets = null;
355354
if (scorerSupplier.totalVectorCount() > 0) {
356355
// build graph
357-
HnswGraphMerger merger = createGraphMerger(fieldInfo, scorerSupplier);
356+
IncrementalHnswGraphMerger merger = createGraphMerger(fieldInfo, scorerSupplier);
358357
for (int i = 0; i < mergeState.liveDocs.length; i++) {
359358
if (hasVectorValues(mergeState.fieldInfos[i], fieldInfo.name)) {
360359
merger.addReader(mergeState.knnVectorsReaders[i], mergeState.docMaps[i], mergeState.liveDocs[i]);
@@ -490,7 +489,7 @@ private void writeMeta(
490489
}
491490
}
492491

493-
private HnswGraphMerger createGraphMerger(FieldInfo fieldInfo, RandomVectorScorerSupplier scorerSupplier) {
492+
private IncrementalHnswGraphMerger createGraphMerger(FieldInfo fieldInfo, RandomVectorScorerSupplier scorerSupplier) {
494493
return new IncrementalHnswGraphMerger(fieldInfo, scorerSupplier, M, beamWidth);
495494
}
496495

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/hnsw/HnswGraphMerger.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/hnsw/IncrementalHnswGraphMerger.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
/**
4545
* This merges multiple graphs in a single thread in incremental fashion.
4646
*/
47-
public class IncrementalHnswGraphMerger implements HnswGraphMerger {
47+
public class IncrementalHnswGraphMerger {
4848

4949
protected final FieldInfo fieldInfo;
5050
protected final RandomVectorScorerSupplier scorerSupplier;
@@ -71,7 +71,6 @@ public IncrementalHnswGraphMerger(FieldInfo fieldInfo, RandomVectorScorerSupplie
7171
* Adds a reader to the graph merger if it meets the following criteria: 1. does not contain any
7272
* deleted docs 2. is a HnswGraphProvider
7373
*/
74-
@Override
7574
public IncrementalHnswGraphMerger addReader(KnnVectorsReader reader, MergeState.DocMap docMap, Bits liveDocs) throws IOException {
7675
numReaders++;
7776
if (hasDeletes(liveDocs) || (reader instanceof HnswGraphProvider == false)) {
@@ -175,7 +174,6 @@ protected final int[][] getNewOrdMapping(KnnVectorValues mergedVectorValues, Bit
175174
return oldToNewOrdinalMap;
176175
}
177176

178-
@Override
179177
public OnHeapHnswGraph merge(KnnVectorValues mergedVectorValues, InfoStream infoStream, int maxOrd) throws IOException {
180178
HnswBuilder builder = createBuilder(mergedVectorValues, maxOrd);
181179
builder.setInfoStream(infoStream);

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/hnsw/InitializedHnswGraphBuilder.java

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
package org.elasticsearch.index.codec.vectors.es910.hnsw;
2222

23-
import org.apache.lucene.util.BitSet;
2423
import org.apache.lucene.util.hnsw.HnswGraph;
25-
import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier;
26-
import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer;
2724

2825
import java.io.IOException;
2926

@@ -33,39 +30,7 @@
3330
* This creates a graph builder that is initialized with the provided HnswGraph. This is useful for
3431
* merging HnswGraphs from multiple segments.
3532
*/
36-
public final class InitializedHnswGraphBuilder extends HnswGraphBuilder {
37-
38-
/**
39-
* Create a new HnswGraphBuilder that is initialized with the provided HnswGraph.
40-
*
41-
* @param scorerSupplier the scorer to use for vectors
42-
* @param beamWidth the number of nodes to explore in the search
43-
* @param seed the seed for the random number generator
44-
* @param initializerGraph the graph to initialize the new graph builder
45-
* @param newOrdMap a mapping from the old node ordinal to the new node ordinal
46-
* @param initializedNodes a bitset of nodes that are already initialized in the initializerGraph
47-
* @param totalNumberOfVectors the total number of vectors in the new graph, this should include
48-
* all vectors expected to be added to the graph in the future
49-
* @return a new HnswGraphBuilder that is initialized with the provided HnswGraph
50-
* @throws IOException when reading the graph fails
51-
*/
52-
public static InitializedHnswGraphBuilder fromGraph(
53-
RandomVectorScorerSupplier scorerSupplier,
54-
int beamWidth,
55-
long seed,
56-
HnswGraph initializerGraph,
57-
int[] newOrdMap,
58-
BitSet initializedNodes,
59-
int totalNumberOfVectors
60-
) throws IOException {
61-
return new InitializedHnswGraphBuilder(
62-
scorerSupplier,
63-
beamWidth,
64-
seed,
65-
initGraph(initializerGraph, newOrdMap, totalNumberOfVectors),
66-
initializedNodes
67-
);
68-
}
33+
public final class InitializedHnswGraphBuilder {
6934

7035
public static OnHeapHnswGraph initGraph(HnswGraph initializerGraph, int[] newOrdMap, int totalNumberOfVectors) throws IOException {
7136
OnHeapHnswGraph hnsw = new OnHeapHnswGraph(initializerGraph.maxConn(), totalNumberOfVectors);
@@ -88,33 +53,4 @@ public static OnHeapHnswGraph initGraph(HnswGraph initializerGraph, int[] newOrd
8853
}
8954
return hnsw;
9055
}
91-
92-
private final BitSet initializedNodes;
93-
94-
public InitializedHnswGraphBuilder(
95-
RandomVectorScorerSupplier scorerSupplier,
96-
int beamWidth,
97-
long seed,
98-
OnHeapHnswGraph initializedGraph,
99-
BitSet initializedNodes
100-
) throws IOException {
101-
super(scorerSupplier, beamWidth, seed, initializedGraph);
102-
this.initializedNodes = initializedNodes;
103-
}
104-
105-
@Override
106-
public void addGraphNode(int node, UpdateableRandomVectorScorer scorer) throws IOException {
107-
if (initializedNodes.get(node)) {
108-
return;
109-
}
110-
super.addGraphNode(node, scorer);
111-
}
112-
113-
@Override
114-
public void addGraphNode(int node) throws IOException {
115-
if (initializedNodes.get(node)) {
116-
return;
117-
}
118-
super.addGraphNode(node);
119-
}
12056
}

0 commit comments

Comments
 (0)