Enum Class MilvusMetric

java.lang.Object
java.lang.Enum<MilvusMetric>
org.eclipse.jnosql.databases.milvus.communication.MilvusMetric
All Implemented Interfaces:
Serializable, Comparable<MilvusMetric>, Constable

public enum MilvusMetric extends Enum<MilvusMetric>
Defines the metrics supported by the Milvus vector index.

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.

  • Enum Constant Details

    • COSINE

      public static final MilvusMetric COSINE
      Cosine similarity, from -1 (opposite) to 1 (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

      public static final MilvusMetric 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

      public static final MilvusMetric 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

      public static MilvusMetric[] 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 MilvusMetric 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
    • parse

      public static MilvusMetric parse(String value)
      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 null
      IllegalArgumentException - when the value is not a supported metric