EXPLAIN plan.
A Query Does Not Use the Vector Index
A query that uses the vector index hasExec Method: TopKScanExecState in its EXPLAIN plan and no Sort node. When it does not, find the cause here.
The warnings arrive inside a longer message that starts with
Query has LIMIT N but is not using Top K scan.
To make these warnings fail a query in development and CI:
EXPLAIN.
A Query Is Slow
Run the query withEXPLAIN ANALYZE and read the Vector Search group.
Recall Is Low
First measure recall with the same filter andLIMIT the application uses.
Fewer Rows Than the LIMIT
A query ordered by distance can return fewer rows than itsLIMIT for these reasons:
- Rows with a
NULLvector are never returned by a query ordered by distance. - The filter matches fewer rows than the
LIMIT. - A filter in an outer query removed rows after the nearest neighbors were chosen.
Descending Order Returns the Nearest Rows
ORDER BY embedding <=> '...' DESC with a search operator returns the nearest rows, in ascending order of distance. Farthest-first ordering is not supported by the vector index. To get it, remove the search operator so that Postgres sorts the rows.