Migrate vector to halfvec
migrate_vector_to_halfvecGenerate a DDL plan to convert a pgvector vector(N) column to halfvec(N), halving per-element storage with minimal recall impact. Includes index handling and rollback SQL.
Instructions
Generate a DDL plan that converts a pgvector vector(N) column to halfvec(N) — halving per-element storage (4 → 2 bytes) with typically negligible recall impact at d ≥ 768. Reads the column's current type + dimension from the catalog, finds every index on the column, and emits an ordered migration_sql plan: DROP each affected index, ALTER COLUMN to halfvec(N) via a USING cast, then recreate each index with its halfvec opclass. Also returns a mirror rollback_sql that restores the original vector(N) type plus the original index definitions. Nothing is executed — feed the plan through the shadow-migration workflow (prepare_migration / validate_migration_schema) before applying. Returns already_halfvec=true (and an empty plan) when the column is already halfvec, and refuses any index whose opclass has no halfvec sibling rather than rewriting it incorrectly. Requires the vector extension.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | ||
| column | Yes | ||
| schema | Yes | ||
| database | No | Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notes | Yes | ||
| indexes | Yes | ||
| available | Yes | ||
| dimension | Yes | ||
| row_count | Yes | ||
| column_type | Yes | ||
| rollback_sql | Yes | ||
| migration_sql | Yes | ||
| already_halfvec | Yes | ||
| estimated_total_bytes_saved | Yes | ||
| estimated_bytes_per_row_after | Yes | ||
| estimated_bytes_per_row_before | Yes |