Interface Vector
- All Known Subinterfaces:
SparseVector
- All Known Implementing Classes:
ByteVector, DoubleVector, FloatVector, SparseByteVector, SparseDoubleVector, SparseFloatVector
@TypeDef(type=OBJECT,
converter=VectorAttributeConverter.class)
public sealed interface Vector
permits DoubleVector, FloatVector, ByteVector, SparseVector
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 -
Method Summary
Modifier and TypeMethodDescriptiongetType()Return the primitive number type the vector is backed by.static @NonNull Vectorof(byte... values) Create a vector from byte values (defensive copy).static @NonNull Vectorof(double... values) Create a vector from double values (defensive copy).static @NonNull Vectorof(float... values) Create a vector from float values (defensive copy).static @NonNull Vectorof(@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.default SparseByteVectorConverts this vector to sparse byte representation.default SparseDoubleVectorConverts this vector to sparse double representation.default SparseFloatVectorConverts this vector to sparse float representation.
-
Field Details
-
VALUES
- See Also:
-
-
Method Details
-
getType
-
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
Converts this vector to sparse float representation.- Returns:
- sparse float vector
-
toSparseDoubleVector
Converts this vector to sparse double representation.- Returns:
- sparse double vector
-
toSparseByteVector
Converts this vector to sparse byte representation.- Returns:
- sparse byte vector
-
of
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
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
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
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
-