Skip to content

daft.functions.cosine_similarity#

cosine_similarity #

cosine_similarity(left: Expression, right: Expression) -> Expression

Compute the cosine similarity between two embeddings.

Parameters:

Name Type Description Default
left FixedSizeList or Embedding Expression

The left vector

required
right FixedSizeList or Embedding Expression

The right vector

required

Returns:

Name Type Description
Expression Float64 Expression

the cosine similarity between the two vectors.

Source code in daft/functions/similarity.py
25
26
27
28
29
30
31
32
33
34
35
def cosine_similarity(left: Expression, right: Expression) -> Expression:
    """Compute the cosine similarity between two embeddings.

    Args:
        left (FixedSizeList or Embedding Expression): The left vector
        right (FixedSizeList or Embedding Expression): The right vector

    Returns:
        Expression (Float64 Expression): the cosine similarity between the two vectors.
    """
    return Expression._call_builtin_scalar_fn("cosine_similarity", left, right)