> ## 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.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/functions-reference/vector/vector-cosine-similarity",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> 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":"github-light","dark":"github-dark"}}
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:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT VECTOR_COSINE_SIMILARITY([1, 2], [3, 4]) AS similarity;
```

**Returns**

| similarity (DOUBLE PRECISION) |
| :---------------------------- |
| 0.9838699100999074            |

**Example**

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

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT VECTOR_COSINE_SIMILARITY([1, 2], [-3, -4]) AS similarity;
```

**Returns**

| similarity (DOUBLE PRECISION) |
| :---------------------------- |
| -0.9838699100999074           |

**Example**

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

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT VECTOR_COSINE_SIMILARITY([2, 0], [0, 2]) AS similarity;
```

**Returns**

| similarity (DOUBLE PRECISION) |
| :---------------------------- |
| 0                             |
