pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #740: HNSW index returns different values when adding a where condition
3+ messages / 2 participants
[nested] [flat]
* [pgvector/pgvector] issue #740: HNSW index returns different values when adding a where condition
@ 2024-12-28 02:33 "sieudx (@sieudx)" <noreply+sieudx@github.com>
0 siblings, 0 replies; 3+ messages in thread
From: sieudx (@sieudx) @ 2024-12-28 02:33 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
My table: pg_embedding_question_answers
Column: embedding, document, cmetadata,id, document_id
Query 1:
SELECT document, cmetadata, (embedding::halfvec(1024) <-> :vector) AS distance
FROM pg_embedding_question_answers
WHERE (embedding::halfvec(1024) <-> :vector) <= :threshold
ORDER BY distance
LIMIT :limit
Query 2:
SELECT document, cmetadata, (embedding::halfvec(1024) <-> :vector) AS distance
FROM pg_embedding_question_answers
WHERE (embedding::halfvec(1024) <-> :vector) <= :threshold
AND document_id = :document_id
ORDER BY distance
LIMIT :limit
I execute 2 queries with the same input parameters
Vector version: 0.7.2
Result query 1: always returns 48 records no matter what limit value I set, and can't get the record with the smallest distance value

Result query 2: Returns the correct value according to limit and gets the value with the smallest distance

I don't know why, and how to fix the query so that query 1 can get the smallest value and the records return according to the parameter of limit
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #740: HNSW index returns different values when adding a where condition
@ 2024-12-29 15:37 ` "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2024-12-29 15:37 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @sieudx, it sounds like the second query isn't using an approximate index (you can use `EXPLAIN ANALYZE` to confirm). Removing the approximate index will give exact results for the first query. Also, check out the [troubleshooting docs](https://github.com/pgvector/pgvector?tab=readme-ov-file#why-are-there-less-results-for-a-query-after...) for more info.
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #740: HNSW index returns different values when adding a where condition
@ 2024-12-29 15:37 ` "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2024-12-29 15:37 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane closed this.
^ permalink raw [nested|flat] 3+ messages in thread
end of thread, other threads:[~2024-12-29 15:37 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-28 02:33 [pgvector/pgvector] issue #740: HNSW index returns different values when adding a where condition "sieudx (@sieudx)" <noreply+sieudx@github.com>
2024-12-29 15:37 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-12-29 15:37 ` "ankane (@ankane)" <noreply+ankane@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