Module org.apache.lucene.core
Class PerFieldKnnVectorsFormat
- java.lang.Object
-
- org.apache.lucene.codecs.KnnVectorsFormat
-
- org.apache.lucene.codecs.perfield.PerFieldKnnVectorsFormat
-
- All Implemented Interfaces:
NamedSPILoader.NamedSPI
public abstract class PerFieldKnnVectorsFormat extends KnnVectorsFormat
Enables per field numeric vector support.Note, when extending this class, the name (
KnnVectorsFormat.getName()
) is written into the index. In order for the field to be read, the name must resolve to your implementation viaKnnVectorsFormat.forName(String)
. This method uses Java'sService Provider Interface
to resolve format names.Files written by each numeric vectors format have an additional suffix containing the format name. For example, in a per-field configuration instead of
_1.dat
filenames would look like_1_Lucene40_0.dat
.- See Also:
ServiceLoader
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PerFieldKnnVectorsFormat.FieldsReader
VectorReader that can wrap multiple delegate readers, selected by field.private class
PerFieldKnnVectorsFormat.FieldsWriter
private static class
PerFieldKnnVectorsFormat.WriterAndSuffix
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PER_FIELD_FORMAT_KEY
FieldInfo
attribute name used to store the format name for each field.static java.lang.String
PER_FIELD_NAME
Name of thisKnnVectorsFormat
.static java.lang.String
PER_FIELD_SUFFIX_KEY
FieldInfo
attribute name used to store the segment suffix name for each field.-
Fields inherited from class org.apache.lucene.codecs.KnnVectorsFormat
DEFAULT_MAX_DIMENSIONS, EMPTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PerFieldKnnVectorsFormat()
Sole constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description KnnVectorsReader
fieldsReader(SegmentReadState state)
Returns aKnnVectorsReader
to read the vectors from the index.KnnVectorsWriter
fieldsWriter(SegmentWriteState state)
Returns aKnnVectorsWriter
to write the vectors to the index.(package private) static java.lang.String
getFullSegmentSuffix(java.lang.String outerSegmentSuffix, java.lang.String segmentSuffix)
abstract KnnVectorsFormat
getKnnVectorsFormatForField(java.lang.String field)
Returns the numeric vector format that should be used for writing new segments offield
.int
getMaxDimensions(java.lang.String fieldName)
Returns the maximum number of vector dimensions supported by this codec for the given field name(package private) static java.lang.String
getSuffix(java.lang.String formatName, java.lang.String suffix)
-
Methods inherited from class org.apache.lucene.codecs.KnnVectorsFormat
availableKnnVectorsFormats, forName, getName, reloadKnnVectorsFormat
-
-
-
-
Field Detail
-
PER_FIELD_NAME
public static final java.lang.String PER_FIELD_NAME
Name of thisKnnVectorsFormat
.- See Also:
- Constant Field Values
-
PER_FIELD_FORMAT_KEY
public static final java.lang.String PER_FIELD_FORMAT_KEY
FieldInfo
attribute name used to store the format name for each field.
-
PER_FIELD_SUFFIX_KEY
public static final java.lang.String PER_FIELD_SUFFIX_KEY
FieldInfo
attribute name used to store the segment suffix name for each field.
-
-
Method Detail
-
fieldsWriter
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws java.io.IOException
Description copied from class:KnnVectorsFormat
Returns aKnnVectorsWriter
to write the vectors to the index.- Specified by:
fieldsWriter
in classKnnVectorsFormat
- Throws:
java.io.IOException
-
fieldsReader
public KnnVectorsReader fieldsReader(SegmentReadState state) throws java.io.IOException
Description copied from class:KnnVectorsFormat
Returns aKnnVectorsReader
to read the vectors from the index.- Specified by:
fieldsReader
in classKnnVectorsFormat
- Throws:
java.io.IOException
-
getMaxDimensions
public int getMaxDimensions(java.lang.String fieldName)
Description copied from class:KnnVectorsFormat
Returns 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:
getMaxDimensions
in classKnnVectorsFormat
- Parameters:
fieldName
- the field name- Returns:
- the maximum number of vector dimensions.
-
getKnnVectorsFormatForField
public abstract KnnVectorsFormat getKnnVectorsFormatForField(java.lang.String field)
Returns the numeric vector format that should be used for writing new segments offield
.The field to format mapping is written to the index, so this method is only invoked when writing, not when reading.
-
getSuffix
static java.lang.String getSuffix(java.lang.String formatName, java.lang.String suffix)
-
getFullSegmentSuffix
static java.lang.String getFullSegmentSuffix(java.lang.String outerSegmentSuffix, java.lang.String segmentSuffix)
-
-