> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for VECTOR_COSINE_SIMILARITY function

# VECTOR_COSINE_SIMILARITY

## VECTOR\_COSINE\_SIMILARITY

Returns the cosine similarity between two vectors, calculated based on the angle (θ) between them. Vector cosine similarity measures how closely two vectors point in the same direction, and is calculated as `cos(θ)`. `VECTOR_COSINE_SIMILARITY` returns a value in the range `[-1, 1]`. A vector cosine similarity of `1` means that the vectors are identical in direction. A similarity of `0` means that they are orthogonal and have no correlation. A similarity of `-1` means that they point in opposite directions.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
VECTOR_COSINE_SIMILARITY(<array>, <array>)
```

## Parameters

| Parameter | Description                                          | Supported input types                                                 |
| :-------- | :--------------------------------------------------- | :-------------------------------------------------------------------- |
| `<array>` | The first array used in the similarity calculation   | Any array of [numeric data types](/reference-sql/data-types#numeric). |
| `<array>` | The second array used in the similarity calculation. | Any array of [numeric data types](/reference-sql/data-types#numeric). |

## Notes

Both input `array` arguments must have the same number of elements.

## Return Type

`DOUBLE`

## Examples

**Example**

The following code returns the cosine similarity between two vectors that point in very similar directions:

<div className="query-window">
  ```
  SELECT VECTOR_COSINE_SIMILARITY([1, 2], [3, 4]) AS similarity;
  ```

  | similarity <span>double</span> |
  | :----------------------------- |
  | 0.9838699100999074             |

  <p><span>Rows: 1</span><span>Execution time: 5.89ms</span></p>
</div>

**Example**

The following code returns the cosine similarity between two vectors that point in very different directions:

<div className="query-window">
  ```
  SELECT VECTOR_COSINE_SIMILARITY([1, 2], [-3, -4]) AS similarity;
  ```

  | similarity <span>double</span> |
  | :----------------------------- |
  | -0.9838699100999074            |

  <p><span>Rows: 1</span><span>Execution time: 5.68ms</span></p>
</div>

**Example**

The following code returns the cosine similarity between two vectors that are orthogonal to each other:

<div className="query-window">
  ```
  SELECT VECTOR_COSINE_SIMILARITY([2, 0], [0, 2]) AS similarity;
  ```

  | similarity <span>double</span> |
  | :----------------------------- |
  | 0                              |

  <p><span>Rows: 1</span><span>Execution time: 19.86ms</span></p>
</div>
