VectorOperations Class

  • java.lang.Object
    • com.microsoft.semantickernel.data.vectorsearch.VectorOperations

public final class VectorOperations

Operations for working with vectors.

Constructor Summary

Constructor Description
VectorOperations()

Method Summary

Modifier and Type Method and Description
static java.util.List<VectorSearchResult<Record>> exactSimilaritySearch(List<Record> records, List<Float> vector, VectorStoreRecordVectorField vectorField, DistanceFunction distanceFunction, VectorSearchOptions options)

Performs an exact similarity search on a list of records using a vector field.

static double cosineDistance(List<Float> x, List<Float> y)

Calculates the cosine distance of two vectors.

static float cosineSimilarity(List<Float> x, List<Float> y)

Calculates the cosine similarity of two vectors.

static java.util.List<java.lang.Float> divide(List<Float> vector, float divisor)

Divides the elements of the vector by the divisor.

static float dot(List<Float> x, List<Float> y)

Calculates the dot product of two vectors.

static float euclideanDistance(List<Float> x, List<Float> y)

Calculates the Euclidean distance between two vectors.

static float euclideanLength(List<Float> vector)

Calculates the Euclidean length of a vector.

static java.util.List<java.lang.Float> multiply(List<Float> vector, float multiplier)

Multiplies the elements of the vector by the multiplier.

static java.util.List<java.lang.Float> normalize(List<Float> vector)

Normalizes the vector such that the Euclidean length is 1.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

VectorOperations

public VectorOperations()

Method Details

exactSimilaritySearch

public static List> exactSimilaritySearch(List records, List vector, VectorStoreRecordVectorField vectorField, DistanceFunction distanceFunction, VectorSearchOptions options)

Performs an exact similarity search on a list of records using a vector field.

Parameters:

records - The records to search.
vector - The vector to search for.
vectorField - The vector field to use for the search.
distanceFunction - The distance function to use for the search.
options - The search options.

Returns:

The search results.

cosineDistance

public static double cosineDistance(List x, List y)

Calculates the cosine distance of two vectors. The vectors must be equal in length and have non-zero norm.

Parameters:

x - First vector, which is not modified
y - Second vector, which is not modified

Returns:

The cosine distance of the two vectors

cosineSimilarity

public static float cosineSimilarity(List x, List y)

Calculates the cosine similarity of two vectors. The vectors must be equal in length and have non-zero norm.

Parameters:

x - First vector, which is not modified
y - Second vector, which is not modified

Returns:

The cosine similarity of the two vectors

divide

public static List divide(List vector, float divisor)

Divides the elements of the vector by the divisor.

Parameters:

vector - Vector to divide, which is not modified
divisor - Divisor to apply to each element of the vector

Returns:

A new vector with the elements divided by the divisor

dot

public static float dot(List x, List y)

Calculates the dot product of two vectors.

Parameters:

x - First vector, which is not modified
y - Second vector, which is not modified

Returns:

The dot product of the two vectors

euclideanDistance

public static float euclideanDistance(List x, List y)

Calculates the Euclidean distance between two vectors.

Parameters:

x - First vector, which is not modified
y - Second vector, which is not modified

Returns:

The Euclidean distance between the two vectors

euclideanLength

public static float euclideanLength(List vector)

Calculates the Euclidean length of a vector.

Parameters:

vector - Vector to calculate the length of, which is not modified

Returns:

The Euclidean length of the vector

multiply

public static List multiply(List vector, float multiplier)

Multiplies the elements of the vector by the multiplier.

Parameters:

vector - Vector to multiply, which is not modified
multiplier - Multiplier to apply to each element of the vector

Returns:

A new vector with the elements multiplied by the multiplier

normalize

public static List normalize(List vector)

Normalizes the vector such that the Euclidean length is 1.

Parameters:

vector - Vector to normalize, which is not modified

Returns:

A new, normalized vector

Applies to