Migrate vector to halfvec
migrate_vector_to_halfvecGenerate an ordered DDL plan to convert a pgvector vector(N) column to halfvec(N), halving element storage, with index drop/recreate 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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"schema": "<schema>",
"table": "<table>",
"column": "<column>"
},
"name": "migrate_vector_to_halfvec"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | ||
| column | Yes | ||
| schema | Yes | ||
| database | No | Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected. |
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 |