pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: sieudx (@sieudx) <noreply+sieudx@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #740: HNSW index returns different values ​​when adding a where condition
Date: Sat, 28 Dec 2024 02:33:01 +0000
Message-ID: <gh-pgvector-pgvector-740@github.com> (raw)

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

![image](https://github.com/user-attachments/assets/d9914542-5953-4556-be24-2350d5b8adb3)


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

![image](https://github.com/user-attachments/assets/c9e8463c-afa8-4fb1-8edb-ea4d925d8c94)

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



view thread (3+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-740@github.com>
Permalink:  ../gh-pgvector-pgvector-740@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