pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: hlinnaka (@hlinnaka) <noreply+hlinnaka@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #702: Index not used when using a WITH expression
Date: Mon, 28 Oct 2024 12:50:07 +0000
Message-ID: <gh-pgvector-pgvector-702-c2441501620@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-702@github.com>
References: <gh-pgvector-pgvector-702@github.com>

In short, the planner doesn't know how to generate the query plan that you'd expect. It doesn't know how to transform the join between 'incident_embedding' and 'v' into "look up the single row with the given incident_id first, and then use that in the distance calculation".

You could write it more explicitly like that though. I think something like this would work:
```
EXPLAIN WITH v AS (SELECT embedding as vec FROM incident_embedding WHERE incident_id = 2491825880941960244)
  SELECT *, embedding <=> (SELECT v.vec from v) as distance FROM incident_embedding ORDER BY 2 LIMIT 5;
```


view thread (4+ messages)  latest in thread

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