Skip to content

Compatible with pgvector

pgvecto.rs can be configured to be compatiable with pgvector at:

  • Creat table
  • Create vector indexes
  • Search vectors

For create table and search vectors, pgvecto.rs natively supports the feature. For create vector indexes, this feature shoule be enabled by SET vectors.pgvector_compat=on;.

This is a compatibility mode for those SDK and user which is designed for pgvector.

Examples

It's easy to turn on compatibility mode and trigger a query.

sql
DROP TABLE IF EXISTS t;
SET vectors.pgvector_compat=on;
CREATE TABLE t (val vector(3));
INSERT INTO t (val) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 100000);
CREATE INDEX hnsw_l2_index ON t USING hnsw (val vector_l2_ops);
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <-> '[0.5,0.5,0.5]' limit 100) t2;
DROP INDEX hnsw_l2_index;

Different type of indexes are accepted:

sql
SET vectors.pgvector_compat=on;
-- [hnsw + vector_l2_ops] index with default options
CREATE INDEX hnsw_l2_index ON t USING hnsw (val vector_l2_ops);
-- [hnsw + vector_cosine_ops] index with single ef_construction option
CREATE INDEX hnsw_cosine_index ON t USING hnsw (val vector_cosine_ops) WITH (ef_construction = 80);
-- anonymous [hnsw + vector_ip_ops] with all options
CREATE INDEX ON t USING hnsw (val vector_ip_ops) WITH (ef_construction = 80, m = 12);
-- [ivfflat + vector_l2_ops] index with default options
CREATE INDEX ivfflat_l2_index ON t USING ivfflat (val vector_l2_ops);
-- [ivfflat + vector_ip_ops] index with all options
CREATE INDEX ivfflat_ip_index ON t USING ivfflat (val vector_cosine_ops) WITH (nlist = 80);
-- anonymous [ivf + vector_ip_ops] with all options
CREATE INDEX ON t USING ivfflat (val vector_ip_ops) WITH (lists = 80);

Limitation

For compatibility, we strive to maintain consistency in user experience, but there are still some limitations in two aspects:

  • Some features of pgvector.rs are unavailable at compatibility mode
  • Some features of pgvector are difference from compatibility mode

Unavailable features of pgvecto.rs

When pgvecto.rs is working at compatibility mode, some features of pgvecto.rs are unaccessed:

  • flat index
  • quantization, including scalar quantization and product quantization
  • prefilter and vbase

And for index ivfflat and hnsw, only the following options are available. Their default value is different from pgvecto.rs original, which keeps the same from pgvector.

Options for ivfflat.

KeyTypeDefaultDescription
listsinteger100Number of cluster units.

Options for hnsw.

KeyTypeDefaultDescription
minteger16Maximum degree of the node.
ef_constructioninteger64Search scope in building.

Difference from pgvector

Though we have kept our best to maintain consistency, there is still difference from pgvector.

Known issues are not limited to: