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 voidcheckDimensions(int qvDims) static voidcheckDimensions(int dvDims, int qvDims) default doublecosineSimilarity(byte[] queryVector) Get the cosine similarity with the un-normalized query vectordoublecosineSimilarity(byte[] queryVector, float qvMagnitude) Get the cosine similarity with the query vectordefault doublecosineSimilarity(float[] queryVector) Get the cosine similarity with the un-normalized query vectordoublecosineSimilarity(float[] queryVector, boolean normalizeQueryVector) Get the cosine similarity with the query vectordefault doublecosineSimilarity(Object queryVector) Get the cosine similarity with the un-normalized query vector.doublecosineSimilarity(List<Number> queryVector) Get the cosine similarity with the un-normalized query vectorintdotProduct(byte[] queryVector) doubledotProduct(float[] queryVector) default doubledotProduct(Object queryVector) doubledotProduct(List<Number> queryVector) static floatgetBitMagnitude(byte[] vector, int dims) intgetDims()floatstatic floatgetMagnitude(byte[] vector) static floatgetMagnitude(byte[] vector, int dims) static floatgetMagnitude(float[] vector) static floatgetMagnitude(List<Number> vector) float[]inthamming(byte[] queryVector) default intintbooleanisEmpty()intl1Norm(byte[] queryVector) doublel1Norm(float[] queryVector) default doubledoubledoublel2Norm(byte[] queryVector) doublel2Norm(float[] queryVector) default doubledoubleintsize()
-
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)
-