Interface Vector

All Known Subinterfaces:
SparseVector
All Known Implementing Classes:
ByteVector, DoubleVector, FloatVector, SparseByteVector, SparseDoubleVector, SparseFloatVector

Lightweight, immutable wrapper for n-dimensional numeric embeddings. Provides conversion helpers to primitive arrays. This type is suitable both for use as a repository method argument/return type and as a persistent property type through Micronaut Data converters. Sealed hierarchy: - DoubleVector (double[]) - FloatVector (float[]) - ByteVector (byte[]) All constructors perform defensive copying to guarantee immutability. Callers should avoid excessive copying in tight loops; prefer reusing instances when possible. Notes about numeric conversions: - Converting between float and double may introduce rounding differences. - Converting to byte[] follows Java narrowing conversions (values are truncated to 8 bits). - NaN/Infinity are preserved in float/double arrays; downstream drivers/platforms may have different handling rules.
Since:
5.0.0
Author:
Nemanja Mikic
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @NonNull Class<? extends Number>
    Return the primitive number type the vector is backed by.
    static @NonNull Vector
    of(byte... values)
    Create a vector from byte values (defensive copy).
    static @NonNull Vector
    of(double... values)
    Create a vector from double values (defensive copy).
    static @NonNull Vector
    of(float... values)
    Create a vector from float values (defensive copy).
    static @NonNull Vector
    of(@NonNull Collection<? extends Number> values)
    Create a vector from a numeric collection.
    byte[]
    Convert this vector to a new byte array copy.
    double[]
    Convert this vector to a new double array copy.
    float[]
    Convert this vector to a new float array copy.
    Converts this vector to sparse byte representation.
    Converts this vector to sparse double representation.
    Converts this vector to sparse float representation.
  • Field Details

  • Method Details

    • getType

      @NonNull Class<? extends Number> getType()
      Return the primitive number type the vector is backed by.
      Returns:
      the primitive number type (Byte.TYPE, Float.TYPE or Double.TYPE)
    • toFloatArray

      float[] toFloatArray()
      Convert this vector to a new float array copy.
      Returns:
      a new float[] with the vector content
    • toDoubleArray

      double[] toDoubleArray()
      Convert this vector to a new double array copy.
      Returns:
      a new double[] with the vector content
    • toByteArray

      byte[] toByteArray()
      Convert this vector to a new byte array copy.
      Returns:
      a new byte[] with the vector content
    • toSparseFloatVector

      default SparseFloatVector toSparseFloatVector()
      Converts this vector to sparse float representation.
      Returns:
      sparse float vector
    • toSparseDoubleVector

      default SparseDoubleVector toSparseDoubleVector()
      Converts this vector to sparse double representation.
      Returns:
      sparse double vector
    • toSparseByteVector

      default SparseByteVector toSparseByteVector()
      Converts this vector to sparse byte representation.
      Returns:
      sparse byte vector
    • of

      static @NonNull Vector of(float... values)
      Create a vector from float values (defensive copy).
      Parameters:
      values - the float values to copy into the vector
      Returns:
      a new float-backed vector
    • of

      static @NonNull Vector of(double... values)
      Create a vector from double values (defensive copy).
      Parameters:
      values - the double values to copy into the vector
      Returns:
      a new double-backed vector
    • of

      static @NonNull Vector of(@NonNull Collection<? extends Number> values)
      Create a vector from a numeric collection. If all elements are Byte, an 8-bit byte-backed vector is created. If all elements are Float, a float-backed vector is created. Otherwise, a double-backed vector is created.
      Parameters:
      values - the collection of numbers; may not be null
      Returns:
      a new vector backed by byte[], float[] or double[]
    • of

      static @NonNull Vector of(byte... values)
      Create a vector from byte values (defensive copy).
      Parameters:
      values - the byte values to copy into the vector
      Returns:
      a new byte-backed vector
      Since:
      5.0.0