pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: leemeii (@leemeii) <noreply+leemeii@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #1047: IVFFlat validation accepts a halfvec operator class missing required type-info support function 5
Date: Mon, 26 Oct 2026 11:57:18 +0000
Message-ID: <gh-pgvector-pgvector-1047@github.com> (raw)

## Summary

`ivfflatvalidate()` unconditionally returns `true`, allowing an IVFFlat operator class for `halfvec` to be accepted even when it omits the required type-info support function 5.

When the index is subsequently created, `IvfflatGetTypeInfo()` falls back to the default `vector` type callbacks instead of rejecting the incomplete operator class. These callbacks are incompatible with `halfvec`, causing index creation to fail at runtime.

This is a validation correctness issue: an invalid operator class passes validation but cannot safely be used to build an index.

## Steps to reproduce

Run the following SQL against a PostgreSQL instance with pgvector installed.

Save it as `repro_ivfflat_halfvec_typeinfo.sql`:

```sql
CREATE EXTENSION IF NOT EXISTS vector;

-- Clean up objects from a previous run.
DROP TABLE IF EXISTS repro_ivfflat_halfvec_typeinfo CASCADE;

DROP OPERATOR CLASS IF EXISTS
    repro_ivfflat_halfvec_typeinfo USING ivfflat;

-- Create a minimal halfvec table.
CREATE TABLE repro_ivfflat_halfvec_typeinfo (
    v halfvec(2)
);

INSERT INTO repro_ivfflat_halfvec_typeinfo
VALUES ('[1,2]'::halfvec(2));

-- Define an IVFFlat operator class without support function 5.
CREATE OPERATOR CLASS repro_ivfflat_halfvec_typeinfo
FOR TYPE halfvec USING ivfflat AS
    OPERATOR 1 <-> (halfvec, halfvec) FOR ORDER BY float_ops,
    FUNCTION 1 halfvec_l2_squared_distance(halfvec, halfvec),
    FUNCTION 3 l2_distance(halfvec, halfvec);

-- Validation unexpectedly succeeds.
SELECT amvalidate(oid) AS valid
FROM pg_opclass
WHERE opcname = 'repro_ivfflat_halfvec_typeinfo';

-- Index creation is expected to fail because the type-info
-- callback is missing and the default vector callbacks are used.
CREATE INDEX repro_ivfflat_halfvec_typeinfo_idx
ON repro_ivfflat_halfvec_typeinfo
USING ivfflat (v repro_ivfflat_halfvec_typeinfo)
WITH (lists = 1);

-- Cleanup. psql must continue after the expected CREATE INDEX error.
DROP TABLE IF EXISTS repro_ivfflat_halfvec_typeinfo CASCADE;

DROP OPERATOR CLASS IF EXISTS
    repro_ivfflat_halfvec_typeinfo USING ivfflat;
```

Run it with:

```bash
psql -X -d your_database -f repro_ivfflat_halfvec_typeinfo.sql
```

Use the default `psql` error-handling behavior for this demonstration; do not enable `ON_ERROR_STOP`, so the cleanup statements can run after the expected index-creation error.

## Expected behavior

The operator class should be rejected during validation because it lacks the required type-info callback for `halfvec`.

The `amvalidate()` result should be `false`, or the invalid definition should otherwise be rejected before it can be used to create an index.

## Actual behavior

1. The custom operator class is created without support function 5.
2. `amvalidate()` returns `true`.
3. `CREATE INDEX` proceeds into the IVFFlat implementation.
4. `IvfflatGetTypeInfo()` falls back to the default `vector` type callbacks.
5. Index creation fails at runtime because those callbacks are incompatible with `halfvec`.

The validation stage therefore accepts an operator class that cannot safely be used by the access method.



view thread (3+ messages)  latest in thread

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