Why SQLSTATE 54000 Triggers on vector and Metadata Columns
Standard PostgreSQL B-tree pages enforce BTMaxItemSize (~2,704 bytes) and IndexTuple hard page limits (8,191 bytes). ORM migrations (Prisma, Drizzle, SQLAlchemy, Django) frequently generate a default B-tree index (CREATE INDEX ON chunks (tenant_id, embedding)) or UNIQUE (content, embedding) instead of USING hnsw. Any vector(3072) (12,288 bytes) or unchunked metadata blob immediately trips maximum size is 8191.
Immediate SQL Fix: Split Tenant B-Tree Keys From halfvec HNSW
-- 1. Inspect and drop accidental B-tree or INCLUDE indexes touching embedding/content
SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'doc_chunks';
DROP INDEX IF EXISTS idx_doc_chunks_embedding_btree;
-- 2. Enforce uniqueness via a 32-byte SHA-256 digest instead of raw text/vector B-tree
ALTER TABLE doc_chunks ADD COLUMN IF NOT EXISTS content_sha256 bytea
GENERATED ALWAYS AS (digest(content, 'sha256')) STORED;
CREATE UNIQUE INDEX CONCURRENTLY idx_chunks_tenant_sha ON doc_chunks (tenant_id, content_sha256);
-- 3. Index the vector solely via HNSW halfvec
CREATE INDEX CONCURRENTLY idx_chunks_hnsw
ON doc_chunks USING hnsw ((embedding::halfvec(3072)) halfvec_cosine_ops);
Offload Vector Storage From Your OLTP PostgreSQL Primary
Keeping 12 KB vector tuples inside transactional PostgreSQL bloats VACUUM, WAL replication, and buffer cache eviction. Keep relational user state in Postgres and route embeddings plus cited retrieval to Voxell Forge ($0 Turbo 1024d, $39/mo Builder annual with 5 GB durable vector storage).