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

# Vector distance functions

> cosine_distance, distance, exact_distance and inner_product: per-row vector distance, and the ORDER BY rewrite into vector search.

**Applies to:** Embedded ❌, Enterprise ✅

```text theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
cosine_distance  distance  exact_distance  inner_product
```

> [!WARNING]
>
> Distance functions can evaluate arrays per row. Some deployment versions also
> recognize `ORDER BY distance(vector, query_vector) LIMIT k` over a table scan
> and plan it as vector search, with indexed or flat search as appropriate.
> Where available, `exact_distance` evaluates distance without that rewrite.
> Confirm the functions supported by your deployment and inspect SQL
> [`EXPLAIN`](https://docs.lancedb.com/sql/dql/explain); the function name alone does not guarantee an
> index-backed plan. See [SQL vector search](https://docs.lancedb.com/basics/sql.md#no-vector-sql).

A third, optional argument is a comma-separated options string, and only
`distance` and `exact_distance` accept one; `cosine_distance` and
`inner_product` are plain two-argument functions. `metric` selects `l2`
(default, alias `euclidean`), `cosine`, or `dot`. `nprobes` and `use_index`
only affect `distance`, since it's the only one of the two that the
index-search rewrite applies to in the first place -- `exact_distance` is
never rewritten into an index search, so passing it `use_index`/`nprobes`
does nothing; use a plain `distance` call with `use_index=false` to force a
flat scan instead:

```sql SQL icon="database" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
SELECT id FROM documents
ORDER BY distance(embedding, ARRAY[0.1, 0.2, 0.3], 'metric=cosine,nprobes=20')
LIMIT 10

-- Force a flat scan, bypassing the index:
SELECT id FROM documents
ORDER BY distance(embedding, ARRAY[0.1, 0.2, 0.3], 'use_index=false')
LIMIT 10
```

## What to read next

> [card] [SQL vector search](https://docs.lancedb.com/basics/sql.md#no-vector-sql)
>
> Server-version requirements and the supported `ORDER BY` query forms.

> [card] [EXPLAIN](https://docs.lancedb.com/sql/dql/explain.md)
>
> Confirm whether a query planned as an index-backed vector search.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.