Skip to content

Provision a database for SerenityGPT

This guide provides instructions for setting up a PostgreSQL database with the pgvector extension for use with SerenityGPT. It covers two scenarios: provisioning a cloud-vendor-managed database, in this example an Azure database for PostgreSQL instance, and optionally provisioning a local Docker instance (for testing purposes).

After completing this guide, you'll have:

  • A provisioned PostgreSQL database with pgvector extension.
  • The credentials required by the SerenityGPT application to connect to the database.

Cloud deployment: Azure Database for PostgreSQL

The following steps are an overview of setting up a PostgreSQL database with pgvector extension on Azure, for use with SerenityGPT. This is the recommended deployment method for a production database server, but can also be used for testing purposes.

Important

These steps are provided as a high-level overview. It's recommended that you always refer to the official Azure documentation for setting up a PostgreSQL database with pgvector extension, available on docs.microsoft.com.

High-level steps and suggestions:

1. Log in to the Azure Portal.

2. Create a new Azure Database for PostgreSQL server:

  • Click "Create a resource" > "Databases" > "Azure Database for PostgreSQL".
  • Choose "Flexible server" for better performance and scalability.
  • Fill in the required details (server name, region, admin credentials).
  • In the "Additional settings" tab, enable the pgvector extension.

3. Configure firewall rules for connectivity from main application target environment.

  • Depending on your default firewall settings, you may need to explicitly expose the database server's port (default 5432).

4. Verify the server is running.

5. Create a new database on that server.

  • The recommended database name is "serenitydb".

6. Note the following properties, required for the application deployment:

  • Host: your database server hostname (for example, myserenitydb.postgres.database.azure.com).
  • Port: the database port (for example, 5432).
  • Database name: the name of the database you created on the server (for example serenitydb).
  • The database user: (for example serenityuser).
  • The password for that user.

Local deployment: Docker Compose (for testing)

This method is ideal for testing and development environments. It allows you to quickly set up a local PostgreSQL instance with pgvector extension, enabling you to experiment with SerenityGPT's features without the need for cloud resources. This approach is particularly useful for initial setup, debugging, and understanding the system's requirements and behaviour before moving to a production environment.

High-level steps and suggestions:

1. Ensure Docker and Docker Compose are installed on your system.

2. Create a docker-compose.yml file with the following content:

services:
  db:
    image: pgvector/pgvector:pg16
    environment:
      POSTGRES_DB: serenitydb
      POSTGRES_USER: serenityuser
      POSTGRES_PASSWORD: serenitypassword
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

Docker volumes

Note that this configuration uses a Docker volume, which is a way to persist data between containers, but isn't a recommended approach for long term data storage. For more information on Docker volumes, refer to the Docker documentation.

3. Start the PostgreSQL container:

docker-compose up -d

4. Verify the container is running:

docker-compose ps

The output should look similar to the following:

CONTAINER ID   IMAGE                      STATUS                   PORTS                
6e524936bc84   pgvector/pgvector:latest   Up 5 seconds (healthy)   0.0.0.0:5432->5432/tcp

5. Note the following properties required for the application deployment:

  • Host: your database server hostname (in the above example localhost).
  • Port: the database port (for example, 5432).
  • Database name: the name of the database you created on the server (for example serenitydb).
  • Database user: (for example serenityuser).
  • Database password for that user: (for example serenitypassword).

Next steps

With the database provisioned, you are ready to proceed with the SerenityGPT setup. Refer to the next section of the documentation for instructions on obtaining and deploying the SerenityGPT container images.