COSINE

Cosine similarity. NOTE: the preferred way to perform cosine similarity is to normalize all vectors to unit length, and instead use VectorSimilarityFunction.DOT_PRODUCT. You should only use this function if you need to preserve the original vectors and cannot normalize them in advance. The similarity score is normalised to assure it is positive.

Properties

Link copied to clipboard
expect val name: String
Link copied to clipboard
expect val ordinal: Int

Functions

Link copied to clipboard
abstract fun compare(v1: ByteArray, v2: ByteArray): Float

Calculates a similarity score between the two vectors with a specified function. Higher similarity scores correspond to closer vectors. Each (signed) byte represents a vector dimension.

abstract fun compare(v1: FloatArray, v2: FloatArray): Float

Calculates a similarity score between the two vectors with a specified function. Higher similarity scores correspond to closer vectors.