Class KnnFloatVectorField

  • All Implemented Interfaces:
    IndexableField
    Direct Known Subclasses:
    KnnVectorField

    public class KnnFloatVectorField
    extends Field
    A field that contains a single floating-point numeric vector (or none) for each document. Vectors are dense - that is, every dimension of a vector contains an explicit value, stored packed into an array (of type float[]) whose length is the vector dimension. Values can be retrieved using FloatVectorValues, which is a forward-only docID-based iterator and also offers random-access by dense ordinal (not docId). VectorSimilarityFunction may be used to compare vectors at query time (for example as part of result ranking). A KnnFloatVectorField may be associated with a search similarity function defining the metric used for nearest-neighbor search among vectors of that field.
    WARNING: This API is experimental and might change in incompatible ways in the next release.
    • Constructor Detail

      • KnnFloatVectorField

        public KnnFloatVectorField​(String name,
                                   float[] vector,
                                   VectorSimilarityFunction similarityFunction)
        Creates a numeric vector field. Fields are single-valued: each document has either one value or no value. Vectors of a single field share the same dimension and similarity function. Note that some vector similarities (like VectorSimilarityFunction.DOT_PRODUCT) require values to be unit-length, which can be enforced using VectorUtil.l2normalize(float[]).
        Parameters:
        name - field name
        vector - value
        similarityFunction - a function defining vector proximity.
        Throws:
        IllegalArgumentException - if any parameter is null, or the vector is empty or has dimension > 1024.
      • KnnFloatVectorField

        public KnnFloatVectorField​(String name,
                                   float[] vector)
        Creates a numeric vector field with the default EUCLIDEAN_HNSW (L2) similarity. Fields are single-valued: each document has either one value or no value. Vectors of a single field share the same dimension and similarity function.
        Parameters:
        name - field name
        vector - value
        Throws:
        IllegalArgumentException - if any parameter is null, or the vector is empty or has dimension > 1024.
      • KnnFloatVectorField

        public KnnFloatVectorField​(String name,
                                   float[] vector,
                                   FieldType fieldType)
        Creates a numeric vector field. Fields are single-valued: each document has either one value or no value. Vectors of a single field share the same dimension and similarity function.
        Parameters:
        name - field name
        vector - value
        fieldType - field type
        Throws:
        IllegalArgumentException - if any parameter is null, or the vector is empty or has dimension > 1024.
    • Method Detail

      • createFieldType

        public static FieldType createFieldType​(int dimension,
                                                VectorSimilarityFunction similarityFunction)
        A convenience method for creating a vector field type.
        Parameters:
        dimension - dimension of vectors
        similarityFunction - a function defining vector proximity.
        Throws:
        IllegalArgumentException - if any parameter is null, or has dimension > 1024.
      • newVectorQuery

        public static Query newVectorQuery​(String field,
                                           float[] queryVector,
                                           int k)
        Create a new vector query for the provided field targeting the float vector
        Parameters:
        field - The field to query
        queryVector - The float vector target
        k - The number of nearest neighbors to gather
        Returns:
        A new vector query
      • vectorValue

        public float[] vectorValue()
        Return the vector value of this field
      • setVectorValue

        public void setVectorValue​(float[] value)
        Set the vector value of this field
        Parameters:
        value - the value to set; must not be null, and length must match the field type