Enum Class VectorDistanceType

java.lang.Object
java.lang.Enum<VectorDistanceType>
io.objectbox.annotation.VectorDistanceType
All Implemented Interfaces:
Serializable, Comparable<VectorDistanceType>, Constable

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

    • DEFAULT

      public static final VectorDistanceType DEFAULT
      The default; currently EUCLIDEAN.
    • 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)

  • Method Details

    • values

      public static VectorDistanceType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static VectorDistanceType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null