pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: jkatz (@jkatz) <noreply+jkatz@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #850: LIMIT clause interferes with ORDER BY on vector distance operations
Date: Wed, 04 Jun 2025 13:51:16 +0000
Message-ID: <gh-pgvector-pgvector-850-c2940126105@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-850@github.com>
References: <gh-pgvector-pgvector-850@github.com>

> When using LIMIT with ORDER BY on pgvector distance operations (e.g., embedding <=> ?), the query returns incorrect results that don't respect the distance-based ordering.

This is fundamentally how approximate nearest neighbor (ANN) search works in any vector search system. If PostgreSQL opts use one of the indexes offered through pgvector (IVFFlat or HNSW), you may not get the best possible results for the query (as measured by recall). However, you can still get an exact nearest-neighbor (aka "K-NN") search with pgvector when you have an `ORDER BY` and `LIMIT` if you don't add any of these indexes to the table, or if PostgreSQL choose to use a different search path (which pgvector v0.8.0 greatly simplifies - I noticed you're using v0.7.4).


view thread (4+ messages)

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