diff --git a/docs/src/main/sphinx/functions/array.md b/docs/src/main/sphinx/functions/array.md index cb60ef8dcc5e..c0222f48a99a 100644 --- a/docs/src/main/sphinx/functions/array.md +++ b/docs/src/main/sphinx/functions/array.md @@ -410,15 +410,6 @@ SELECT dot_product(ARRAY[1.0, 2.0], ARRAY[3.0, 4.0]); ``` ::: -:::{function} cosine_distance(array(double), array(double)) -> double -Calculates the cosine distance: - -```sql -SELECT cosine_distance(ARRAY[1.0, 2.0], ARRAY[3.0, 4.0]); --- 0.01613008990009257 -``` -::: - :::{function} zip(array1, array2[, ...]) -> array(row) Merges the given arrays, element-wise, into a single array of rows. The M-th element of the N-th argument will be the N-th field of the M-th output element. diff --git a/docs/src/main/sphinx/functions/list-by-topic.md b/docs/src/main/sphinx/functions/list-by-topic.md index 9e61e1aed278..233bf3e580c5 100644 --- a/docs/src/main/sphinx/functions/list-by-topic.md +++ b/docs/src/main/sphinx/functions/list-by-topic.md @@ -370,6 +370,7 @@ For more details, see {doc}`math` - {func}`ceil` - {func}`cos` - {func}`cosh` +- {func}`cosine_distance` - {func}`cosine_similarity` - {func}`degrees` - {func}`e` diff --git a/docs/src/main/sphinx/functions/list.md b/docs/src/main/sphinx/functions/list.md index 2301be603a3e..fef1ade7672a 100644 --- a/docs/src/main/sphinx/functions/list.md +++ b/docs/src/main/sphinx/functions/list.md @@ -102,6 +102,7 @@ - {func}`corr` - {func}`cos` - {func}`cosh` +- {func}`cosine_distance` - {func}`cosine_similarity` - {func}`count` - {func}`count_if` diff --git a/docs/src/main/sphinx/functions/math.md b/docs/src/main/sphinx/functions/math.md index 584dfc3fee09..58823823e668 100644 --- a/docs/src/main/sphinx/functions/math.md +++ b/docs/src/main/sphinx/functions/math.md @@ -194,6 +194,36 @@ Returns the tangent of `x`. Returns the hyperbolic tangent of `x`. ::: +## Geometric functions + +:::{function} cosine_distance(array(double), array(double)) -> double +Calculates the cosine distance between two dense vectors: + +```sql +SELECT cosine_distance(ARRAY[1.0, 2.0], ARRAY[3.0, 4.0]); +-- 0.01613008990009257 +``` +::: + +:::{function} cosine_similarity(array(double), array(double)) -> double +Calculates the cosine similarity of two dense vectors: + +```sql +SELECT cosine_similarity(ARRAY[1.0, 2.0], ARRAY[3.0, 4.0]); +-- 0.9838699100999074 +``` +::: + +:::{function} cosine_similarity(x, y) -> double +:no-index: +Calculates the cosine similarity of two sparse vectors: + +```sql +SELECT cosine_similarity(MAP(ARRAY['a'], ARRAY[1.0]), MAP(ARRAY['a'], ARRAY[2.0])); +-- 1.0 +``` +::: + ## Floating point functions :::{function} infinity() -> double @@ -228,14 +258,6 @@ Returns the base-`radix` representation of `x`. ## Statistical functions -:::{function} cosine_similarity(x, y) -> double -Returns the cosine similarity between the sparse vectors `x` and `y`: - -``` -SELECT cosine_similarity(MAP(ARRAY['a'], ARRAY[1.0]), MAP(ARRAY['a'], ARRAY[2.0])); -- 1.0 -``` -::: - :::{function} t_pdf(x, df) -> double Computes the Student's t-distribution probability density function for given x and degrees of freedom (df). The x must be a real value and degrees of freedom must be