최종 수정: 에
COSINE_SIMILARITY_APPROXIMATE
Description
Calculates cosine similarity between two vectors. NULL arrays or NULL elements raise an error.
Available in Doris 4.2 builds that include this function.Eligible Lance Top-N queries can use native approximate retrieval; other queries execute scalar kernels.
Syntax
COSINE_SIMILARITY_APPROXIMATE(<array1>, <array2>)
Parameters
| Parameter | Description |
|---|---|
<array1> | Numeric array, implicitly converted to ARRAY |
<array2> | Numeric array, implicitly converted to ARRAY |
Return Value
Returns FLOAT; larger means more similar. Scalar evaluation computes dot(x,y) / (norm(x) * norm(y)). If either norm is zero, including two empty arrays, it returns 0.Unequal lengths, NULL arrays, or NULL elements raise an error rather than return NULL.Native candidate eligibility, numerical precision, and NULL/NaN behavior can differ from scalar execution; see automatic search.
Example
SELECT COSINE_SIMILARITY_APPROXIMATE([1,0], [0,1]) AS value;
value
0
SELECT COSINE_SIMILARITY_APPROXIMATE([0,0], [1,0]) AS value;
value
0
SELECT COSINE_SIMILARITY_APPROXIMATE(NULL, [0,1]);
ERROR: First argument for function cosine_similarity_approximate cannot be null
SELECT COSINE_SIMILARITY_APPROXIMATE([0,NULL], [0,1]);
ERROR: First argument for function cosine_similarity_approximate cannot have null