Documentation

    array_cosine_similarity

    Computes the cosine similarity between two arrays of the same size. The array elements can not be NULL. The arrays can have any size as long as the size is the same for both arguments.

    Try an expression

    In Formula, enter the expression and set Output type to FLOAT.

    Expression

    array_cosine_similarity(array_value(1.0::FLOAT, 2.0::FLOAT, 3.0::FLOAT), array_value(2.0::FLOAT, 3.0::FLOAT, 4.0::FLOAT))

    Result

    0.9925834

    To use your own data, replace the example values with column names. Keep format strings and other options as written.

    Arguments and types

    array_cosine_similarity(array1, array2)
    array1
    List
    array2
    List
    Supported signatures (2)
    array_cosine_similarity(array1: DOUBLE[ANY], array2: DOUBLE[ANY]) → DOUBLE
    array_cosine_similarity(array1: FLOAT[ANY], array2: FLOAT[ANY]) → FLOAT

    The result type can depend on the input types. See DuckDB for the full argument rules.

    Things to know

    If the first argument is missing, the result is NULL.

    Browse lists & arraysDuckDB documentation

    Function metadata from DuckDB, used under the MIT license.