EDB Postgres AI AI/ML - Installing the pgai tech preview

Suggest edits

The preview release of pgai is distributed as a self-contained Docker container that runs PostgreSQL and includes all of the pgai dependencies.

Configuring and running the container image

If you haven't already, sign up for an EDB account and log in to the EDB container registry.

Log in to Docker with the username tech-preview and your EDB Repo 2.0 subscription token as your password:

docker login docker.enterprisedb.com -u tech-preview -p <your_EDB_repo_token>
Output
Login Succeeded

Download the pgai container image:

docker pull docker.enterprisedb.com/tech-preview/pgai
Output
...
Status: Downloaded newer image for docker.enterprisedb.com/tech-preview/pgai:latest
docker.enterprisedb.com/tech-preview/pgai:latest

Specify a password to use for Postgres in the environment variable PGPASSWORD. The tech preview container will set up Postgres with this password and use it to connect to it. In bash or zsh set it as follows:

export PGPASSWORD=<your_password>

You can use the pgai extension with encoder LLMs in Open AI or with open encoder LLMs from HuggingFace. If you want to use Open AI you also must provide your API key for that in the OPENAI_API_KEY environment variable:

export OPENAI_API_KEY=<your_openai_key>

You can use the pgai extension with AI data stored in Postgres tables or on S3 compatible object storage. To work with object storage you need to specify the ACCESS_KEY and SECRET_KEY environment variables:.

export ACCESS_KEY=<your_access_key>
export SECRET_KEY=<your_secret_key>

Start the pgai tech preview container with the following command. It makes the tech preview PostgreSQL database available on local port 15432:

docker run -d --name pgai \
       -e ACCESS_KEY=$ACCESS_KEY \
       -e SECRET_KEY=$SECRET_KEY \
       -e OPENAI_API_KEY=$OPENAI_API_KEY \
       -e POSTGRES_PASSWORD=$PGPASSWORD \
       -e PGDATA=/var/lib/postgresql/data/pgdata \
       -p 15432:5432 \
       docker.enterprisedb.com/tech-preview/pgai:latest

Connect to Postgres

If you haven't yet, install the Postgres command-line tools. If you're on a Mac, using Homebrew, you can install it as follows:

brew install libpq

Connect to the tech preview PostgreSQL running in the container. Note that this relies on $PGPASSWORD being set - if you're using a different terminal for this part, make sure you re-export the password:

psql -h localhost -p 15432 -U postgres postgres
Output
psql (16.1, server 16.3 (Debian 16.3-1.pgdg120+1))
Type "help" for help.

postgres=#

Install the pgai extension:

create extension pgai cascade;
Output
NOTICE:  installing required extension "plpython3u"
NOTICE:  installing required extension "vector"
CREATE EXTENSION
postgres=# 
\dx
Output
                               List of installed extensions
    Name    | Version |   Schema   |                     Description
------------+---------+------------+------------------------------------------------------
 pgai       | 0.0.1   | public     | An extension to do the AIs
 plpgsql    | 1.0     | pg_catalog | PL/pgSQL procedural language
 plpython3u | 1.0     | pg_catalog | PL/Python3U untrusted procedural language
 vector     | 0.6.0   | public     | vector data type and ivfflat and hnsw access methods
(4 rows)

Could this page be better? Report a problem or suggest an addition!