From: ankane (@ankane) <noreply+ankane@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #781: index not used with cte
Date: Sat, 22 Feb 2025 18:27:57 +0000
Message-ID: <gh-pgvector-pgvector-781-c2676339746@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-781@github.com>
References: <gh-pgvector-pgvector-781@github.com>
As I mentioned earlier, there's not much pgvector can do if the planner isn't considering the index. You'll need to write the query in a way where the planner does consider it (or get this changed in the planner code).
```sql
EXPLAIN ANALYZE WITH vars AS (
SELECT chunk_embedding AS qvt_embedding FROM dbpedia_14 WHERE chunk_index = 473679
)
SELECT a.title, (SELECT qvt_embedding FROM vars) <-> a.chunk_embedding AS l2distance
FROM dbpedia_14 a ORDER BY l2distance LIMIT 10;
```