-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Concurrent HNSW merging, rebased, not tested after rebase
- Loading branch information
Showing
18 changed files
with
899 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
lucene/core/src/java/org/apache/lucene/util/hnsw/ConcurrentHnswMerger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.util.hnsw; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ExecutorService; | ||
import org.apache.lucene.codecs.HnswGraphProvider; | ||
import org.apache.lucene.index.FieldInfo; | ||
import org.apache.lucene.search.DocIdSetIterator; | ||
import org.apache.lucene.util.BitSet; | ||
import org.apache.lucene.util.FixedBitSet; | ||
|
||
/** This merger merges graph in a concurrent manner, by using {@link HnswConcurrentMergeBuilder} */ | ||
public class ConcurrentHnswMerger extends IncrementalHnswGraphMerger { | ||
|
||
private final ExecutorService exec; | ||
private final int numWorker; | ||
|
||
/** | ||
* @param fieldInfo FieldInfo for the field being merged | ||
*/ | ||
public ConcurrentHnswMerger( | ||
FieldInfo fieldInfo, | ||
RandomVectorScorerSupplier scorerSupplier, | ||
int M, | ||
int beamWidth, | ||
ExecutorService exec, | ||
int numWorker) { | ||
super(fieldInfo, scorerSupplier, M, beamWidth); | ||
this.exec = exec; | ||
this.numWorker = numWorker; | ||
} | ||
|
||
@Override | ||
protected IHnswGraphBuilder createBuilder(DocIdSetIterator mergedVectorIterator, int maxOrd) | ||
throws IOException { | ||
if (initReader == null) { | ||
return new HnswConcurrentMergeBuilder( | ||
exec, numWorker, scorerSupplier, M, beamWidth, new OnHeapHnswGraph(M, maxOrd), null); | ||
} | ||
|
||
HnswGraph initializerGraph = ((HnswGraphProvider) initReader).getGraph(fieldInfo.name); | ||
BitSet initializedNodes = new FixedBitSet(maxOrd); | ||
int[] oldToNewOrdinalMap = getNewOrdMapping(mergedVectorIterator, initializedNodes); | ||
|
||
return new HnswConcurrentMergeBuilder( | ||
exec, | ||
numWorker, | ||
scorerSupplier, | ||
M, | ||
beamWidth, | ||
InitializedHnswGraphBuilder.initGraph(M, initializerGraph, oldToNewOrdinalMap, maxOrd), | ||
initializedNodes); | ||
} | ||
} |
Oops, something went wrong.