Module org.elasticsearch.server
Interface DenseVector
- All Known Implementing Classes:
BinaryDenseVector
,BitBinaryDenseVector
,BitKnnDenseVector
,ByteBinaryDenseVector
,ByteKnnDenseVector
,KnnDenseVector
public interface DenseVector
DenseVector value type for the painless.
dotProduct, l1Norm, l2Norm, cosineSimilarity have three flavors depending on the type of the queryVector
1) float[], this is for the ScoreScriptUtils class bindings which have converted a List based query vector into an array
2) List, A painless script will typically use Lists since they are easy to pass as params and have an easy
literal syntax. Working with Lists directly, instead of converting to a float[], trades off runtime operations against
memory pressure. Dense Vectors may have high dimensionality, up to 4096. Allocating a float[] per doc per script API
call is prohibitively expensive.
3) Object, the whitelisted method for the painless API. Calls into the float[] or List version based on the
class of the argument and checks dimensionality.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault void
checkDimensions
(int qvDims) static void
checkDimensions
(int dvDims, int qvDims) default double
cosineSimilarity
(byte[] queryVector) Get the cosine similarity with the un-normalized query vectordouble
cosineSimilarity
(byte[] queryVector, float qvMagnitude) Get the cosine similarity with the query vectordefault double
cosineSimilarity
(float[] queryVector) Get the cosine similarity with the un-normalized query vectordouble
cosineSimilarity
(float[] queryVector, boolean normalizeQueryVector) Get the cosine similarity with the query vectordefault double
cosineSimilarity
(Object queryVector) Get the cosine similarity with the un-normalized query vector.double
cosineSimilarity
(List<Number> queryVector) Get the cosine similarity with the un-normalized query vectorint
dotProduct
(byte[] queryVector) double
dotProduct
(float[] queryVector) default double
dotProduct
(Object queryVector) double
dotProduct
(List<Number> queryVector) static float
getBitMagnitude
(byte[] vector, int dims) int
getDims()
float
static float
getMagnitude
(byte[] vector) static float
getMagnitude
(byte[] vector, int dims) static float
getMagnitude
(float[] vector) static float
getMagnitude
(List<Number> vector) float[]
int
hamming
(byte[] queryVector) default int
int
boolean
isEmpty()
int
l1Norm
(byte[] queryVector) double
l1Norm
(float[] queryVector) default double
double
double
l2Norm
(byte[] queryVector) double
l2Norm
(float[] queryVector) default double
double
int
size()
-
Field Details
-
EMPTY
-
-
Method Details
-
checkDimensions
default void checkDimensions(int qvDims) -
getVector
float[] getVector() -
getMagnitude
float getMagnitude() -
dotProduct
int dotProduct(byte[] queryVector) -
dotProduct
double dotProduct(float[] queryVector) -
dotProduct
-
dotProduct
-
l1Norm
int l1Norm(byte[] queryVector) -
l1Norm
double l1Norm(float[] queryVector) -
l1Norm
-
l1Norm
-
hamming
int hamming(byte[] queryVector) -
hamming
-
hamming
-
l2Norm
double l2Norm(byte[] queryVector) -
l2Norm
double l2Norm(float[] queryVector) -
l2Norm
-
l2Norm
-
cosineSimilarity
default double cosineSimilarity(byte[] queryVector) Get the cosine similarity with the un-normalized query vector -
cosineSimilarity
double cosineSimilarity(byte[] queryVector, float qvMagnitude) Get the cosine similarity with the query vector- Parameters:
qvMagnitude
- - pre-calculated magnitude of the query vector
-
cosineSimilarity
default double cosineSimilarity(float[] queryVector) Get the cosine similarity with the un-normalized query vector -
cosineSimilarity
double cosineSimilarity(float[] queryVector, boolean normalizeQueryVector) Get the cosine similarity with the query vector- Parameters:
normalizeQueryVector
- - normalize the query vector, does not change the contents of passed in query vector
-
cosineSimilarity
Get the cosine similarity with the un-normalized query vector -
cosineSimilarity
Get the cosine similarity with the un-normalized query vector. Handles queryVectors of type float[] and List. -
isEmpty
boolean isEmpty() -
getDims
int getDims() -
size
int size() -
getMagnitude
static float getMagnitude(byte[] vector) -
getMagnitude
static float getMagnitude(byte[] vector, int dims) -
getBitMagnitude
static float getBitMagnitude(byte[] vector, int dims) -
getMagnitude
static float getMagnitude(float[] vector) -
getMagnitude
-
checkDimensions
static void checkDimensions(int dvDims, int qvDims)
-