ES|QL V_COSINE function
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
GA
9.4+
…
Generally available since 9.4
Preview in 9.3
Calculates the cosine similarity between two dense_vectors.
left- first dense_vector to calculate cosine similarity
right-
second dense_vector to calculate cosine similarity
Calculates the cosine similarity between two dense_vectors.
| left | right | result |
|---|---|---|
| dense_vector | dense_vector | double |
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 |