# Fixing ERROR: column cannot have more than 2000 dimensions in pgvector HNSW

> Source: <https://dev.to/jcorners68/fixing-error-column-cannot-have-more-than-2000-dimensions-in-pgvector-hnsw-3dj5>
> Published: 2026-12-03 20:43:05+00:00

**Recommendation:** When indexing embeddings above 2,000 dimensions in pgvector, build a halfvec expression index and repeat the identical cast in every query, or the planner will silently sequential-scan.
More in the playbook "Retrieval and RAG": <https://wpnews.pro/playbooks/rag-retrieval>

If you migrate a PostgreSQL Retrieval-Augmented Generation (RAG) table from `1536`-dimensional embeddings to `3072`-dimensional vectors (` text-embedding-3-large` or `gemini-embedding-001`) and build an HNSW index, PostgreSQL immediately aborts DDL execution:

```
ERROR: column cannot have more than 2000 dimensions for hnsw index
```

The same hard ceiling hits `ivfflat` (`ERROR: column cannot have more than 2000 dimensions for ivfflat index`). Here is why PostgreSQL enforces that page-size limit and the three production ways to fix it without losing retrieval recall.

`vector` Indexes at 2,000 Dimensions
PostgreSQL uses a fixed `8 KB` (`8,192`-byte) heap and index page size by default. An uncompressed 32-bit float (`vector(3072)`) consumes `3,072 * 4 = 12,288` bytes (`12 KB`) per tuple before index graph pointers and tuple headers. Because a single index tuple must fit inside an `8 KB` page without TOAST out-of-line indirection during HNSW graph traversal, `pgvector` caps standard FP32 `vector` index columns at `2,000` dimensions (`8,000` bytes).

`halfvec` FP16 Expression Indexing (`pgvector >= 0.7.0`)
Casting `vector(3072)` to 16-bit floats (`halfvec(3072)`) halves storage to `6,144` bytes per tuple, raising the HNSW limit to `4,000` dimensions:

```
CREATE INDEX CONCURRENTLY idx_chunks_emb_hnsw_fp16
ON doc_chunks
USING hnsw ((embedding::halfvec(3072)) halfvec_cosine_ops)
WITH (m = 16, ef_construction = 128);

-- Every SELECT ORDER BY must repeat the exact cast so the planner uses the index:
SELECT chunk_id, content
FROM doc_chunks
ORDER BY (embedding::halfvec(3072)) <=> $1::halfvec(3072)
LIMIT 20;
```

Watch out for query planner drift: if an ORM, **Model Context Protocol (MCP)** tool server, or **Agent2Agent (A2A)** service queries `embedding <=> $1` without the explicit `::halfvec(3072)` cast, PostgreSQL silently falls back to a sequential scan.

`<= 2000d`)
Matryoshka Representation Learning (MRL) concentrates coarse-to-fine semantic variance into leading vector coordinates so you can store native `vector(1024)` or `vector(1536)` columns directly in `pgvector` HNSW with zero cast gymnastics.

However, truncating a `3072d` vector on the client without L2 re-normalization breaks inner-product indexes. In empirical probes on `gemini-embedding-001` (`3072d` truncated to `768d`), the prefix L2 norm drops to `0.5841`, collapsing unnormalized dot products from `0.8111` to `0.2793`.

[**Voxell Forge**](https://voxell.ai/forge/) handles both paths cleanly:

`turbo` (`1024d` native, `$0/forever`):` pgvector` FP32 `vector(1024)` HNSW natively at `4 KB` per vector with zero casting.`pro` (`2560d` native, `$0.25/1M` tokens):`1536d`) with automatic unit-norm L2 re-normalization, or indexes at full `halfvec(2560)` (`5 KB` per tuple). Paired with `C_corpus` zero-LLM ingest conditioning, `Pro` reaches `99.04%` Stage-1 `Recall@20` and `0.8849 nDCG@10` with two-stage `Max` neural reranking.

``` python
from openai import OpenAI

client = OpenAI(base_url="https://api.voxell.ai/v1", api_key="FORGE_API_KEY")

# Returns server-side L2-normalized 1536d vectors ready for native pgvector HNSW
res = client.embeddings.create(
    model="pro",
    input=["PostgreSQL HNSW page layout and tuple headers"],
    dimensions=1536,
)
```

| Configuration | Bytes / Vector | Raw Vector RAM (10M) | Native `vector` HNSW | Recall & Rerank Notes | 
|---|---|---|---|---|
| `vector(3072)` FP32 | `12,288 B` | `122.9 GB` | Fails ( `> 2000d` ) | Sequential scan only unless cast | 
| `halfvec(2560)` FP16 (`Forge Pro` ) | `5,120 B` | `51.2 GB` | Supported ( `<= 4000d` ) | `99.04% Recall@20` (`C_corpus` ) +`0.8849 nDCG@10` (`Max` ) | 
| `vector(1536)` FP32 MRL (`Forge Pro` ) | `6,144 B` | `61.4 GB` | Supported ( `<= 2000d` ) | Server-side L2 re-normalized unit vector | 
| `vector(1024)` FP32 (`Forge Turbo` ) | `4,096 B` | `41.0 GB` | Supported ( `<= 2000d` ) | `$0/forever` embedding tier |
