Enum VectorDistanceType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<VectorDistanceType>

    public enum VectorDistanceType
    extends java.lang.Enum<VectorDistanceType>
    The vector distance algorithm used by an HnswIndex (vector search).
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      COSINE
      Cosine similarity compares two vectors irrespective of their magnitude (compares the angle of two vectors).
      DEFAULT
      The default; currently EUCLIDEAN.
      DOT_PRODUCT
      For normalized vectors (vector length == 1.0), the dot product is equivalent to the cosine similarity.
      DOT_PRODUCT_NON_NORMALIZED
      A custom dot product similarity measure that does not require the vectors to be normalized.
      EUCLIDEAN
      Typically "Euclidean squared" internally.
      GEO
      For geospatial coordinates, more specifically latitude and longitude pairs.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private VectorDistanceType()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static VectorDistanceType valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static VectorDistanceType[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • EUCLIDEAN

        public static final VectorDistanceType EUCLIDEAN
        Typically "Euclidean squared" internally.
      • COSINE

        public static final VectorDistanceType COSINE
        Cosine similarity compares two vectors irrespective of their magnitude (compares the angle of two vectors).

        Often used for document or semantic similarity.

        Value range: 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)

      • DOT_PRODUCT

        public static final VectorDistanceType DOT_PRODUCT
        For normalized vectors (vector length == 1.0), the dot product is equivalent to the cosine similarity.

        Because of this, the dot product is often preferred as it performs better.

        Value range (normalized vectors): 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)

      • GEO

        public static final VectorDistanceType GEO
        For geospatial coordinates, more specifically latitude and longitude pairs.

        Note, the vector dimension should be 2, with the latitude being the first element and longitude the second. If the vector has more than 2 dimensions, only the first 2 dimensions are used. If the vector has fewer than 2 dimensions, the distance is always zero.

        Internally, this uses haversine distance.

        Value range: 0 km - 6371 * π km (approx. 20015.09 km; half the Earth's circumference)

      • DOT_PRODUCT_NON_NORMALIZED

        public static final VectorDistanceType DOT_PRODUCT_NON_NORMALIZED
        A custom dot product similarity measure that does not require the vectors to be normalized.

        Note: this is no replacement for cosine similarity (like DotProduct for normalized vectors is). The non-linear conversion provides a high precision over the entire float range (for the raw dot product). The higher the dot product, the lower the distance is (the nearer the vectors are). The more negative the dot product, the higher the distance is (the farther the vectors are).

        Value range: 0.0 - 2.0 (nonlinear; 0.0: nearest, 1.0: orthogonal, 2.0: farthest)

    • Constructor Detail

      • VectorDistanceType

        private VectorDistanceType()
    • Method Detail

      • values

        public static VectorDistanceType[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (VectorDistanceType c : VectorDistanceType.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static VectorDistanceType valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null