Alert API uses three databases: a PostgreSQL database, an Elasticsearch database, and a Qdrant database.
The Docker images for these databases are available on the official Docker registry, so no image build is necessary.
The Postgres database has two uses:
- user management
- storage of conversation logs with the models
When the API is run in development mode, an SQLite database is used instead of the PostgreSQL database.
Alembic is a database schema migration tool for the SQLAlchemy ORM. After deploying the Postgres container, to create or upgrade the data schemas according to the latest models in the API code, run the following command:
PYTHONPATH=. alembic upgrade head
When the API is run from Docker, this command is automatically executed when the API starts from the api/start.sh
file called by the api/Dockerfile
.
After deploying the Postgres container, you can back up the database with the following command:
PGPASSWORD=<password> pg_dump --username postgres --data-only postgres" > my_dump.dump
...or, if you are using Docker:
docker exec -i <postgres-container-name> /bin/bash -c "PGPASSWORD=<password> pg_dump --username postgres --data-only postgres" > my_dump.dump
If you want to export the database schemas (in case you also want to rebuild the database), you can omit the --data-only
option from the pg_dump
command:
docker exec -i <postgres-container-name> /bin/bash -c "PGPASSWORD=<password> pg_dump --username postgres postgres" > my_dump.dump
After deploying the Postgres container, you can restore the database from a dump with the following command:
docker exec -i <postgres-container-name> /bin/bash -c "PGPASSWORD=<password> psql --username postgres postgres" < my_dump.dump
To feed models with knowledge bases (Retrieval Augmented Generation, RAG), two databases need to be deployed:
- an Elasticsearch database, which stores document corpuses and chunks of these documents
- a Qdrant database, the vector store that holds embedding vectors
To install them, follow the installation documentation.