Module org.apache.lucene.codecs
Class HnswBitVectorsFormat
java.lang.Object
org.apache.lucene.codecs.KnnVectorsFormat
org.apache.lucene.codecs.bitvectors.HnswBitVectorsFormat
- All Implemented Interfaces:
NamedSPILoader.NamedSPI
Encodes bit vector values into an associated graph connecting the documents having values. The
graph is used to power HNSW search. The format consists of two files, and uses
Lucene99FlatVectorsFormat to store the actual vectors, but with a custom scorer implementation:
For details on graph storage and file extensions, see Lucene99HnswVectorsFormat.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe number of candidate neighbors to track while searching the graph for each newly inserted node.private final FlatVectorsFormatThe format for storing, reading, merging vectors on diskprivate final intControls how many of the nearest neighbor candidates are connected to the new node.private final TaskExecutorstatic final Stringprivate final intFields inherited from class org.apache.lucene.codecs.KnnVectorsFormat
DEFAULT_MAX_DIMENSIONS, EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a format using default graph construction parametersHnswBitVectorsFormat(int maxConn, int beamWidth) Constructs a format using the given graph construction parameters.HnswBitVectorsFormat(int maxConn, int beamWidth, int numMergeWorkers, ExecutorService mergeExec) Constructs a format using the given graph construction parameters and scalar quantization. -
Method Summary
Modifier and TypeMethodDescriptionfieldsReader(SegmentReadState state) Returns aKnnVectorsReaderto read the vectors from the index.fieldsWriter(SegmentWriteState state) Returns aKnnVectorsWriterto write the vectors to the index.intgetMaxDimensions(String fieldName) Returns the maximum number of vector dimensions supported by this codec for the given field nametoString()Methods inherited from class org.apache.lucene.codecs.KnnVectorsFormat
availableKnnVectorsFormats, forName, getName, reloadKnnVectorsFormat
-
Field Details
-
NAME
- See Also:
-
maxConn
private final int maxConnControls how many of the nearest neighbor candidates are connected to the new node. Defaults toLucene99HnswVectorsFormat.DEFAULT_MAX_CONN. SeeHnswGraphfor more details. -
beamWidth
private final int beamWidthThe number of candidate neighbors to track while searching the graph for each newly inserted node. Defaults toLucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH. SeeHnswGraphfor details. -
flatVectorsFormat
The format for storing, reading, merging vectors on disk -
numMergeWorkers
private final int numMergeWorkers -
mergeExec
-
-
Constructor Details
-
HnswBitVectorsFormat
public HnswBitVectorsFormat()Constructs a format using default graph construction parameters -
HnswBitVectorsFormat
public HnswBitVectorsFormat(int maxConn, int beamWidth) Constructs a format using the given graph construction parameters.- Parameters:
maxConn- the maximum number of connections to a node in the HNSW graphbeamWidth- the size of the queue maintained during graph construction.
-
HnswBitVectorsFormat
public HnswBitVectorsFormat(int maxConn, int beamWidth, int numMergeWorkers, ExecutorService mergeExec) Constructs a format using the given graph construction parameters and scalar quantization.- Parameters:
maxConn- the maximum number of connections to a node in the HNSW graphbeamWidth- the size of the queue maintained during graph construction.numMergeWorkers- number of workers (threads) that will be used when doing merge. If larger than 1, a non-nullExecutorServicemust be passed as mergeExecmergeExec- theExecutorServicethat will be used by ALL vector writers that are generated by this format to do the merge
-
-
Method Details
-
fieldsWriter
Description copied from class:KnnVectorsFormatReturns aKnnVectorsWriterto write the vectors to the index.- Specified by:
fieldsWriterin classKnnVectorsFormat- Throws:
IOException
-
fieldsReader
Description copied from class:KnnVectorsFormatReturns aKnnVectorsReaderto read the vectors from the index.- Specified by:
fieldsReaderin classKnnVectorsFormat- Throws:
IOException
-
getMaxDimensions
Description copied from class:KnnVectorsFormatReturns the maximum number of vector dimensions supported by this codec for the given field nameCodecs should override this method to specify the maximum number of dimensions they support.
- Overrides:
getMaxDimensionsin classKnnVectorsFormat- Parameters:
fieldName- the field name- Returns:
- the maximum number of vector dimensions.
-
toString
-