Enum VectorSimilarity
- All Implemented Interfaces:
Serializable
,Comparable<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 Summary
Enum ConstantsEnum ConstantDescriptionCosine similarity.Use the backend-specific default.Inner product (dot product in particular).L2 (Euclidean) norm.Similar toDOT_PRODUCT
but does not require vector normalization. -
Method Summary
Modifier and TypeMethodDescriptionstatic VectorSimilarity
Returns the enum constant of this type with the specified name.static VectorSimilarity[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
DEFAULT
Use the backend-specific default. -
L2
L2 (Euclidean) norm. Distance is calculated asd(x,y) = \sum_(i=1) ^(n) (x_i - y_i)^2
and similarity function iss = 1 / (1+d)
-
DOT_PRODUCT
Inner product (dot product in particular). Distance is calculated asd(x,y) = \sum_(i=1) ^(n) x_i*y_i
, similarity function iss = 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
Cosine similarity. Distance is calculated asd(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 iss = 1 / (1+d)
, but may differ between backends. -
MAX_INNER_PRODUCT
Similar toDOT_PRODUCT
but does not require vector normalization. Distance is calculated asd(x,y) = \sum_(i=1) ^(n) (x_i - y_i)^2
and similarity function isd < 0 ? s = 1 / (1 - d) : s = d + 1
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-