From: WalidMustapha (@WalidMustapha) <noreply+WalidMustapha@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #760: HNSW Index Not Used When Combining ORDER BY Distance with Deduplication
Date: Sat, 18 Jan 2025 22:07:06 +0000
Message-ID: <gh-pgvector-pgvector-760-c2600160402@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-760@github.com>
References: <gh-pgvector-pgvector-760@github.com>
Appreciate you taking the time to reply.
You are correct, it does fail. I missed the 'id'.
```
WITH vector_search AS (
SELECT *
FROM table
ORDER BY vector_column <-> query_vector
LIMIT {increased_limit}
)
SELECT DISTINCT ON (id) *
FROM vector_search
ORDER BY id, vector_distance
```