pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
11+ messages / 3 participants
[nested] [flat]

* [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 07:40 "SteveLauC (@SteveLauC)" <noreply+SteveLauC@github.com>
  0 siblings, 0 replies; 11+ messages in thread

From: SteveLauC (@SteveLauC) @ 2024-10-10 07:40 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi, thanks for this amazing extension!

Looking at the source code, I noticed that [the dimension check will be skipped](https://github.com/pgvector/pgvector/blob/fa6782985ab9fd6c3f289196b7cf3053c1d46eef/src/vector.c#L65-...) if the `typmod` argument of the text input function is `-1`, I am thinking, shouldn't this `typmod` be always given and the check of the input value be always performed? 🤔

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 07:44 ` "ankane (@ankane)" <noreply+ankane@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: ankane (@ankane) @ 2024-10-10 07:44 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 07:44 ` "ankane (@ankane)" <noreply+ankane@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: ankane (@ankane) @ 2024-10-10 07:44 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @SteveLauC, `-1` means it's a [variable-dimension column](https://github.com/pgvector/pgvector?tab=readme-ov-file#can-i-store-vectors-with-different-dimension...).

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 07:47 ` "SteveLauC (@SteveLauC)" <noreply+SteveLauC@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: SteveLauC (@SteveLauC) @ 2024-10-10 07:47 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi, thanks for the quick response!

So if I am not using a variable-dimension column, with a fixed-dimension column, is it possible that `typmod` could be `-1`?

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 07:49 ` "ankane (@ankane)" <noreply+ankane@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: ankane (@ankane) @ 2024-10-10 07:49 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

That shouldn't be possible.

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 07:50 ` "SteveLauC (@SteveLauC)" <noreply+SteveLauC@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: SteveLauC (@SteveLauC) @ 2024-10-10 07:50 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Get it, thanks for the reply.

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 16:56 ` "workingjubilee (@workingjubilee)" <noreply+workingjubilee@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: workingjubilee (@workingjubilee) @ 2024-10-10 16:56 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

It is possible, Tom Lane said so: https://www.postgresql.org/message-id/28121.1237251420%40sss.pgh.pa.us

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 17:25 ` "workingjubilee (@workingjubilee)" <noreply+workingjubilee@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: workingjubilee (@workingjubilee) @ 2024-10-10 17:25 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Specifically, because I am having trouble getting people to read what he posted:
For every SQL statement in a form like
```sql
insert into foo values ('[1]');
```

It is **not always** implemented via:
1. determine typmod for foo's columns
2. call `TYPE_IN` with determined typmod

It **can also** be implemented via:
1. call `TYPE_IN` with typmod -1
2. **cast** input types when performing insert


The latter is the behavior Tom Lane describes as not only common but _more prevalent_ in the Postgres codebase at the time. While Postgres has likely changed its internals, proving that Postgres NEVER does the input-then-cast behavior would require auditing every site at which Postgres does these kinds of type conversions.

@ankane What you did not know in answering this question is that Steve is actually asking the question, "can I ALWAYS ASSERT (and thus ereport if failed) that the `TYPE_IN` function is provided a non-`(-1)` typmod, and fail to create the type if it is not provided one?" That is not the behavior that pgvector has, your source code does not assert if you do this, as it specifically skips the assert:

https://github.com/pgvector/pgvector/blob/fa6782985ab9fd6c3f289196b7cf3053c1d46eef/src/vector.c#L65-...

In doing so, you implement a behavior actually compatible with Postgres. This may be more critical than you may imagine.

So have you actually tried to run pgvector in production with an assertion that demands the typmod on every call to the type's input function, or were you just answering off-the-cuff?

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 17:40 ` "ankane (@ankane)" <noreply+ankane@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: ankane (@ankane) @ 2024-10-10 17:40 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

The typmod is what differentiates fixed vs variable, so if it's `-1`, it's considered variable.

Postgres can pass `-1` to the `INPUT` function and then cast, which is why the code handles that case.

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 17:54 ` "workingjubilee (@workingjubilee)" <noreply+workingjubilee@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: workingjubilee (@workingjubilee) @ 2024-10-10 17:54 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Thank you for clarifying.

Sorry to bother, I just get questions from people who are new to writing Postgres extensions a lot as part of fielding questions about how to write something using pgrx. Then these discussions spill out weirdly when people refuse to believe that Postgres does things in counterintuitive way sometimes (or at least, "however it damn well wants").

^ permalink  raw  [nested|flat] 11+ messages in thread

* Re: [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1`
@ 2024-10-10 23:47 ` "SteveLauC (@SteveLauC)" <noreply+SteveLauC@github.com>
  9 siblings, 0 replies; 11+ messages in thread

From: SteveLauC (@SteveLauC) @ 2024-10-10 23:47 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi, thanks both for your time and reply, really appreciate the help. ♥️

^ permalink  raw  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2024-10-10 23:47 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-10-10 07:40 [pgvector/pgvector] issue #693: Question: why is pgvector skipping vector dimenstion check when `typmod` is `-1` "SteveLauC (@SteveLauC)" <noreply+SteveLauC@github.com>
2024-10-10 07:44 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-10 07:44 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-10 07:47 ` "SteveLauC (@SteveLauC)" <noreply+SteveLauC@github.com>
2024-10-10 07:49 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-10 07:50 ` "SteveLauC (@SteveLauC)" <noreply+SteveLauC@github.com>
2024-10-10 16:56 ` "workingjubilee (@workingjubilee)" <noreply+workingjubilee@github.com>
2024-10-10 17:25 ` "workingjubilee (@workingjubilee)" <noreply+workingjubilee@github.com>
2024-10-10 17:40 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-10 17:54 ` "workingjubilee (@workingjubilee)" <noreply+workingjubilee@github.com>
2024-10-10 23:47 ` "SteveLauC (@SteveLauC)" <noreply+SteveLauC@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