pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #728: Query never uses index
3+ messages / 1 participants
[nested] [flat]
* [pgvector/pgvector] issue #728: Query never uses index
@ 2024-12-09 10:34 "QuentinFarizon (@QuentinFarizon)" <noreply+QuentinFarizon@github.com>
0 siblings, 0 replies; 3+ messages in thread
From: QuentinFarizon (@QuentinFarizon) @ 2024-12-09 10:34 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
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
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #728: Query never uses index
@ 2024-12-09 11:13 ` "QuentinFarizon (@QuentinFarizon)" <noreply+QuentinFarizon@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: QuentinFarizon (@QuentinFarizon) @ 2024-12-09 11:13 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Ok, the issue was with my test function empty_vector(), wich returned a non-constant value. With a constant value HNSW is used
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #728: Query never uses index
@ 2024-12-09 11:13 ` "QuentinFarizon (@QuentinFarizon)" <noreply+QuentinFarizon@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: QuentinFarizon (@QuentinFarizon) @ 2024-12-09 11:13 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@QuentinFarizon closed this.
^ permalink raw [nested|flat] 3+ messages in thread
end of thread, other threads:[~2024-12-09 11:13 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-09 10:34 [pgvector/pgvector] issue #728: Query never uses index "QuentinFarizon (@QuentinFarizon)" <noreply+QuentinFarizon@github.com>
2024-12-09 11:13 ` "QuentinFarizon (@QuentinFarizon)" <noreply+QuentinFarizon@github.com>
2024-12-09 11:13 ` "QuentinFarizon (@QuentinFarizon)" <noreply+QuentinFarizon@github.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox