pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: knizhnik (@knizhnik) <noreply+knizhnik@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #259: Understanding HNSW + filtering
Date: Sun, 17 Sep 2023 19:41:45 +0000
Message-ID: <gh-pgvector-pgvector-259-c1722551867@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-259@github.com>
References: <gh-pgvector-pgvector-259@github.com>

Sorry, I do not completely understand your concern.
Assume that you have query mentions above: 
```
SELECT id, text FROM document WHERE category = $1 ORDER BY embedding <-> $2 LIMIT 10;
```
Plan is the following:
```
 Limit  (cost=4.48..51.74 rows=3 width=56)
   ->  Index Scan using document_embedding_idx on document  (cost=4.48..51.74 rows=3 width=56)
         Order By: (embedding <-> '[1,2,3]'::vector)
         Filter: (category = 'first'::text)
```
We ask hens index to return tuples in order of increasing distance and then apply filter until 10 results are found.
So we can 't "end up exhaustively searching the index until we find the best candidate vectors". We will repeat HNSW search once and once again with increased `ef_search` until 10 documents with specified category are found.
There're two main drawbacks:
1. Repeating index search will definitely increase query execution time.
2. Returned results are not always in distance ascending order.
But we can not return i.e. 5 results if there are 10 or more records of the specified category doesn't;t matter how far them are from specified vector.






view thread (90+ messages)  latest in thread

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