Self Hosting

This guide will demonstrate how to self host the Vault API on your own server or a cloud provider of your choice.

Prerequisites

  • A server running Ubuntu 18.04 or later
  • A domain name that you own
  • A valid SSL certificate for your domain name
  • A sendgrid account with an API key
  • Some knowledge of reverse proxies and DNS
  • An OpenAI API key or Your own Self hosted model (more on that later)

Step 1 - Configure DNS

You will need to configure your DNS to point to your server. You can do this by creating an A record for each of the subdomains you want to use.

A		self-chat.trieve.ai
A		self-api.trieve.ai
A		self-search.trieve.ai

Step 2 - Install Docker on machine

Follow the guide here to install docker on your server: https://docs.docker.com/engine/install/ubuntu/

Step 3 - Clone the repository

Shell

git clone https://github.com/devflowinc/trieve
cd trieve

Step 4 - Configure the Environment Variables for the API

There are 3 files you need to modify We have an example .env file in the root of the repository. You can use this as a starting point for your own configuration.

cat .env.server .env.chat .env.search .env.docker-compose > .env

The main ENV variables you will need to update are:

# FOR SERVER
DATABASE_URL
QDRANT_URL
QDRANT_API_KEY
OPENAI_API_KEY

# For CHAT
VITE_API_HOST=https://self-api.trieve.ai/api
VITE_SEARCH_URL=https://self-api.trieve.ai/api
# For SEARCH
PUBLIC_API_HOST=https://self-api.trieve.ai/api

Everything else can be left as default but there are some passwords that may want to be hardened if this is for production.

To see a full list of ENV variables and what they do please see the env file

Step 5 - Setup docker compose

Shell

docker compose up -d

This docker compose file will setup the following services:

  • postgres
  • Qdrant
  • server
  • chat
  • search

We DO NOT reccomend to run Qdrant or Postgres on the same machine as the API. You can use a managed database service such as AWS RDS or Neon (our prefernce) to host postgres. and we reccomend using a differnt machine for Qdrant (Mainly just to prevent the chance of data loss).

Step 6 - Configure Caddyfile

Install caddy using the instructions here: https://caddyserver.com/docs/install

We have an example Caddyfile in the root of the repository. You can use this as a starting point for your own configuration.

sudo cp Caddyfile /etc/caddy/Caddyfile

/etc/caddy/Caddyfile

# Global options
{
    email developer@trieve.ai
}

# Define a site block for chat.trieve.ai
self-chat.trieve.ai {
    reverse_proxy localhost:3000
}

# Define a site block for api.trieve.ai
self-api.trieve.ai {
    reverse_proxy localhost:8090
}

# Define a site block for search.trieve.ai
self-search.trieve.ai {
    reverse_proxy localhost:3001
}

Once you have this you can run the caddy daemon using systemctl

sudo systemctl enable caddy.service
sudo systemctl restart caddy.service

Step 7 - Profit 🦀🦀🦀

Congratulations you have now self hosted the Trieve API. You can now use the API by navigating to your domain name in your browser on either chat or search.