Record Class BinaryVector

java.lang.Object
java.lang.Record
io.micronaut.data.model.vector.BinaryVector
Record Components:
data - the packed bits, eight dimensions per byte, most significant bit first (a defensive copy is returned by accessors)
All Implemented Interfaces:
Vector

@TypeDef(type=OBJECT, converter=BinaryVectorAttributeConverter.class) public record BinaryVector(byte[] data) extends Record implements Vector
Bit-packed immutable vector, mapped to Oracle VECTOR(n, BINARY) columns.

Each dimension is one bit. The backing array packs eight dimensions per byte, most significant bit first, so a vector of n dimensions holds n / 8 bytes and the number of dimensions is always a multiple of 8. This is the layout Oracle uses for BINARY vectors.

Compare binary vectors with ScoringFunction.HAMMING or ScoringFunction.JACCARD.

The array conversions of Vector return one element per dimension, 0 or 1. Use data() for the packed bytes.

Since:
5.3.0
Author:
Graeme Rocher
  • Constructor Details

    • BinaryVector

      public BinaryVector(byte[] data)
      Creates a binary vector from packed bits.
      Parameters:
      data - the packed bits, eight dimensions per byte, most significant bit first
  • Method Details

    • of

      public static @NonNull BinaryVector of(boolean... bits)
      Creates a binary vector with one dimension per bit.
      Parameters:
      bits - the bits; the length must be a multiple of 8
      Returns:
      the binary vector
    • data

      public byte[] data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • dimensions

      public int dimensions()
      Returns:
      the number of dimensions, which is the number of bits
    • get

      public boolean get(int index)
      Returns the bit at the given dimension.
      Parameters:
      index - the dimension, from 0
      Returns:
      true when the bit is set
    • toBooleanArray

      public boolean[] toBooleanArray()
      Returns:
      one element per dimension, true where the bit is set
    • getType

      public @NonNull Class<? extends Number> getType()
      Returns byte: the type of the packed backing array.
      Specified by:
      getType in interface Vector
      Returns:
      Byte.TYPE
    • toFloatArray

      public float[] toFloatArray()
      Description copied from interface: Vector
      Convert this vector to a new float array copy.
      Specified by:
      toFloatArray in interface Vector
      Returns:
      a new float[] with the vector content
    • toDoubleArray

      public double[] toDoubleArray()
      Description copied from interface: Vector
      Convert this vector to a new double array copy.
      Specified by:
      toDoubleArray in interface Vector
      Returns:
      a new double[] with the vector content
    • toByteArray

      public byte[] toByteArray()
      Description copied from interface: Vector
      Convert this vector to a new byte array copy.
      Specified by:
      toByteArray in interface Vector
      Returns:
      a new byte[] with the vector content
    • toString

      public @NonNull String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.