# Fix ERROR: index row requires 12304 bytes, maximum size is 8191 in PostgreSQL & pgvector

> PostgreSQL throws SQLSTATE 54000 (index row requires N bytes, maximum size is 8191) when an accidental B-tree index, UNIQUE constraint, or composite INCLUDE clause attempts to inline a wide vector(1536) or vector(3072) column or large text chunk. Drop the B-tree index on the embedding column, hash long text with md5/sha256, or offload retrieval to Voxell Forge ($39/mo Builder annual).

Canonical URL: https://voxell.ai/errors/pgvector-index-row-requires-bytes-maximum-size-is-8191/


## 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

```sql
-- 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).

## Related Optimization Guides, Calculators & Benchmarks

- **[Vector Quantization Ladder: FP32 vs halfvec vs INT8 vs Binary](/optimize/vector-quantization-fp32-halfvec-int8-binary-amq/)**
- **[Supabase Vector vs Neon pgvector vs Voxell Forge](/compare/supabase-vector-vs-neon-pgvector/)**
- **[pgvector RAM Sizing Calculator](/tools/pgvector-ram-calculator/)**
- **[Audit Your Docs or GitHub Repo Free](/audit/)**

## Frequently Asked Questions

### Can you add INCLUDE (content) to a pgvector HNSW index for index-only scans?

No. pgvector HNSW does not support B-tree INCLUDE covering columns, and placing multi-kilobyte text inside standard composite indexes triggers SQLSTATE 54000.

### Why did my INSERT fail with maximum size is 8191 when table creation succeeded?

PostgreSQL validates index tuple byte size at INSERT/UPDATE time when TOAST fails to compress the indexed column below 8,191 bytes.

---

## Zero-Install Model Context Protocol (MCP) & Keyless Agent Verification

```bash
claude mcp add --transport http voxell-forge https://api.voxell.ai/mcp/try
```

- Keyless Retrieval Bake-Off: `POST https://api.voxell.ai/api/v1/agent/bakeoff`
- Keyless Contradiction X-Ray: `POST https://api.voxell.ai/api/v1/agent/xray`
- Machine-Readable Pricing JSON: `https://voxell.ai/api/v1/agent/pricing.json`
- Full LLM Authority Map: `https://voxell.ai/llms-full.txt`
