pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #394: Question regarding HNSW
5+ messages / 4 participants
[nested] [flat]
* [pgvector/pgvector] issue #394: Question regarding HNSW
@ 2024-01-03 15:17 "nikhilshinday (@nikhilshinday)" <noreply+nikhilshinday@github.com>
0 siblings, 0 replies; 5+ messages in thread
From: nikhilshinday (@nikhilshinday) @ 2024-01-03 15:17 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
I'm having trouble finding the right parameters for an hnsw index. Here's the rough outline of my table ontology:
```
vectorized_document {
id: bigint pk
text: text
embedding: vector(n)
index: vectorized_document_embedding_idx hnsw (embedding vector_cosine_ops)
}
vectorized_document_relationship {
vectorized_document_id: bigint fk
call_monologue_id: bigint fk
call_summary_id: bigint fk
}
call_monologue {
id: bigint pk
text: text
call_id: bigint fk
}
call_summary {
id: bigint pk
text: text
call_id: bigint fk
}
call {
id: bigint pk
organization_id: bigint fk
}
```
Users belong to an organization id, which means that we have a permission filter in all queries that goes something like:
```sql
select vectorized_document.* from vectorized_document
left join vectorized_document_relationship
left join call_monologue
left join call_summary
where
call_monologue.call_id in (select id from call where organization_id = session.user.organization_id
or
call_summary.call_id in (select id from call where organization_id = session.user.organization_id
order by embedding <> '[....n long vector]';
```
given what I know about HNSW and the postgres query planner, it seems like, roughly, the query planner would filter down to a subset of vectorized_document IDs based on the access query and then do the ordering on those vectorized document based on the embedding column's HNSW index. The problem I see is that, since the index is built up without knowledge of the access pattern that is being used, there will be less qualified neighbors at each "small world" of vectors, which means we're _really_ likely to miss out on vectors and less results will be returned. I validated that for the above query, values are returned when I don't use semantic vector-based ordering, and values aren't returned when I use that ordering.
My question is: would jacking up the `m` parameter make sense here? My guess is that it would work, but that it would also create a ton of unnecessary neighbors for vectors that will never be compared to each other.
Broader picture, is there _any_ index that would be appropriate here? It seems like a lot of these indexes are based on the assumption that the access pattern for a table will always be a direct query.
^ permalink raw [nested|flat] 5+ messages in thread
* Re: [pgvector/pgvector] issue #394: Question regarding HNSW
@ 2024-01-04 16:41 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
3 siblings, 0 replies; 5+ messages in thread
From: jkatz (@jkatz) @ 2024-01-04 16:41 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
The work in the [https://github.com/pgvector/pgvector/tree/hqann](https://github.com/pgvector/pgvector/tree/hqann) branch may benefit your access pattern -- the gist of it is that you can build vector indexes that include scalar (e.g. `call_id`) values and be able to perform a more precise prefiltering over the data.
^ permalink raw [nested|flat] 5+ messages in thread
* Re: [pgvector/pgvector] issue #394: Question regarding HNSW
@ 2024-01-05 23:51 ` "ankane (@ankane)" <noreply+ankane@github.com>
3 siblings, 0 replies; 5+ messages in thread
From: ankane (@ankane) @ 2024-01-05 23:51 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hey @nikhilshinday, I'm not sure increasing `m` will help here, but shouldn't be too hard to try. I think you'll probably see the best results by adding `organization_id` to `vectorized_document` (denormalizing it) and using one of [these methods](https://github.com/pgvector/pgvector#filtering) for filtering.
^ permalink raw [nested|flat] 5+ messages in thread
* Re: [pgvector/pgvector] issue #394: Question regarding HNSW
@ 2024-01-11 00:39 ` "ankane (@ankane)" <noreply+ankane@github.com>
3 siblings, 0 replies; 5+ messages in thread
From: ankane (@ankane) @ 2024-01-11 00:39 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane closed this.
^ permalink raw [nested|flat] 5+ messages in thread
* Re: [pgvector/pgvector] issue #394: Question regarding HNSW
@ 2024-09-18 09:25 ` "kolafish (@kolafish)" <noreply+kolafish@github.com>
3 siblings, 0 replies; 5+ messages in thread
From: kolafish (@kolafish) @ 2024-09-18 09:25 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Will this branch merge to master?
^ permalink raw [nested|flat] 5+ messages in thread
end of thread, other threads:[~2024-09-18 09:25 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03 15:17 [pgvector/pgvector] issue #394: Question regarding HNSW "nikhilshinday (@nikhilshinday)" <noreply+nikhilshinday@github.com>
2024-01-04 16:41 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-01-05 23:51 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-01-11 00:39 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-09-18 09:25 ` "kolafish (@kolafish)" <noreply+kolafish@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