From: QuentinFarizon (@QuentinFarizon) <noreply+QuentinFarizon@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #728: Query never uses index
Date: Mon, 09 Dec 2024 10:34:20 +0000
Message-ID: <gh-pgvector-pgvector-728@github.com> (raw)
I'm using L2 distance on a column of type vector(1536). I have 144K products (100K where embedding is not null)
I have added these indexes :
create index t21 on products using hnsw (embedding vector_l2_ops);
create index t22 on products using ivfflat (embedding vector_l2_ops) WITH (lists = 100);
Here is the simplest query :
```
cty=# explain (analyze, settings) select * from products order by embedding <-> empty_vector() ASC LIMIT 5;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------
Limit (cost=93891.37..93891.38 rows=5 width=2982) (actual time=16312.479..16312.481 rows=5 loops=1)
-> Sort (cost=93891.37..94252.77 rows=144561 width=2982) (actual time=16312.477..16312.478 rows=5 loops=1)
Sort Key: ((embedding <-> empty_vector()))
Sort Method: top-N heapsort Memory: 45kB
-> Seq Scan on products (cost=0.00..91490.26 rows=144561 width=2982) (actual time=0.252..16180.368 rows=144561 loops=1)
Planning Time: 0.801 ms
Execution Time: 16312.519 ms
(7 rows)
```
Indexes are never used.
I have tried setting `SET LOCAL enable_seqscan = off;` with no change
And also "ALTER TABLE products ALTER COLUMN embedding SET STORAGE PLAIN;" with no change