DocsDeploy with Docker

Deploy with Docker Compose

This document provides instructions for deploying the entire Autoflow application using Docker Compose.

Prerequisites

Deploy

  1. Clone the repository:

    git clone https://github.com/pingcap/autoflow.git;
    cd autoflow/;
  2. Copy and edit the .env file:

    cp .env.example .env
    vim .env # or use another text editor to edit this file

    Replace the following placeholders with your own values:

    • SECRET_KEY: you can generate a random secret key using:
      `python3 -c "import secrets; print(secrets.token_urlsafe(32))"`
    • TIDB_HOST, TIDB_USER, TIDB_PASSWORD and TIDB_DATABASE: you can get these values from the TiDB cluster you set up before.
      • Note: if you are using a self-managed TiDB cluster, you need to set TIDB_SSL=false.
    • EMBEDDING_MAX_TOKENS: set them according to the embedding model you choose before, it can not be changed after the deployment.(We will remove it in the future, and move it to the admin panel)
  3. Migrate the database schema:

    docker compose run backend /bin/sh -c "alembic upgrade head"
  4. Bootstrap the database with initial data:

    # Use default admin credentials (admin@example.com with random password)
    docker compose run backend /bin/sh -c "python bootstrap.py"
     
    # Or specify a custom admin email
    docker compose run backend /bin/sh -c "python bootstrap.py --email new-admin@example.com"

    Running the bootstrap script creates an admin user. You can find the username and password in the output.

    # Reset admin password (random generated)
    docker compose run backend /bin/sh -c "python bootstrap.py -r"
     
    # Or specify a new password
    docker compose run backend /bin/sh -c "python bootstrap.py -r --password <new_password>"
  5. Start the services:

    If you are using a SaaS embedding model, start the services with the following command:

    docker compose up

    If you want to use the built-in local embedding reranker, start the services with the following command:

    docker compose --profile local-embedding-reranker up
  6. Done! Now you can open your browser and visit http://localhost:3000 locally

Configuration

After you deploy the application, you need to initialize the application by following quick start guide.

  1. Set up the default LLM model in the Models > LLMs page.

  2. Set up the default Embedding model in the Models > Embedding Models page.

  3. Add a new Knowledge Base in the Knowledge Bases page.

  4. Configure default Chat Engine and set up the new knowledge base as the retrieval database.

Upgrade

This section will help you upgrade pingcap/autoflow to the new version.

Suppose you want to upgrade pingcap/autoflow from 0.3.0 to 0.3.1. Follow these steps:

  1. Edit your docker-compose.yml file to use the new image version.

    services:
      backend:
        image: tidbai/backend:0.3.1
      frontend:
        image: tidbai/frontend:0.3.1
      background:
        image: tidbai/backend:0.3.1
  2. Pull the new image:

    docker compose pull
  3. Migrate the database schema:

    docker compose run backend /bin/sh -c "alembic upgrade head"
  4. Recreate the docker containers:

    docker compose up -d --force-recreate
  5. Check the logs to ensure everything is working correctly:

    docker compose logs -f
  6. Done!