VectorSimilarityFunction

Vector similarity function; used in search to return top K most similar vectors to a target vector. This is a label describing the method used during indexing and searching of the vectors in order to determine the nearest neighbors.

Entries

Link copied to clipboard

Euclidean distance

Link copied to clipboard

Dot product. NOTE: this similarity is intended as an optimized way to perform cosine similarity. In order to use it, all vectors must be normalized, including both document and query vectors. Using dot product with vectors that are not normalized can result in errors or poor search results. Floating point vectors must be normalized to be of unit length, while byte vectors should simply all have the same norm.

Link copied to clipboard

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.

Link copied to clipboard

Maximum inner product. This is like VectorSimilarityFunction.DOT_PRODUCT, but does not require normalization of the inputs. Should be used when the embedding vectors store useful information within the vector magnitude

Properties

Link copied to clipboard

Returns a representation of an immutable list of all enum entries, in the order they're declared.

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.

Link copied to clipboard

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Link copied to clipboard

Returns an array containing the constants of this enum type, in the order they're declared.