Enum VectorSimilarity

java.lang.Object
java.lang.Enum<VectorSimilarity>
org.hibernate.search.engine.backend.types.VectorSimilarity
All Implemented Interfaces:
Serializable, Comparable<VectorSimilarity>

@Incubating public enum VectorSimilarity extends Enum<VectorSimilarity>
Defines a function to calculate the vector similarity, i.e. distance between two vectors.

Note, some backends or their distributions may not support all of available similarity options.

  • Enum Constant Details

    • DEFAULT

      public static final VectorSimilarity DEFAULT
      Use the backend-specific default.
    • L2

      public static final VectorSimilarity L2
      L2 (Euclidean) norm. Distance is calculated as d(x,y) = \sum_(i=1) ^(n) (x_i - y_i)^2 and similarity function is s = 1 / (1+d)
    • DOT_PRODUCT

      public static final VectorSimilarity DOT_PRODUCT
      Inner product (dot product in particular). Distance is calculated as d(x,y) = \sum_(i=1) ^(n) x_i*y_i , similarity function is s = 1 / (1+d) , but may differ between backends.

      WARNING:: to use this similarity efficiently, both index and search vectors must be normalized, otherwise search may produce poor results. Floating point vectors must be normalized to be of unit length, while byte vectors should simply all have the same norm.

    • COSINE

      public static final VectorSimilarity COSINE
      Cosine similarity. Distance is calculated as d(x,y) = 1 - \sum_(i=1) ^(n) x_i*y_i / ( \sqrt( \sum_(i=1) ^(n) x_i^2 ) \sqrt( \sum_(i=1) ^(n) y_i^2 ) , similarity function is s = 1 / (1+d) , but may differ between backends.
    • MAX_INNER_PRODUCT

      public static final VectorSimilarity MAX_INNER_PRODUCT
      Similar to DOT_PRODUCT but does not require vector normalization. Distance is calculated as d(x,y) = \sum_(i=1) ^(n) (x_i - y_i)^2 and similarity function is d < 0 ? s = 1 / (1 - d) : s = d + 1
  • Method Details

    • values

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

      public static VectorSimilarity valueOf(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:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null