Interface Vector


public interface Vector
A vector is a fixed-length array of non-null numeric values. Vectors are represent a point in a multidimensional space that is commonly used in machine learning and statistics.

Vector properties do not map cleanly to an existing class in the standard JDK Collections hierarchy. Vectors when used with embeddings (machine learning) represent an opaque point in the vector space that does not expose meaningful properties nor guarantees computational values to the outside world.

Vectors should be treated as opaque values and should not be modified. They can be created from an array of numbers (typically double or float values) and used by components that need to provide the vector for storage or computation.

Since:
3.5
Author:
Mark Paluch
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the source array of the vector.
    Class<? extends Number>
    Returns the type of the underlying vector source.
    static Vector
    of(double... values)
    Creates a new Vector from the given double values.
    static Vector
    of(float... values)
    Creates a new Vector from the given float values.
    static Vector
    of(Collection<? extends Number> values)
    Creates a new Vector from the given number values.
    int
    Returns the number of dimensions.
    double[]
    Convert the vector to a double array.
    float[]
    Convert the vector to a float array.
    static Vector
    unsafe(double[] values)
    Creates a new unsafe Vector wrapper from the given values.
    static Vector
    unsafe(float[] values)
    Creates a new unsafe Vector wrapper from the given values.
  • Method Details

    • of

      static Vector of(float... values)
      Creates a new Vector from the given float values. Vector values are duplicated to avoid capturing a mutable array instance and to prevent mutability.
      Parameters:
      values - float vector values.
      Returns:
      the Vector for the given vector values.
    • of

      static Vector of(double... values)
      Creates a new Vector from the given double values. Vector values are duplicated to avoid capturing a mutable array instance and to prevent mutability.
      Parameters:
      values - double vector values.
      Returns:
      the Vector for the given vector values.
    • of

      static Vector of(Collection<? extends Number> values)
      Creates a new Vector from the given number values. Vector values are duplicated to avoid capturing a mutable collection instance and to prevent mutability.
      Parameters:
      values - number vector values.
      Returns:
      the Vector for the given vector values.
    • unsafe

      static Vector unsafe(float[] values)
      Creates a new unsafe Vector wrapper from the given values. Unsafe wrappers do not duplicate array values and are merely a view on the source array.

      Supported source type

      Parameters:
      values - vector values.
      Returns:
      the Vector for the given vector values.
    • unsafe

      static Vector unsafe(double[] values)
      Creates a new unsafe Vector wrapper from the given values. Unsafe wrappers do not duplicate array values and are merely a view on the source array.

      Supported source type

      Parameters:
      values - vector values.
      Returns:
      the Vector for the given vector values.
    • getType

      Class<? extends Number> getType()
      Returns the type of the underlying vector source.
      Returns:
      the type of the underlying vector source.
    • getSource

      Object getSource()
      Returns the source array of the vector. The source array is not copied and should not be modified to avoid mutability issues. This method should be used for performance access.
      Returns:
      the source array of the vector.
    • size

      int size()
      Returns the number of dimensions.
      Returns:
      the number of dimensions.
    • toFloatArray

      float[] toFloatArray()
      Convert the vector to a float array. The returned array is a copy of the source array and can be modified safely.

      Conversion to float can incorporate loss of precision or result in values with a slight offset due to data type conversion if the source is not a float array.

      Note that Vectors using quantization or binary representations may not be convertible to a float array.

      Returns:
      a new float array representing the vector point.
    • toDoubleArray

      double[] toDoubleArray()
      Convert the vector to a double array. The returned array is a copy of the source array and can be modified safely.

      Conversion to double can incorporate loss of precision or result in values with a slight offset due to data type conversion if the source is not a double array.

      Note that Vectors using quantization or binary representations may not be convertible to a double array.

      Returns:
      a new double array representing the vector point.