Enum Class MilvusMetric
- All Implemented Interfaces:
Serializable,Comparable<MilvusMetric>,Constable
The metric determines how Milvus compares stored vectors with a query vector.
It belongs to the collection index configuration, so it is chosen when the collection is created
(MilvusConfigurations.METRIC) and it is not selected per search operation.
query vector
|
v
configured metric
|
v
stored vectors
|
v
nearest matches
The search threshold follows the metric: with COSINE and INNER_PRODUCT it is the
minimum similarity a result must exceed, and with EUCLIDEAN it is the maximum distance a result
must stay under.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionCosine similarity, from-1(opposite) to1(same direction).Euclidean (L2) distance, the straight-line distance between two points.Inner (dot) product, which grows with both the alignment and the magnitude of the vectors. -
Method Summary
Modifier and TypeMethodDescriptionstatic MilvusMetricParses a metric by its name or its Milvus name (L2,IP), ignoring the case.static MilvusMetricReturns the enum constant of this class with the specified name.static MilvusMetric[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
COSINE
Cosine similarity, from-1(opposite) to1(same direction).It compares the direction of the vectors and ignores their magnitude. It suits embeddings where the pattern matters more than the amount: a user who rated three movies 10, 2 and 1 is close to a user who rated them 5, 1 and 0.5, because both prefer the same movie.
cos(a, b) = (a ยท b) / (|a| * |b|)Higher scores are more similar.
-
EUCLIDEAN
Euclidean (L2) distance, the straight-line distance between two points.It compares the absolute position of the vectors, so magnitude matters: two products with the same attributes but very different prices are far from each other.
l2(a, b) = sqrt(sum((a[i] - b[i])^2))Lower distances are more similar. It is also accepted as
L2. -
INNER_PRODUCT
Inner (dot) product, which grows with both the alignment and the magnitude of the vectors.It suits embeddings where a stronger signal means a stronger match, such as vectors already normalized by the model or recommendation scores that encode relevance in their length.
ip(a, b) = sum(a[i] * b[i])Higher scores are more similar. It is also accepted as
IP.
-
-
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
-
parse
Parses a metric by its name or its Milvus name (L2,IP), ignoring the case.- Parameters:
value- the metric name- Returns:
- the metric
- Throws:
NullPointerException- when the value is nullIllegalArgumentException- when the value is not a supported metric
-