Enum Class DenseVectorSimilarity
- All Implemented Interfaces:
JsonEnum,JsonpSerializable,Serializable,Comparable<DenseVectorSimilarity>,Constable
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>Nested classes/interfaces inherited from interface co.elastic.clients.json.JsonEnum
JsonEnum.Deserializer<T extends JsonEnum> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionComputes the cosine similarity.Computes the dot product of two unit vectors.Computes similarity based on theL2distance (also known as Euclidean distance) between the vectors.Computes the maximum inner product of two vectors. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic DenseVectorSimilarityReturns the enum constant of this class with the specified name.static DenseVectorSimilarity[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
Cosine
Computes the cosine similarity. During indexing Elasticsearch automatically normalizes vectors withcosinesimilarity to unit length. This allows to internally usedot_productfor computing similarity, which is more efficient. Original un-normalized vectors can be still accessed through scripts.The document
_scoreis computed as(1 + cosine(query, vector)) / 2.The
cosinesimilarity does not allow vectors with zero magnitude, since cosine is not defined in this case. -
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 byelement_type.When
element_typeisfloat, all vectors must be unit length, including both document and query vectors.The document
_scoreis computed as(1 + dot_product(query, vector)) / 2.When
element_typeisbyte, all vectors must have the same length including both document and query vectors or results will be inaccurate.The document
_scoreis computed as0.5 + (dot_product(query, vector) / (32768 * dims))wheredimsis the number of dimensions per vector. -
L2Norm
Computes similarity based on theL2distance (also known as Euclidean distance) between the vectors.The document
_scoreis computed as1 / (1 + l2_norm(query, vector)^2).For
bitvectors, instead of usingl2_norm, thehammingdistance between the vectors is used.The
_scoretransformation is(numBits - hamming(a, b)) / numBits. -
MaxInnerProduct
Computes the maximum inner product of two vectors. This is similar todot_product, but doesn't require vectors to be normalized. This means that each vector’s magnitude can significantly effect the score.The document
_scoreis adjusted to prevent negative values. Formax_inner_productvalues< 0, the_scoreis1 / (1 + -1 * max_inner_product(query, vector)). For non-negativemax_inner_productresults the_scoreis calculatedmax_inner_product(query, vector) + 1.
-
-
Field Details
-
_DESERIALIZER
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
jsonValue
-