Package org.apache.lucene.util.hnsw
Class HnswGraphBuilder
java.lang.Object
org.apache.lucene.util.hnsw.HnswGraphBuilder
Builder for HNSW graph. See
HnswGraph
for a gloss on the algorithm and the meaning of the
hyperparameters.-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
A name for the HNSW component for the info-stream *static long
Random seed for level generation; public to expose for testing * -
Constructor Summary
ConstructorDescriptionHnswGraphBuilder
(RandomAccessVectorValuesProducer vectors, VectorSimilarityFunction similarityFunction, int maxConn, int beamWidth, long seed) Reads all the vectors from a VectorValues, builds a graph connecting them by their dense ordinals, using the given hyperparameter settings, and returns the resulting graph. -
Method Summary
Modifier and TypeMethodDescriptionbuild
(RandomAccessVectorValues vectors) Reads all the vectors from two copies of a random access VectorValues.void
setInfoStream
(InfoStream infoStream) Set info-stream to output debugging information *
-
Field Details
-
HNSW_COMPONENT
A name for the HNSW component for the info-stream *- See Also:
-
randSeed
public static long randSeedRandom seed for level generation; public to expose for testing *
-
-
Constructor Details
-
HnswGraphBuilder
public HnswGraphBuilder(RandomAccessVectorValuesProducer vectors, VectorSimilarityFunction similarityFunction, int maxConn, int beamWidth, long seed) Reads all the vectors from a VectorValues, builds a graph connecting them by their dense ordinals, using the given hyperparameter settings, and returns the resulting graph.- Parameters:
vectors
- the vectors whose relations are represented by the graph - must provide a different view over those vectors than the one used to add via addGraphNode.maxConn
- the number of connections to make when adding a new graph node; roughly speaking the graph fanout.beamWidth
- the size of the beam search to use when finding nearest neighbors.seed
- the seed for a random number generator used during graph construction. Provide this to ensure repeatable construction.
-
-
Method Details
-
build
Reads all the vectors from two copies of a random access VectorValues. Providing two copies enables efficient retrieval without extra data copying, while avoiding collision of the returned values.- Parameters:
vectors
- the vectors for which to build a nearest neighbors graph. Must be an independet accessor for the vectors- Throws:
IOException
-
setInfoStream
Set info-stream to output debugging information *
-