Enum Class WeaviateDistance

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

public enum WeaviateDistance extends Enum<WeaviateDistance>
Defines the distances supported by the Weaviate vector index.

The distance determines how Weaviate compares stored vectors with a query vector. It belongs to the collection vector index configuration, so it is chosen when the collection is created (WeaviateConfigurations.DISTANCE) and it is not selected per search operation.

 query vector
      |
      v
 configured distance
      |
      v
 stored vectors
      |
      v
 nearest matches
 

The search threshold of the JNoSQL vector API keeps the same meaning for every distance: with COSINE and DOT it is the minimum similarity a result must have, and with EUCLIDEAN, MANHATTAN and HAMMING it is the maximum distance a result may have.

  • Enum Constant Details

    • COSINE

      public static final WeaviateDistance COSINE
      Cosine similarity, from -1 (opposite) to 1 (same direction).

      It compares the direction of the vectors and ignores their magnitude. It suits text embeddings, where two sentences about the same topic point in the same direction even if one of them is much longer.

      
       cos(a, b) = (a ยท b) / (|a| * |b|)
       

      Higher similarities are more similar.

    • DOT

      public static final WeaviateDistance DOT
      Dot (inner) product, which grows with both the alignment and the magnitude of the vectors.

      It suits embeddings that are already normalized by the model, or recommendation scores where a longer vector means a stronger match.

      
       dot(a, b) = sum(a[i] * b[i])
       

      Higher products are more similar.

    • EUCLIDEAN

      public static final WeaviateDistance 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))
       

      Weaviate stores the squared distance (l2-squared), which ranks results the same way and avoids the square root. Lower distances are more similar. It is also accepted as L2_SQUARED.

    • MANHATTAN

      public static final WeaviateDistance MANHATTAN
      Manhattan (L1) distance, the sum of the absolute differences of each dimension.

      It is the distance of walking a city grid, and it is less sensitive than EUCLIDEAN to a single dimension that differs a lot.

      
       l1(a, b) = sum(|a[i] - b[i]|)
       

      Lower distances are more similar.

    • HAMMING

      public static final WeaviateDistance HAMMING
      Hamming distance, the number of dimensions whose values differ.

      It suits vectors of flags or hashes, such as the set of features an item has or lacks.

      
       hamming(a, b) = count(a[i] != b[i])
       

      Lower distances are more similar.

  • Method Details

    • values

      public static WeaviateDistance[] 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 WeaviateDistance 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 WeaviateDistance parse(String value)
      Parses a distance by its name or its Weaviate name (L2_SQUARED), ignoring the case.
      Parameters:
      value - the distance name
      Returns:
      the distance
      Throws:
      NullPointerException - when the value is null
      IllegalArgumentException - when the value is not a supported distance