Run PgVector on Docker

Create a file resources.py with the following contents:

resources.py
from phi.docker.app.postgres import PgVectorDb
from phi.docker.resources import DockerResources

# -*- PgVector running on port 5432:5432
vector_db = PgVectorDb(
    pg_user="ai",
    pg_password="ai",
    pg_database="ai",
    debug_mode=True,
)

# -*- DockerResources
dev_docker_resources = DockerResources(apps=[vector_db])

Start resources using:

phi start resources.py

Press Enter to confirm and verify container status on the docker dashboard.

Run Jupyter on Docker

A jupyter notebook is a must have for AI development. Update the resources.py file to:

resources.py
from os import getenv

from phi.docker.app.jupyter import Jupyter
from phi.docker.app.postgres import PgVectorDb
from phi.docker.resources import DockerResources

# -*- PgVector running on port 5432:5432
vector_db = PgVectorDb(
    pg_user="ai",
    pg_password="ai",
    pg_database="ai",
    debug_mode=True,
)

# -*- Jupyter running on port 8888:8888
jupyter = Jupyter(
    mount_workspace=True,
    env_vars={"OPENAI_API_KEY": getenv("OPENAI_API_KEY")},
)

# -*- DockerResources
dev_docker_resources = DockerResources(
    apps=[vector_db, jupyter],
)

Start resources using:

phi start resources.py

View Jupyterlab UI

  • Open localhost:8888 to view the Jupyterlab UI. Password: admin
  • The directory is automatically mounted in the notebook.

Stop resources

phi stop resources.py