Interface Vector
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 TypeMethodDescriptionReturns the source array of the vector.getType()
Returns the type of the underlying vector source.static Vector
of
(double... values) Creates a newVector
from the given doublevalues
.static Vector
of
(float... values) Creates a newVector
from the given floatvalues
.static Vector
of
(Collection<? extends Number> values) Creates a newVector
from the given numbervalues
.int
size()
Returns the number of dimensions.double[]
Convert the vector to adouble
array.float[]
Convert the vector to afloat
array.static Vector
unsafe
(double[] values) Creates a new unsafeVector
wrapper from the givenvalues
.static Vector
unsafe
(float[] values) Creates a new unsafeVector
wrapper from the givenvalues
.
-
Method Details
-
of
Creates a newVector
from the given floatvalues
. 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
Creates a newVector
from the given doublevalues
. 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
Creates a newVector
from the given numbervalues
. 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
Creates a new unsafeVector
wrapper from the givenvalues
. 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
Creates a new unsafeVector
wrapper from the givenvalues
. 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
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 afloat
array. The returned array is a copy of thesource
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 afloat
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 adouble
array. The returned array is a copy of thesource
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 adouble
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.
-