Class DenseVectorField

  • All Implemented Interfaces:
    FloatValueFieldType, NumericValueFieldType

    public class DenseVectorField
    extends FloatPointField
    Provides a field type to support Lucene's KnnVectorField. See KnnVectorQuery for 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 index codec format is specified in the Lucene Codec constructor. For Lucene 9.0 e.g. See Lucene90Codec Currently only Lucene90HnswVectorsFormat is supported for advanced hyper-parameter customisation. See HnswGraph for more details about the implementation.
    Only Indexed and Stored attributes are supported.
    • Constructor Detail

      • DenseVectorField

        public DenseVectorField()
      • DenseVectorField

        public DenseVectorField​(int dimension)
      • DenseVectorField

        public DenseVectorField​(int dimension,
                                org.apache.lucene.index.VectorSimilarityFunction similarityFunction)
    • Method Detail

      • getDimension

        public int getDimension()
      • getSimilarityFunction

        public org.apache.lucene.index.VectorSimilarityFunction getSimilarityFunction()
      • getCodecFormat

        public String getCodecFormat()
      • getHnswMaxConn

        public Integer getHnswMaxConn()
      • getHnswBeamWidth

        public Integer getHnswBeamWidth()
      • checkSchemaField

        public void checkSchemaField​(SchemaField field)
                              throws SolrException
        Description copied from class: FieldType
        Check's SchemaField instances constructed using this field type to ensure that they are valid.

        This method is called by the SchemaField constructor to check that its initialization does not violate any fundamental requirements of the FieldType. Subclasses may choose to throw a SolrException if invariants are violated by the SchemaField.

        Overrides:
        checkSchemaField in class FieldType
        Throws:
        SolrException
      • createField

        public org.apache.lucene.index.IndexableField createField​(SchemaField field,
                                                                  Object parsedVector)
        Description copied from class: FieldType
        Used 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:
        createField in class FloatPointField
        See Also:
        FieldType.toInternal(java.lang.String)
      • getUninversionType

        public UninvertingReader.Type getUninversionType​(SchemaField sf)
        Description copied from class: FieldType
        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. This specifies the structure to use.

        This method will not be used if the field is (effectively) uninvertible="false"

        Overrides:
        getUninversionType in class FloatPointField
        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: FieldType
        called to get the default value source (normally, from the Lucene FieldCache.)
        Overrides:
        getValueSource in class FloatPointField
      • getKnnVectorQuery

        public org.apache.lucene.search.Query getKnnVectorQuery​(String fieldName,
                                                                float[] vectorToSearch,
                                                                int topK)
      • 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:
        getFieldQuery in class PointField
        Parameters:
        parser - The QParser calling the method
        field - The SchemaField of the field to search
        externalVal - The String representation of the value to search
        Returns:
        The Query instance. This implementation returns a TermQuery but 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:
        getRangeQuery in class FieldType
        Parameters:
        parser - the QParser calling the method
        field - the schema field
        part1 - the lower boundary of the range, nulls are allowed.
        part2 - the upper boundary of the range, nulls are allowe
        minInclusive - whether the minimum of the range is inclusive or not
        maxInclusive - whether the maximum of the range is inclusive or not
        Returns:
        a Query instance to perform range search according to given parameters