Skip to content

Postgres Vector Store

You can use a Postgres database with the pgvector extension as a vector store.

The Postgres vector store requires both the psycopg2 and pgvector packages:

pip install psycopg2-binary pgvector

Use the VectorStoreFactory.for_vector_store() static factory method to create an instance of a Postgres vector store.

To create a Postgres vector store, supply a connection string in the following format:

postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]

For example:

postgresql://graphrag:!zfg%dGGh@mydbcluster.cluster-123456789012.us-west-2.rds.amazonaws.com:5432/postgres

Connecting to an IAM auth-enabled Postgres vector store

Section titled “Connecting to an IAM auth-enabled Postgres vector store”

If your Postgres database supports AWS Identity and Access Management (IAM) database authentication, omit the password, and add enable_iam_db_auth=True to the connection string query parameters:

postgresql://graphrag@mydbcluster.cluster-123456789012.us-west-2.rds.amazonaws.com:5432/postgres?enable_iam_db_auth=True

You will need to create a database user, and grant the rds_iam role to use IAM authentication.