pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: vinodhbalasubramanian (@vinodhbalasubramanian) <noreply+vinodhbalasubramanian@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #671: HNSW + Filter inconsistent result issue (based on HNSW index used vs unused)
Date: Wed, 11 Sep 2024 12:06:47 +0000
Message-ID: <gh-pgvector-pgvector-671@github.com> (raw)

Postgres gives inconsistent result count when it uses the HNSW index vs index not being used.

I am using PGVector HNSW USING hnsw (embedding vector_cosine_ops) WITH (m='16', ef_construction='32');
IFacing an issue with the below sample query 

WITH filtered_opportunities AS (SELECT sf.notice_id FROM opportunity_filter sf 
WHERE 
sf.full_parent_path_name IN ('ABC SERVICE')
//and has_related_award=true // line 2
) 
SELECT sv.notice_id FROM semantic_vector sv  JOIN filtered_opportunities fo ON fo.notice_id = sv.notice_id 
ORDER BY sv.embedding <=> cast('[-0.5078125]’) limit 200

From the above query, It gives me a result count of 30 by having one filter condition, if I add another AND condition (uncomment line 2) it is giving me 200 records (ideally adding more where condition should reduce the resultset). 

The difference in above is, with the first query, it uses HNSW index, so postgres fetches 1000 records from vector table & then apply filter on top of it which reduces the resultset, in the second query postgres doesn't uses HNSW index, so it fetches more records while applying the filter at same time. This is a major issue in our application, where the filters behaves differently based on HNSW index used/not used.

Is this is a Postgres bug? any way to solve this?


view thread (13+ messages)  latest in thread

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