Enum Class DenseVectorSimilarity

java.lang.Object
java.lang.Enum<DenseVectorSimilarity>
co.elastic.clients.elasticsearch._types.mapping.DenseVectorSimilarity
All Implemented Interfaces:
JsonEnum, JsonpSerializable, Serializable, Comparable<DenseVectorSimilarity>, Constable

@JsonpDeserializable public enum DenseVectorSimilarity extends Enum<DenseVectorSimilarity> implements JsonEnum
See Also:
  • Enum Constant Details

    • Cosine

      public static final DenseVectorSimilarity Cosine
      Computes the cosine similarity. During indexing Elasticsearch automatically normalizes vectors with cosine similarity to unit length. This allows to internally use dot_product for computing similarity, which is more efficient. Original un-normalized vectors can be still accessed through scripts.

      The document _score is computed as (1 + cosine(query, vector)) / 2.

      The cosine similarity does not allow vectors with zero magnitude, since cosine is not defined in this case.

    • DotProduct

      public static final DenseVectorSimilarity DotProduct
      Computes the dot product of two unit vectors. This option provides an optimized way to perform cosine similarity. The constraints and computed score are defined by element_type.

      When element_type is float, all vectors must be unit length, including both document and query vectors.

      The document _score is computed as (1 + dot_product(query, vector)) / 2.

      When element_type is byte, all vectors must have the same length including both document and query vectors or results will be inaccurate.

      The document _score is computed as 0.5 + (dot_product(query, vector) / (32768 * dims)) where dims is the number of dimensions per vector.

    • L2Norm

      public static final DenseVectorSimilarity L2Norm
      Computes similarity based on the L2 distance (also known as Euclidean distance) between the vectors.

      The document _score is computed as 1 / (1 + l2_norm(query, vector)^2).

      For bit vectors, instead of using l2_norm, the hamming distance between the vectors is used.

      The _score transformation is (numBits - hamming(a, b)) / numBits.

    • MaxInnerProduct

      public static final DenseVectorSimilarity MaxInnerProduct
      Computes the maximum inner product of two vectors. This is similar to dot_product, but doesn't require vectors to be normalized. This means that each vector’s magnitude can significantly effect the score.

      The document _score is adjusted to prevent negative values. For max_inner_product values < 0, the _score is 1 / (1 + -1 * max_inner_product(query, vector)). For non-negative max_inner_product results the _score is calculated max_inner_product(query, vector) + 1.

  • Field Details

  • Method Details

    • values

      public static DenseVectorSimilarity[] 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 DenseVectorSimilarity 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
    • jsonValue

      public String jsonValue()
      Specified by:
      jsonValue in interface JsonEnum