Class BinaryVector
- Direct Known Subclasses:
Float32BinaryVector
,Int8BinaryVector
,PackedBitBinaryVector
BinaryVector.DataType
's and provides static methods to create vectors.
NOTE: This class should be treated as sealed: it must not be extended or implemented by consumers of the library.
- Since:
- 5.3
- See Also:
- Since server release
- 6.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Represents the data type (dtype) of a vector. -
Method Summary
Modifier and TypeMethodDescriptionReturns theFloat32BinaryVector
.Returns theInt8BinaryVector
.Returns thePackedBitBinaryVector
.static Float32BinaryVector
floatVector
(float[] data) Creates a vector with theBinaryVector.DataType.FLOAT32
data type.ReturnsBinaryVector.DataType
of the vector.static Int8BinaryVector
int8Vector
(byte[] data) Creates a vector with theBinaryVector.DataType.INT8
data type.static PackedBitBinaryVector
packedBitVector
(byte[] data, byte padding) Creates a vector with theBinaryVector.DataType.PACKED_BIT
data type.
-
Method Details
-
packedBitVector
Creates a vector with theBinaryVector.DataType.PACKED_BIT
data type.A
BinaryVector.DataType.PACKED_BIT
vector is a binary quantized vector where each element of a vector is represented by a single bit (0 or 1). Each byte can hold up to 8 bits (vector elements). The padding parameter is used to specify how many least-significant bits in the final byte should be ignored.For example, a vector with two bytes and a padding of 4 would have the following structure:
Byte 1: 238 (binary: 11101110) Byte 2: 224 (binary: 11100000) Padding: 4 (ignore the last 4 bits in Byte 2) Resulting vector: 12 bits: 111011101110
NOTE: The byte array `data` is not copied; changes to the provided array will be reflected in the created
PackedBitBinaryVector
instance.- Parameters:
data
- The byte array representing the packed bit vector data. Each byte can store 8 bits.padding
- The number of least-significant bits (0 to 7) to ignore in the final byte of the vector data.- Returns:
- A
PackedBitBinaryVector
instance with theBinaryVector.DataType.PACKED_BIT
data type. - Throws:
IllegalArgumentException
- If the padding value is greater than 7.
-
int8Vector
Creates a vector with theBinaryVector.DataType.INT8
data type.A
BinaryVector.DataType.INT8
vector is a vector of 8-bit signed integers where each byte in the vector represents an element of a vector, with values in the range [-128, 127].NOTE: The byte array `data` is not copied; changes to the provided array will be reflected in the created
Int8BinaryVector
instance.- Parameters:
data
- The byte array representing theBinaryVector.DataType.INT8
vector data.- Returns:
- A
Int8BinaryVector
instance with theBinaryVector.DataType.INT8
data type.
-
floatVector
Creates a vector with theBinaryVector.DataType.FLOAT32
data type.A
BinaryVector.DataType.FLOAT32
vector is a vector of floating-point numbers, where each element in the vector is a float.NOTE: The float array `data` is not copied; changes to the provided array will be reflected in the created
Float32BinaryVector
instance.- Parameters:
data
- The float array representing theBinaryVector.DataType.FLOAT32
vector data.- Returns:
- A
Float32BinaryVector
instance with theBinaryVector.DataType.FLOAT32
data type.
-
asPackedBitVector
Returns thePackedBitBinaryVector
.- Returns:
PackedBitBinaryVector
.- Throws:
IllegalStateException
- if this vector is not of typeBinaryVector.DataType.PACKED_BIT
. UsegetDataType()
to check the vector type before calling this method.
-
asInt8Vector
Returns theInt8BinaryVector
.- Returns:
Int8BinaryVector
.- Throws:
IllegalStateException
- if this vector is not of typeBinaryVector.DataType.INT8
. UsegetDataType()
to check the vector type before calling this method.
-
asFloat32Vector
Returns theFloat32BinaryVector
.- Returns:
Float32BinaryVector
.- Throws:
IllegalStateException
- if this vector is not of typeBinaryVector.DataType.FLOAT32
. UsegetDataType()
to check the vector type before calling this method.
-
getDataType
ReturnsBinaryVector.DataType
of the vector.- Returns:
- the data type of the vector.
-