Class FlatVectorsWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,Accountable
- Direct Known Subclasses:
Lucene104ScalarQuantizedVectorsWriter,Lucene99FlatVectorsWriter
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceData prepared while merging a field for scoring its merged vectors.Nested classes/interfaces inherited from class org.apache.lucene.codecs.KnnVectorsWriter
KnnVectorsWriter.MergedVectorValues -
Field Summary
FieldsFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFlatVectorsWriter(FlatVectorsScorer vectorsScorer) Sole constructor -
Method Summary
Modifier and TypeMethodDescriptionabstract FlatFieldVectorsWriter<?> Add a new field for indexingfinal IORunnablemergeOneField(FieldInfo fieldInfo, MergeState mergeState) Merges vectors for a single field, returning a runnable for any deferred work (e.g., HNSW graph construction).abstract voidmergeOneFlatVectorField(FieldInfo fieldInfo, MergeState mergeState) mergeOneFlatVectorFieldForMergeScorer(FieldInfo fieldInfo, MergeState mergeState, IntPredicate needsMergeScorer) Merges one field and, while writing the merged vectors, optionally prepares what a merge scorer needs, so that the merged float vectors need not be read back.Methods inherited from class org.apache.lucene.codecs.KnnVectorsWriter
finish, flush, mapOldOrdToNewOrd, mergeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources, ramBytesUsed
-
Field Details
-
vectorsScorer
Scorer for flat vectors
-
-
Constructor Details
-
FlatVectorsWriter
Sole constructor
-
-
Method Details
-
getFlatVectorScorer
- Returns:
- the
FlatVectorsScorerfor this reader.
-
addField
Add a new field for indexing- Specified by:
addFieldin classKnnVectorsWriter- Parameters:
fieldInfo- fieldInfo of the field to add- Returns:
- a writer for the field
- Throws:
IOException- if an I/O error occurs when adding the field
-
mergeOneField
public final IORunnable mergeOneField(FieldInfo fieldInfo, MergeState mergeState) throws IOException Description copied from class:KnnVectorsWriterMerges vectors for a single field, returning a runnable for any deferred work (e.g., HNSW graph construction). The default implementation merges naively the vectors and returnsnull(no deferred work).Subclasses should override this method may implement a two-phase merge strategy where flat vectors are written in the first phase and additional indexing structures (like HNSW graphs) are built in the second phase using the already-written flat vector data.
- Overrides:
mergeOneFieldin classKnnVectorsWriter- Parameters:
fieldInfo- the field to mergemergeState- the merge state- Returns:
- a runnable to execute in phase 2, or
nullif there is no deferred work - Throws:
IOException- if an I/O error occurs
-
mergeOneFlatVectorField
public abstract void mergeOneFlatVectorField(FieldInfo fieldInfo, MergeState mergeState) throws IOException - Throws:
IOException
-
mergeOneFlatVectorFieldForMergeScorer
public FlatVectorsWriter.MergeScorerData mergeOneFlatVectorFieldForMergeScorer(FieldInfo fieldInfo, MergeState mergeState, IntPredicate needsMergeScorer) throws IOException Merges one field and, while writing the merged vectors, optionally prepares what a merge scorer needs, so that the merged float vectors need not be read back.A wrapping writer should forward this method along with
mergeOneFlatVectorField(org.apache.lucene.index.FieldInfo, org.apache.lucene.index.MergeState). Forwarding only the latter stays correct, but the wrapped writer then prepares nothing. Forwarding helps only when the wrapping format's reader over the merged segment is the wrapped writer's own reader. OtherwiseFlatVectorsWriter.MergeScorerData.scorerSupplier(org.apache.lucene.codecs.hnsw.FlatVectorsReader)rejects the prepared data and the merge uses its fallback.- Parameters:
fieldInfo- field to mergemergeState- merge stateneedsMergeScorer- whether to prepare scorer data for a vector count. The writer applies this predicate to the number of live vectors written after deletions, so it does not prepare data for a merged field that is too small to build a graph.- Returns:
- prepared data that the caller must close, or
nullif none was prepared, which is what the default implementation returns and what any writer returns for a field it cannot prepare for. The caller then builds the scorer itself. - Throws:
IOException- if an I/O error occurs
-