Table of Contents

Method SimilarityCosine

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

SimilarityCosine<TElement>(IEnumerable<TElement>, IEnumerable<TElement>, bool)

Translated to the "$similarityCosine" operator in MQL to measure the similarity between two vectors.

public static double SimilarityCosine<TElement>(IEnumerable<TElement> vector1, IEnumerable<TElement> vector2, bool normalizeScore)

Parameters

vector1 IEnumerable<TElement>

The first vector to compare. Must have the same length as the second vector.

vector2 IEnumerable<TElement>

The second vector to compare. Must have the same length as the first vector.

normalizeScore bool

Whether to normalize the result for use as a vector search score.

Returns

double

The cosine measure between the two vectors.

Type Parameters

TElement

The vector element type

Exceptions

NotSupportedException

if used for anything other than translating to MQL.

SimilarityCosine<TElement>(ReadOnlyMemory<TElement>, ReadOnlyMemory<TElement>, bool)

Translated to the "$similarityCosine" operator in MQL to measure the similarity between two vectors.

public static double SimilarityCosine<TElement>(ReadOnlyMemory<TElement> vector1, ReadOnlyMemory<TElement> vector2, bool normalizeScore)

Parameters

vector1 ReadOnlyMemory<TElement>

The first vector to compare. Must have the same length as the second vector.

vector2 ReadOnlyMemory<TElement>

The second vector to compare. Must have the same length as the first vector.

normalizeScore bool

Whether to normalize the result for use as a vector search score.

Returns

double

The cosine measure between the two vectors.

Type Parameters

TElement

The vector element type

Exceptions

NotSupportedException

if used for anything other than translating to MQL.