Database / pgvector basics Interview Questions
What is the pgvector maximum supported dimensions limit and how do you handle high-dimensional vectors?
pgvector has dimension limits that vary by data type. These limits are generous for current embedding models but may be a consideration for future or custom embeddings.
| Type | Max dimensions | Notes |
|---|---|---|
| vector(n) | 16,000 | Standard; covers OpenAI (1536/3072), most models |
| halfvec(n) | 16,000 | Half-precision; same dim limit, half storage |
| bit(n) | 64,000 | Binary quantised; very high dimension support |
| sparsevec(n) | 1,000,000 | Sparse vectors; only non-zero values stored |
-- Check current dimension limit at runtime: SELECT current_setting('vector.max_dimensions'); -- If you need > 16,000 dimensions (rare in practice): -- Option 1: Use sparsevec if vector is sparse CREATE TABLE items ( id BIGSERIAL PRIMARY KEY, embedding SPARSEVEC(100000) -- up to 1M dims ); -- Option 2: Dimensionality reduction before storage -- Use PCA or UMAP to reduce from e.g. 65536-dim to 2048-dim -- then store as vector(2048) -- Option 3: Split vector across columns (workaround, ugly) -- Not recommended but possible for extreme edge cases -- Real-world dimension reference: -- text-embedding-3-small: 1,536 dims (well within limit) -- text-embedding-3-large: 3,072 dims (well within limit) -- CLIP image embeddings: 512-768 dims (well within limit) -- Custom deep models: may go up to 4096 dims -- All well within the 16,000 dim limit for vector(n)
More Related questions...