## TL;DR

Ordering by the wrong distance function gives the warning ANN index not used: not ordering by COSINE distance.

## Fix

1. Ordering by the wrong distance function gives the warning ANN index not used: not ordering by COSINE distance.
   Expected: you can confirm this matches your situation.

## When to use

- You are setting up or using this TiDB vector index feature.
- The symptom matches: SHOW WARNINGS explains why the ANN index was not used.

## When NOT to use

- Unrelated TiDB vector index issues (different feature, different failure).
- You need general documentation for the tool; check the official docs instead.

## Compatibility

Reported against TiDB vector index. Source: https://docs.pingcap.com/tidb/dev/vector-search-index/.

## Variant phrasings

### SHOW WARNINGS explains why the ANN index was not used

## Why it happens

When the vector index cannot be used, TiDB emits a warning naming the cause. Check warnings right after EXPLAIN.

## Edge cases

- If your error message differs even slightly, this is probably a different issue; search the exact text.
- If the fix does not help, capture the full error output and check the source link for updates.

## Source

https://docs.pingcap.com/tidb/dev/vector-search-index/