2020
2121package org .elasticsearch .index .codec .vectors .es910 .hnsw ;
2222
23- import org .apache .lucene .util .BitSet ;
2423import org .apache .lucene .util .hnsw .HnswGraph ;
25- import org .apache .lucene .util .hnsw .RandomVectorScorerSupplier ;
26- import org .apache .lucene .util .hnsw .UpdateableRandomVectorScorer ;
2724
2825import java .io .IOException ;
2926
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