Postgres Vector Store
Topics
Section titled “Topics”Overview
Section titled “Overview”You can use a Postgres database with the pgvector extension as a vector store.
Install dependencies
Section titled “Install dependencies”The Postgres vector store requires both the psycopg2 and pgvector packages:
pip install psycopg2-binary pgvectorCreating a Postgres vector store
Section titled “Creating a Postgres vector store”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/postgresConnecting 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=TrueYou will need to create a database user, and grant the rds_iam role to use IAM authentication.