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

# Distance metrics overview

> Measure similarity between vectors using cosine similarity, Euclidean distance, or dot product.

Distance metrics measure similarity between vectors in high-dimensional space. Actian VectorAI DB uses these metrics to rank vectors by how closely they match a query, enabling semantic search and retrieval.

The distance metric you choose depends on how your embedding model was trained and whether its output vectors are normalized. VectorAI DB supports the following distance metrics: cosine similarity, Euclidean distance, and dot product.

## Cosine similarity

Cosine similarity measures the angular relationship between vectors, ignoring magnitude. This metric focuses on direction rather than scale, making it ideal for text embeddings where the angle between vectors matters more than their length.

<img src="https://mintcdn.com/actianvectorai/3XmHIEec3Y5mC9ex/images/fundamentals/distance-metrics/cosine_similarity_metric.png?fit=max&auto=format&n=3XmHIEec3Y5mC9ex&q=85&s=926e12d8748e7cd5d0b727d64db87515" alt="Diagram showing two vectors and the angle between them used to compute cosine similarity" width="398" height="368" data-path="images/fundamentals/distance-metrics/cosine_similarity_metric.png" />

Cosine similarity ranges from negative one to one. A value of one means the vectors point in the same direction, zero means they are orthogonal, and negative one means they point in opposite directions. Some systems, including VectorAI DB, work with cosine distance internally rather than cosine similarity. Cosine distance is derived as one minus cosine similarity, so it ranges from zero (identical vectors) to two (opposite vectors).

Use cosine similarity for:

* Text embeddings and semantic similarity
* Normalized vectors
* Natural language processing applications
* Recommendation systems

## Euclidean distance

Euclidean distance measures straight-line distance between points using the Pythagorean theorem. This metric is sensitive to both direction and magnitude, making it suitable for scenarios where the absolute distance matters.

<img src="https://mintcdn.com/actianvectorai/3XmHIEec3Y5mC9ex/images/fundamentals/distance-metrics/euclidean_distance_metric.png?fit=max&auto=format&n=3XmHIEec3Y5mC9ex&q=85&s=52b48a0e558fa6c7a908229d3400bfbe" alt="Diagram showing the straight-line distance between two points in vector space" width="398" height="368" data-path="images/fundamentals/distance-metrics/euclidean_distance_metric.png" />

Euclidean squared omits the square root for faster computation while preserving relative ordering. Use the squared variant when you only need rankings, not absolute distances.

Use Euclidean distance for:

* Image embeddings
* Spatial data
* When magnitude matters
* Performance-critical applications with the squared variant

## Dot product

Dot product measures both alignment and magnitude by summing products of corresponding components. It can be computationally efficient for large-scale applications because it avoids the division and square root operations required by cosine similarity.

<img src="https://mintcdn.com/actianvectorai/3XmHIEec3Y5mC9ex/images/fundamentals/distance-metrics/dot_product_metric.png?fit=max&auto=format&n=3XmHIEec3Y5mC9ex&q=85&s=a7ad0e20c20d768ee2fc190120ba6e2a" alt="Diagram showing how dot product scores increase as two vectors align in direction" width="398" height="368" data-path="images/fundamentals/distance-metrics/dot_product_metric.png" />

As vectors align more closely, the dot product score increases. The following diagram illustrates how changing the angle between vectors affects the resulting score.

<img src="https://mintcdn.com/actianvectorai/3XmHIEec3Y5mC9ex/images/fundamentals/distance-metrics/dot_product_metric_2.png?fit=max&auto=format&n=3XmHIEec3Y5mC9ex&q=85&s=fb1b820c057c564669be0f8ed2a28bf8" alt="Diagram showing the relationship between vector angle and dot product score" width="840" height="281" data-path="images/fundamentals/distance-metrics/dot_product_metric_2.png" />

Dot product ranges from negative infinity to positive infinity. A positive value means the vectors point in the same direction, zero means they are orthogonal, and a negative value means they point in opposite directions. For unit-normalized vectors, the dot product produces the same results as cosine similarity but computes faster because it avoids division and square root operations.

Use dot product for:

* Pre-normalized embeddings
* Embedding models that output normalized vectors
* Large-scale search systems
* Recommendation engines

## Task guides

The following guides show how to configure each distance metric.

* [Cosine similarity](/docs/fundamentals/distance-metrics/cosine-similarity-task).
* [Euclidean distance](/docs/fundamentals/distance-metrics/euclidean-distance-task).
* [Dot product](/docs/fundamentals/distance-metrics/dot-product-task).

## Next steps

* [Collections](/docs/fundamentals/collections/collections) — Organize vectors into named, searchable groups.
* [Indexing](/docs/fundamentals/indexing/indexing) — Optimize search performance with HNSW parameters.
* [Vectors](/docs/fundamentals/vectors/vectors) — Understand vector embeddings.
* [Search operations](/docs/fundamentals/search/search) — Query vectors for similarity.
