From b1d0d4c7a3ea4687a24458e2c278cba93e4af543 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 15 Mar 2024 14:01:24 -0700 Subject: [PATCH] Improved troubleshooting docs [skip ci] --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f653f93..bd5a0f6 100644 --- a/README.md +++ b/README.md @@ -552,7 +552,17 @@ SELECT pg_size_pretty(pg_relation_size('index_name')); #### Why isn’t a query using an index? -The cost estimation in pgvector < 0.4.3 does not always work well with the planner. You can encourage the planner to use an index for a query with: +The query needs to have an `ORDER BY` and `LIMIT`, and the `ORDER BY` must be the result of a distance operator, not an expression. + +```sql +-- index +ORDER BY embedding <=> '[3,1,2]' LIMIT 5; + +-- no index +ORDER BY 1 - (embedding <=> '[3,1,2]') DESC LIMIT 5; +``` + +You can encourage the planner to use an index for a query with: ```sql BEGIN;