From: alanwli (@alanwli) <noreply+alanwli@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #678: Iterative index scans
Date: Fri, 27 Sep 2024 20:25:05 +0000
Message-ID: <gh-pgvector-pgvector-678-c2379999605@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-678@github.com>
References: <gh-pgvector-pgvector-678@github.com>
> @alanwli What's the incorrect semantic here? PostgreSQL has supported K-NN index searches with GiST for more than a decade.
To clarify, I'm referring the semantics of the current discussion - @ankane's branch has the following example query where the outer ORDER BY would be needed because the inner ORDER BY LIMIT may return out of order results, which does not follow SQL semantics.
`WITH approx_order AS MATERIALIZED (
SELECT *, embedding <-> '[1,2,3]' AS distance FROM items WHERE ... ORDER BY distance LIMIT 5
) SELECT * FROM approx_order ORDER BY distance;`