Frequently Asked Questions
How many vectors can be stored in a single table?
A non-partitioned table has a limit of 32 TB by default in Postgres. A partitioned table can have thousands of partitions of that size.
Is replication supported?
Yes, pgvector uses the write-ahead log (WAL), which allows for replication and point-in-time recovery.
What if I want to index vectors with more than 2,000 dimensions?
You can use half-precision indexing to index up to 4,000 dimensions or binary quantization to index up to 64,000 dimensions. Another option is dimensionality reduction.
Can I store vectors with different dimensions in the same column?
You can use vector as the type (instead of vector(3)).
CREATE TABLE embeddings (model_id bigint, item_id bigint, embedding vector, PRIMARY KEY (model_id, item_id));
However, you can only create indexes on rows with the same number of dimensions (using expression and partial indexing):
CREATE INDEX ON embeddings USING hnsw ((embedding::vector(3)) vector_l2_ops) WHERE (model_id = 123);
and query with:
SELECT * FROM embeddings WHERE model_id = 123 ORDER BY embedding::vector(3) <-> '[3,1,2]' LIMIT 5;
Can I store vectors with more precision?
You can use the double precision[] or numeric[] type to store vectors with more precision.
CREATE TABLE items (id bigserial PRIMARY KEY, embedding double precision[]);
-- use {} instead of [] for Postgres arrays
INSERT INTO items (embedding) VALUES ('{1,2,3}'), ('{4,5,6}');
Optionally, add a check constraint to ensure data can be converted to the vector type and has the expected dimensions.
ALTER TABLE items ADD CHECK (vector_dims(embedding::vector) = 3);
Use expression indexing to index (at a lower precision):
CREATE INDEX ON items USING hnsw ((embedding::vector(3)) vector_l2_ops);
and query with:
SELECT * FROM items ORDER BY embedding::vector(3) <-> '[3,1,2]' LIMIT 5;
Do indexes need to fit into memory?
No, but like other index types, you’ll likely see better performance if they do. You can get the size of an index with:
SELECT pg_size_pretty(pg_relation_size('index_name'));