From: mahdimanesh (@mahdimanesh) <noreply+mahdimanesh@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
Date: Mon, 07 Apr 2025 19:53:56 +0000
Message-ID: <gh-pgvector-pgvector-816@github.com> (raw)
Dear all,
**The setup:**
- I am storing embeddings in a table, using pgvector's vector extension (1024 dimensions).
- I also use LangChain (for initial setup or embeddings and collection tables)
- An HSNW index was created; it consumes around 90GB (around 15M records)
- All setup on AWS Aurora Serverless V2 (0...256 ACUs allowed, so 512 GB RAM)
```
CREATE INDEX IF NOT EXISTS titan_dims_1024_idx_cosine
ON public.langchain_pg_embedding
USING hnsw (((embedding)::public.vector(1024)) public.vector_cosine_ops)
WHERE (collection_id = 'my-uuid'::uuid);
```
**The challenge:** I cannot get even a basic query to use the HSNW index. It always falls back to seq scan (EXPLAIN)
```
SELECT *
FROM langchain_pg_embedding
WHERE collection_id = 'my-uuid'
ORDER BY embedding <=> '[my-vector]'
LIMIT 4;
```
```
"Limit (cost=5579931.98..5579932.45 rows=4 width=1528)"
" -> Gather Merge (cost=5579931.98..6905972.03 rows=11365264 width=1528)"
" Workers Planned: 2"
" -> Sort (cost=5578931.96..5593138.54 rows=5682632 width=1528)"
" Sort Key: ((embedding <=> '[my-vector]'::vector))"
" -> Parallel Seq Scan on langchain_pg_embedding (cost=0.00..5493692.48 rows=5682632 width=1528)"
" Filter: (collection_id = 'my-uuid'::uuid)"
```
**What I tried:**
- Enforcing settings with specific settings:
```
SET enable_seqscan = off;
SET maintenance_work_mem = '4GB';
SET effective_cache_size = '32GB';
Setting minimum ACUs to 64 and 128
```
Any input is welcome,
M.