vector
vector
(pgvector
) is an extension that provides native vector data types and
indexing capabilities for Postgres. All Crunchy Bridge clusters come with the
extension available, but you need to enable it with the following command:
CREATE EXTENSION vector;
Once enabled, you can create a vector column with your tables:
CREATE TABLE my_table (
id SERIAL PRIMARY KEY,
embedding vector(1536)
)
Then, to create an index on the vector data, you can run:
CREATE INDEX ON my_table USING ivfflat (embedding vector_l2_ops) WITH (lists = 500);
Note that the vector size (that is, the number in the parenthesis for
VECTOR(#)
) on the column definition is important. Without it, you will see the
following error when creating an index:
ERROR: column does not have dimensions
We've created a few tutorials for using vector
:
- Beginning
vector
: What's Postgres Got To Do With AI? - Using
vector
: Performance Tips for Developers Using Postgres and vector - See also our AI blog series
vector
documentation: