Class DenseVectorField
-
- All Implemented Interfaces:
FloatValueFieldType,NumericValueFieldType
public class DenseVectorField extends FloatPointField
Provides a field type to support Lucene'sKnnVectorField. SeeKnnVectorQueryfor more details. It supports a fixed cardinality dimension for the vector and a fixed similarity function. The default similarity is EUCLIDEAN_HNSW (L2). The default algorithm is HNSW. For Lucene 9.1 e.g. SeeHnswGraphfor more details about the implementation.
OnlyIndexedandStoredattributes are supported.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.solr.schema.FieldType
FieldType.DefaultAnalyzer, FieldType.MultiValueSelector
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_KNN_ALGORITHMstatic StringHNSW_ALGORITHM-
Fields inherited from class org.apache.solr.schema.PointField
TEST_HACK_IGNORE_USELESS_TRIEFIELD_ARGS
-
Fields inherited from class org.apache.solr.schema.NumericFieldType
doubleOrFloat, type
-
Fields inherited from class org.apache.solr.schema.FieldType
ANALYZER, args, AUTO_GENERATE_PHRASE_QUERIES, CHAR_FILTER, CHAR_FILTERS, CLASS_NAME, docValuesFormat, ENABLE_GRAPH_QUERIES, falseProperties, FILTER, FILTERS, INDEX, INDEX_ANALYZER, MULTI_TERM, MULTI_TERM_ANALYZER, POLY_FIELD_SEPARATOR, postingsFormat, properties, QUERY, QUERY_ANALYZER, similarity, SIMILARITY, similarityFactory, SYNONYM_QUERY_STYLE, TOKENIZER, trueProperties, TYPE, TYPE_NAME, typeName
-
Fields inherited from class org.apache.solr.schema.FieldProperties
BINARY, DOC_VALUES, INDEXED, LARGE_FIELD, MULTIVALUED, OMIT_NORMS, OMIT_POSITIONS, OMIT_TF_POSITIONS, REQUIRED, SORT_MISSING_FIRST, SORT_MISSING_LAST, STORE_OFFSETS, STORE_TERMOFFSETS, STORE_TERMPAYLOADS, STORE_TERMPOSITIONS, STORE_TERMVECTORS, STORED, TOKENIZED, UNINVERTIBLE, USE_DOCVALUES_AS_STORED
-
-
Constructor Summary
Constructors Constructor Description DenseVectorField()DenseVectorField(int dimension)DenseVectorField(int dimension, org.apache.lucene.index.VectorSimilarityFunction similarityFunction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckSchemaField(SchemaField field)Check'sSchemaFieldinstances constructed using this field type to ensure that they are valid.org.apache.lucene.index.IndexableFieldcreateField(SchemaField field, Object parsedVector)Used for adding a document when a field needs to be created from a type and a string.List<org.apache.lucene.index.IndexableField>createFields(SchemaField field, Object value)Given aSchemaField, create one or moreIndexableFieldinstancesintgetDimension()org.apache.lucene.search.QuerygetFieldQuery(QParser parser, SchemaField field, String externalVal)Not Supported.IntegergetHnswBeamWidth()IntegergetHnswMaxConn()StringgetKnnAlgorithm()org.apache.lucene.search.QuerygetKnnVectorQuery(String fieldName, float[] vectorToSearch, int topK, org.apache.lucene.search.Query filterQuery)org.apache.lucene.search.QuerygetRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive)Not Supportedorg.apache.lucene.index.VectorSimilarityFunctiongetSimilarityFunction()org.apache.lucene.search.SortFieldgetSortField(SchemaField field, boolean top)Not SupportedUninvertingReader.TypegetUninversionType(SchemaField sf)If DocValues is not enabled for a field, but it's indexed, docvalues can be constructed on the fly (uninverted, aka fieldcache) on the first request to sort, facet, etc.org.apache.lucene.queries.function.ValueSourcegetValueSource(SchemaField field, QParser parser)called to get the default value source (normally, from the Lucene FieldCache.)voidinit(IndexSchema schema, Map<String,String> args)NOTE: This method can be removed completely whenPointField.TEST_HACK_IGNORE_USELESS_TRIEFIELD_ARGSis removed-
Methods inherited from class org.apache.solr.schema.FloatPointField
getExactQuery, getPointRangeQuery, getSetQuery, getSingleValueSource, getStoredField, indexedToReadable, readableToIndexed, toNativeType, toObject, toObject
-
Methods inherited from class org.apache.solr.schema.PointField
getPrefixQuery, getSingleValueSource, getSpecializedRangeQuery, indexedToReadable, indexedToReadable, isFieldUsed, isPointField, isTokenized, multiValuedFieldCache, storedToIndexed, storedToReadable, toInternal, toInternalByteRef, write
-
Methods inherited from class org.apache.solr.schema.NumericFieldType
getDocValuesRangeQuery, getNumberType, getRangeQueryForFloatDoubleDocValues, getRangeQueryForMultiValuedDoubleDocValues, getRangeQueryForMultiValuedFloatDocValues, getSpecializedExistenceQuery, numericDocValuesRangeQuery, treatUnboundedRangeAsExistence
-
Methods inherited from class org.apache.solr.schema.PrimitiveFieldType
checkSupportsDocValues, getDefaultMultiValueSelectorForSort
-
Methods inherited from class org.apache.solr.schema.FieldType
createField, getAnalyzerProperties, getClassArg, getDocValuesFormat, getExistenceQuery, getFieldTermQuery, getIndexAnalyzer, getNamedPropertyValues, getNonFieldPropertyArgs, getNumericSort, getPostingsFormat, getQueryAnalyzer, getRewriteMethod, getSimilarity, getSimilarityFactory, getSortedNumericSortField, getSortedSetSortField, getSortField, getStringSort, getTypeName, hasProperty, isExplicitAnalyzer, isExplicitQueryAnalyzer, isMultiValued, isPolyField, isUtf8Field, marshalBase64SortValue, marshalSortValue, marshalStringSortValue, readableToIndexed, restrictProps, setArgs, setIndexAnalyzer, setIsExplicitAnalyzer, setIsExplicitQueryAnalyzer, setQueryAnalyzer, setSimilarity, supportsAnalyzers, toExternal, toString, unmarshalBase64SortValue, unmarshalSortValue, unmarshalStringSortValue, useDocValuesAsStored, write
-
-
-
-
Field Detail
-
HNSW_ALGORITHM
public static final String HNSW_ALGORITHM
- See Also:
- Constant Field Values
-
DEFAULT_KNN_ALGORITHM
public static final String DEFAULT_KNN_ALGORITHM
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(IndexSchema schema, Map<String,String> args)
Description copied from class:PointFieldNOTE: This method can be removed completely whenPointField.TEST_HACK_IGNORE_USELESS_TRIEFIELD_ARGSis removed- Overrides:
initin classPointField
-
getDimension
public int getDimension()
-
getSimilarityFunction
public org.apache.lucene.index.VectorSimilarityFunction getSimilarityFunction()
-
getKnnAlgorithm
public String getKnnAlgorithm()
-
getHnswMaxConn
public Integer getHnswMaxConn()
-
getHnswBeamWidth
public Integer getHnswBeamWidth()
-
checkSchemaField
public void checkSchemaField(SchemaField field) throws org.apache.solr.common.SolrException
Description copied from class:FieldTypeCheck'sSchemaFieldinstances constructed using this field type to ensure that they are valid.This method is called by the
SchemaFieldconstructor to check that its initialization does not violate any fundamental requirements of theFieldType. Subclasses may choose to throw aSolrExceptionif invariants are violated by theSchemaField.- Overrides:
checkSchemaFieldin classFieldType- Throws:
org.apache.solr.common.SolrException
-
createFields
public List<org.apache.lucene.index.IndexableField> createFields(SchemaField field, Object value)
Description copied from class:FieldTypeGiven aSchemaField, create one or moreIndexableFieldinstances- Overrides:
createFieldsin classPointField- Parameters:
field- theSchemaFieldvalue- The value to add to the field- Returns:
- An array of
IndexableField - See Also:
FieldType.createField(SchemaField, Object),FieldType.isPolyField()
-
createField
public org.apache.lucene.index.IndexableField createField(SchemaField field, Object parsedVector)
Description copied from class:FieldTypeUsed for adding a document when a field needs to be created from a type and a string.By default, the indexed value is the same as the stored value (taken from toInternal()). Having a different representation for external, internal, and indexed would present quite a few problems given the current Lucene architecture. An analyzer for adding docs would need to translate internal->indexed while an analyzer for querying would need to translate external->indexed.
The only other alternative to having internal==indexed would be to have internal==external. In this case, toInternal should convert to the indexed representation, toExternal() should do nothing, and createField() should *not* call toInternal, but use the external value and set tokenized=true to get Lucene to convert to the internal(indexed) form. :TODO: clean up and clarify this explanation.
- Overrides:
createFieldin classFloatPointField- See Also:
FieldType.toInternal(java.lang.String)
-
getUninversionType
public UninvertingReader.Type getUninversionType(SchemaField sf)
Description copied from class:FieldTypeIf DocValues is not enabled for a field, but it's indexed, docvalues can be constructed on the fly (uninverted, aka fieldcache) on the first request to sort, facet, etc. This specifies the structure to use.This method will not be used if the field is (effectively)
uninvertible="false"- Overrides:
getUninversionTypein classFloatPointField- Parameters:
sf- field instance- Returns:
- type to uninvert, or
null(to disallow uninversion for the field) - See Also:
SchemaField.isUninvertible()
-
getValueSource
public org.apache.lucene.queries.function.ValueSource getValueSource(SchemaField field, QParser parser)
Description copied from class:FieldTypecalled to get the default value source (normally, from the Lucene FieldCache.)- Overrides:
getValueSourcein classFloatPointField
-
getKnnVectorQuery
public org.apache.lucene.search.Query getKnnVectorQuery(String fieldName, float[] vectorToSearch, int topK, org.apache.lucene.search.Query filterQuery)
-
getFieldQuery
public org.apache.lucene.search.Query getFieldQuery(QParser parser, SchemaField field, String externalVal)
Not Supported. Please use the {!knn} query parser to run K nearest neighbors search queries.- Overrides:
getFieldQueryin classPointField- Parameters:
parser- TheQParsercalling the methodfield- TheSchemaFieldof the field to searchexternalVal- The String representation of the value to search- Returns:
- The
Queryinstance. This implementation returns aTermQuerybut overriding queries may not
-
getRangeQuery
public org.apache.lucene.search.Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive)
Not Supported- Overrides:
getRangeQueryin classFieldType- Parameters:
parser- theQParsercalling the methodfield- the schema fieldpart1- the lower boundary of the range, nulls are allowed.part2- the upper boundary of the range, nulls are alloweminInclusive- whether the minimum of the range is inclusive or notmaxInclusive- whether the maximum of the range is inclusive or not- Returns:
- a Query instance to perform range search according to given parameters
-
getSortField
public org.apache.lucene.search.SortField getSortField(SchemaField field, boolean top)
Not Supported
-
-