﻿---
title: ES|QL V_COSINE function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/3028/reference/query-languages/esql/functions-operators/dense-vector-functions/v_cosine
products:
  - Elasticsearch
---

# ES|QL V_COSINE function
<applies-to>
  - Elastic Stack: Preview in 9.3
</applies-to>


## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/3028/reference/query-languages/esql/images/functions/v_cosine.svg)


## Parameters

<definitions>
  <definition term="left">
    first dense_vector to calculate cosine similarity
  </definition>
  <definition term="right">
    second dense_vector to calculate cosine similarity
  </definition>
</definitions>


## Description

Calculates the cosine similarity between two dense_vectors.

## Supported types


| left         | right        | result |
|--------------|--------------|--------|
| dense_vector | dense_vector | double |


## Example

```esql
from colors
| where color != "black"
| eval similarity = v_cosine(rgb_vector, [0, 255, 255])
| sort similarity desc, color asc
```


| color:text  | similarity:double  |
|-------------|--------------------|
| cyan        | 1.0                |
| teal        | 1.0                |
| turquoise   | 0.9781067967414856 |
| aqua marine | 0.929924726486206  |
| azure       | 0.8324936032295227 |
| lavender    | 0.827340304851532  |
| mint cream  | 0.8245516419410706 |
| honeydew    | 0.8244848847389221 |
| gainsboro   | 0.8164966106414795 |
| gray        | 0.8164966106414795 |