pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #816: 90GB sized HSNW index not used
7+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
@ 2025-04-07 19:53 "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@github.com>
  0 siblings, 0 replies; 7+ messages in thread

From: mahdimanesh (@mahdimanesh) @ 2025-04-07 19:53 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

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.

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
@ 2025-04-07 19:54 ` "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: mahdimanesh (@mahdimanesh) @ 2025-04-07 19:54 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@mahdimanesh renamed this.

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
@ 2025-04-07 20:14 ` "ankane (@ankane)" <noreply+ankane@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: ankane (@ankane) @ 2025-04-07 20:14 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @mahdimanesh, a few questions:

1. Are you using the same `my-uuid` in the query as the `CREATE INDEX` statement?
2. What's the output of `\d public.langchain_pg_embedding` with psql?

Since you're creating the index with `CREATE INDEX IF NOT EXISTS`, my guess is there may already be an existing index with different options.

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
@ 2025-04-07 20:26 ` "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: mahdimanesh (@mahdimanesh) @ 2025-04-07 20:26 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ankane ,

1. yes, it is (at least, I checked multiple times) : 'f8399948-0726-456a-96f3-a84d90ca945e'::uuid
2. Here you go (screenshot for brevity):

<img width="1481" alt="Image" src="https://github.com/user-attachments/assets/b9a4097e-696e-4791-84f8-01567b7712e4"; />

I did use the "IF NOT EXISTS" as I had an index first created by LangChain, but I dropped it before I did a batch import of all records to speed things up. Could have gotten around without it, actually. Langchain does create all three kinds of indexes up front (I just need cosine, I assume).

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
@ 2025-04-07 20:36 ` "ankane (@ankane)" <noreply+ankane@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: ankane (@ankane) @ 2025-04-07 20:36 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Thanks. Since you're using an expression index, you'll need to include the expression in the query (or the index won't be used).

```sql
ORDER BY embedding::vector(1024) <=> ...
```

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
@ 2025-04-07 20:36 ` "ankane (@ankane)" <noreply+ankane@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: ankane (@ankane) @ 2025-04-07 20:36 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 7+ messages in thread

* Re: [pgvector/pgvector] issue #816: 90GB sized HSNW index not used
@ 2025-04-08 08:03 ` "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@github.com>
  5 siblings, 0 replies; 7+ messages in thread

From: mahdimanesh (@mahdimanesh) @ 2025-04-08 08:03 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

So you mean my query like this is incorrect:

`SELECT *
FROM langchain_pg_embedding
WHERE collection_id = 'my-uuid'
ORDER BY embedding <=> '[my-vector]'
LIMIT 4;`

And I should try...

`SELECT *
FROM langchain_pg_embedding
WHERE collection_id = 'my-uuid'
ORDER BY embedding::vector(1024) <=> '[my-vector]'. -- Explicit typecast?!
LIMIT 4;`

=> Tested and it works! Many thx, @ankane! Saved my day. :-)

^ permalink  raw  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2025-04-08 08:03 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-04-07 19:53 [pgvector/pgvector] issue #816: 90GB sized HSNW index not used "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@github.com>
2025-04-07 19:54 ` "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@github.com>
2025-04-07 20:14 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-04-07 20:26 ` "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@github.com>
2025-04-07 20:36 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-04-07 20:36 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-04-08 08:03 ` "mahdimanesh (@mahdimanesh)" <noreply+mahdimanesh@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