pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #825: Question: HNSW index params
2+ messages / 1 participants
[nested] [flat]

* [pgvector/pgvector] issue #825: Question: HNSW index params
@ 2025-04-21 16:53  "damaon (@damaon)" <noreply+damaon@github.com>
  0 siblings, 0 replies; 2+ messages in thread

From: damaon (@damaon) @ 2025-04-21 16:53 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

I have such query:
```sql
 WITH similarity_candidates AS (
      SELECT id, embedding <=> :embedding AS vector_score
      FROM topic
      WHERE is_recent = true
      ORDER BY embedding <=> :embedding
      LIMIT 500
 )
```
And such index:
```sql
CREATE INDEX CONCURRENTLY idx_topic_embedding_hnsw_recent
ON topic USING hnsw (embedding vector_cosine_ops)
WHERE is_recent = TRUE;
```

When I change to too high ef.search (90), the query planer starts to simply use is_recent index and compute embedding for all candidates (which can be up to 100K) and query is slow (3s+) instead of < 20ms when index triggered.

The problem is that I do further filtering and actually embedding match is most selective from these 100K rows so I need top 500 or even better top 1000 to further filter it later but with default index settings it doesn't work. 

I really searched a lot of internet for some good answer to this issue but it's very hard to get some solid advice that's why I am posting here.

Question:

How should I tweak HNSW index params to make it work well for searching top 500 candidates from 100K rows?

More context:

This is for searching news so data is coming all the time that's why I decided to use partial index that's recomputed and HNSW as it seems to handle data addition better than IVFlat AFAIK. It's also read heavy app. 
My more general question: https://stackoverflow.com/questions/79584189/postgres-query-optimization-partial-indexes

Extra debug info:

`pg_vector` version: `0.5.1`, EDIT: updated to `0.8.0` same issue
`postgres` version: `PostgreSQL 14.17 on x86_64-pc-linux-gnu, compiled by Debian clang version 12.0.1, 64-bit`






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

* Re: [pgvector/pgvector] issue #825: Question: HNSW index params
@ 2025-04-24 09:10  "damaon (@damaon)" <noreply+damaon@github.com>
  0 siblings, 0 replies; 2+ messages in thread

From: damaon (@damaon) @ 2025-04-24 09:10 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@damaon closed this.

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


end of thread, other threads:[~2025-04-24 09:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-04-21 16:53 [pgvector/pgvector] issue #825: Question: HNSW index params "damaon (@damaon)" <noreply+damaon@github.com>
2025-04-24 09:10 Re: [pgvector/pgvector] issue #825: Question: HNSW index params "damaon (@damaon)" <noreply+damaon@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