From: daviddanialy (@daviddanialy) <noreply+daviddanialy@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #725: HNSW Index Bypassed Based On Table Size?
Date: Tue, 03 Dec 2024 21:24:09 +0000
Message-ID: <gh-pgvector-pgvector-725@github.com> (raw)
I have two tables with 2000-length vector columns. One table (embeddings) has 13,000 rows and the other (image_prompt_embedding) has 7,500,000. Running the exact same query:
`EXPLAIN SELECT *
FROM embeddings ipe
ORDER BY ipe.sidekick_embedding <-> ${embedding}::vector
LIMIT 5;`
`EXPLAIN SELECT *
FROM image_prompt_embedding ipe
ORDER BY embedding <-> ${embedding}::vector
LIMIT 5;`
on both tables yields different results:
Limit (cost=572.60..573.04 rows=5 width=83)
-> Index Scan using idx_embeddings_vector on embeddings ipe (cost=572.60..1702.65 rows=12964 width=83)
Order By: (sidekick_embedding <-> vector)
Limit (cost=163578.48..163579.07 rows=5 width=50)
-> Gather Merge (cost=163578.48..899400.09 rows=6306602 width=50)
Workers Planned: 2
-> Sort (cost=162578.46..170461.71 rows=3153301 width=50)
Sort Key: ((embedding <-> vector))
-> Parallel Seq Scan on image_prompt_embedding ipe (cost=0.00..110203.26 rows=3153301 width=50)
Both of the HNSW indices were created as such:
`CREATE INDEX idx_name ON table USING hnsw (embedding vector_l2_ops);`
Is this an issue with the table size or something else?