pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #641: Cant use DISTINCT ON
6+ messages / 3 participants
[nested] [flat]
* [pgvector/pgvector] issue #641: Cant use DISTINCT ON
@ 2024-08-11 02:01 "mfandre (@mfandre)" <noreply+mfandre@github.com>
0 siblings, 0 replies; 6+ messages in thread
From: mfandre (@mfandre) @ 2024-08-11 02:01 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Always receive the follow error: _SQL Error [42P10]: ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions_
```
SELECT distinct on (embedding, path) path
FROM chunks
ORDER BY embedding <=> '[0.00581426,-0.0013586936,0.009351607,-0.0007560063,...]',path
LIMIT 3
```
<img width="874" alt="image" src="https://github.com/user-attachments/assets/fcd3c8ae-a42f-4603-8108-561a1098b1b7";
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #641: Cant use DISTINCT ON
@ 2024-08-11 02:32 "ankane (@ankane)" <noreply+ankane@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: ankane (@ankane) @ 2024-08-11 02:32 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @mfandre, this error isn't specific to pgvector. Please use other resources for help.
https://www.postgresql.org/docs/current/sql-select.html#SQL-DISTINCT
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #641: Cant use DISTINCT ON
@ 2024-08-11 02:32 "ankane (@ankane)" <noreply+ankane@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: ankane (@ankane) @ 2024-08-11 02:32 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane closed this.
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #641: Cant use DISTINCT ON
@ 2024-08-12 12:58 "mfandre (@mfandre)" <noreply+mfandre@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: mfandre (@mfandre) @ 2024-08-12 12:58 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane I disagree, it worked perfectly when it used without embbeding order by. The problem is something relationed in how oder by embbeding is constructed behind de scenes.
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #641: Cant use DISTINCT ON
@ 2024-08-12 13:44 "jkatz (@jkatz)" <noreply+jkatz@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: jkatz (@jkatz) @ 2024-08-12 13:44 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@mfandre What you described above is a different type of query. With your first query:
```sql
SELECT DISTINCT ON (embedding, path) path
FROM chunks
ORDER BY embedding <=> '[...]'
LIMIT 3
```
your `ORDER BY` clause is calculating the distance between `embedding` and a query vector, whereas your projection (`DISTINCT ON`) is using just the value of `embedding`.
If you want to use `DISTINCT ON` using the distance, you would write it with something like this (untested):
```sql
SELECT DISTINCT ON (distance, path)
embedding <=> '[...]' AS distance, path
FROM chunks
ORDER BY distance
LIMIT 3;
```
though (again untested in this case) I don't see the difference between that and using `DISTINCT`.
For the second query, the reason it worked is because you don't have to account for ordering. As it says in the docs that @ankane referenced:
> ...[DISTINCT ON] keeps only the first row of each set of rows where the given expressions evaluate to equal.
so because order matters, the values in `DISTINCT ON` must match the same values provided in order in the `ORDER BY` clause.
^ permalink raw [nested|flat] 6+ messages in thread
* Re: [pgvector/pgvector] issue #641: Cant use DISTINCT ON
@ 2024-08-12 17:13 "mfandre (@mfandre)" <noreply+mfandre@github.com>
4 siblings, 0 replies; 6+ messages in thread
From: mfandre (@mfandre) @ 2024-08-12 17:13 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Makes sense, Thx for explanation!
^ permalink raw [nested|flat] 6+ messages in thread
end of thread, other threads:[~2024-08-12 17:13 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-08-11 02:01 [pgvector/pgvector] issue #641: Cant use DISTINCT ON "mfandre (@mfandre)" <noreply+mfandre@github.com>
2024-08-11 02:32 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-08-11 02:32 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-08-12 12:58 ` "mfandre (@mfandre)" <noreply+mfandre@github.com>
2024-08-12 13:44 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-08-12 17:13 ` "mfandre (@mfandre)" <noreply+mfandre@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