Enum Class VectorScoringFunctions

java.lang.Object
java.lang.Enum<VectorScoringFunctions>
org.springframework.data.domain.VectorScoringFunctions
All Implemented Interfaces:
Serializable, Comparable<VectorScoringFunctions>, Constable, ScoringFunction

public enum VectorScoringFunctions extends Enum<VectorScoringFunctions> implements ScoringFunction
Commonly used ScoringFunction implementations for vector-based similarity computations.

Provides a set of standard scoring strategies for comparing vectors in search or matching operations. Includes options such as Euclidean distance, cosine similarity, and dot product.

These constants are intended for reuse across components requiring vector scoring semantics. Each scoring function represents a mathematical approach to quantifying the similarity or distance between vectors in a multidimensional space.

When selecting a scoring function, consider the specific requirements of your application domain:

  • For spatial distance measurements where magnitude matters, use EUCLIDEAN.
  • For directional similarity irrespective of magnitude, use COSINE.
  • For efficient high-dimensional calculations, use DOT_PRODUCT.
  • For grid-based or axis-aligned problems, use TAXICAB.
  • For binary vector or string comparisons, use HAMMING.
The choice of scoring function can significantly impact the relevance of the results returned by a Vector Search query. ScoringFunction and score values are typically subject to fine-tuning during the development to achieve optimal performance and accuracy.
Since:
4.0
Author:
Mark Paluch
  • Enum Constant Details

    • EUCLIDEAN

      public static final VectorScoringFunctions EUCLIDEAN
      Scoring based on the Euclidean distance between two vectors.

      Computes the L2 norm, involving a square root operation. Typically more computationally expensive than COSINE or DOT_PRODUCT, but precise in spatial distance measurement.

    • COSINE

      public static final VectorScoringFunctions COSINE
      Scoring based on cosine similarity between two vectors.

      Measures the angle between vectors, independent of their magnitude. Involves a DOT_PRODUCT and normalization, offering a balance between precision and performance.

    • DOT_PRODUCT

      public static final VectorScoringFunctions DOT_PRODUCT
      Scoring based on the dot product (also known as inner product) between two vectors.

      Efficient to compute and particularly useful in high-dimensional vector spaces.

    • TAXICAB

      public static final VectorScoringFunctions TAXICAB
      Scoring based on taxicab (Manhattan) distance.

      Computes the sum of absolute differences across dimensions. Useful in contexts where axis-aligned movement or L1 norms are preferred.

    • HAMMING

      public static final VectorScoringFunctions HAMMING
      Scoring based on the Hamming distance between two vectors or strings.

      Counts the number of differing positions. Suitable for binary (bitwise) vectors or fixed-length character sequences.

  • Method Details

    • values

      public static VectorScoringFunctions[] 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 VectorScoringFunctions 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
    • getName

      public String getName()
      Description copied from interface: ScoringFunction
      Return the name of the scoring function.

      Typically used for display or configuration purposes.

      Specified by:
      getName in interface ScoringFunction
      Returns:
      the identifying name of this scoring function.