Skip to content

Commit

Permalink
Add geometric math functions to docs
Browse files Browse the repository at this point in the history
Add docs for new cosine_distance function, move related docs, and clean up
and docs
  • Loading branch information
mosabua committed Nov 4, 2024
1 parent cb4b539 commit bd9fee7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
9 changes: 0 additions & 9 deletions docs/src/main/sphinx/functions/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/sphinx/functions/list-by-topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/sphinx/functions/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
- {func}`corr`
- {func}`cos`
- {func}`cosh`
- {func}`cosine_distance`
- {func}`cosine_similarity`
- {func}`count`
- {func}`count_if`
Expand Down
38 changes: 30 additions & 8 deletions docs/src/main/sphinx/functions/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bd9fee7

Please sign in to comment.