Class MongoVector
- All Implemented Interfaces:
Vector
Vector
based on Mongo's BinaryVector
. Note that only float32
and int8
variants can be represented as floating-point numbers. int1
throws
UnsupportedOperationException
when calling toFloatArray()
and toDoubleArray()
.- Since:
- 4.5
- Author:
- Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptionboolean
static MongoVector
Creates a new binaryMongoVector
from the givenVector
.org.bson.BinaryVector
getType()
int
hashCode()
static MongoVector
of
(org.bson.BinaryVector v) Creates a new binaryMongoVector
using the givenBinaryVector
.static MongoVector
ofFloat
(float... data) Creates a new binaryMongoVector
using the givendata
.static MongoVector
ofInt8
(byte[] data) Creates a new binaryMongoVector
using the givendata
.int
size()
double[]
float[]
toString()
-
Method Details
-
of
Creates a new binaryMongoVector
using the givenBinaryVector
.- Parameters:
v
- binary vector representation.- Returns:
- the
MongoVector
wrappingBinaryVector
.
-
ofInt8
Creates a new binaryMongoVector
using the givendata
.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 is not copied; changes to the provided array will be referenced in the created
MongoVector
instance.- Parameters:
data
- the byte array representing theBinaryVector.DataType.INT8
vector data.- Returns:
- the
MongoVector
containing the given vector values to be represented as binaryint8
.
-
ofFloat
Creates a new binaryMongoVector
using the givendata
.A
BinaryVector.DataType.FLOAT32
vector is a vector of floating-point numbers, where each element in the vector is afloat
.NOTE: The float array is not copied; changes to the provided array will be referenced in the created
MongoVector
instance.- Parameters:
data
- the float array representing theBinaryVector.DataType.FLOAT32
vector data.- Returns:
- the
MongoVector
containing the given vector values to be represented as binaryfloat32
.
-
fromFloat
Creates a new binaryMongoVector
from the givenVector
.A
BinaryVector.DataType.FLOAT32
vector is a vector of floating-point numbers, where each element in the vector is afloat
. The givenVector
must be able to return afloat
array.NOTE: The float array is not copied; changes to the provided array will be referenced in the created
MongoVector
instance.- Parameters:
v
- the- Returns:
- the
MongoVector
using vector values from the givenVector
to be represented as binary float32.
-
getType
-
getSource
public org.bson.BinaryVector getSource() -
size
public int size() -
toFloatArray
public float[] toFloatArray()- Specified by:
toFloatArray
in interfaceVector
- Throws:
UnsupportedOperationException
- if the underlying data type isint1
PackedBitBinaryVector
.
-
toDoubleArray
public double[] toDoubleArray()- Specified by:
toDoubleArray
in interfaceVector
- Throws:
UnsupportedOperationException
- if the underlying data type isint1
PackedBitBinaryVector
.
-
equals
-
hashCode
public int hashCode() -
toString
-