Skip to content

Deploying Knowtation

Knowtation runs as three containers from compose.yaml: Postgres 18 (db), the API (api) and the web app with its reverse proxy (web). Uploaded files and the database live in two named volumes, api-data and db-data.

Everyone signs in with an account the admin creates (accounts and sharing). Knowtation's own sign-in needs no mail server and no outside identity provider.

Requirements

  • Podman 5 with podman compose, or Docker with Compose v2.
  • About 300 MB of memory when idle; more while reading large files (an 833 MB CSV peaked at about 3 GB). Disk for the datasets you upload.
  • Network access while building (container images, Python and npm packages); afterwards only for URL sources and cloud LLMs.

Install

git clone https://gitlab.tarkam.org/tarkam/knowtation.git
cd knowtation
cp .env.example .env        # then edit .env, or: scripts/dev-setup.sh
podman compose up -d --build

The first build takes a few minutes (the web image also builds this documentation, served at docs.<host>). Check that db and api are healthy and web is up, then open the app:

podman compose ps
curl -fsS http://localhost:8080/api/health

Configuration (.env)

Variable Default What it does
POSTGRES_PASSWORD knowtation Password of the database owner. Takes effect only when the db-data volume is first created; to change it later, use ALTER ROLE in Postgres too
KNOWTATION_APP_DB_PASSWORD knowtation_app Password of the role the API uses; the API applies it at each start (database.md)
KNOWTATION_PORT 8080 Host port (or address:port) of the web app. 127.0.0.1:8080 keeps it off the network
KNOWTATION_BASE_PATH empty Public URL prefix, such as /knowtation, when a reverse proxy serves the app under a path. Empty serves it at /. Baked into the web image at build time, so a change needs a rebuild. The proxy strips this prefix before forwarding
KNOWTATION_USE_SUBDOMAINS 0 Set 1 in production so /docs/ and /api/docs on the app's address redirect to docs.<host> and api.<host>. Leave empty on a laptop or under a path prefix. An IP address never redirects
KNOWTATION_ROOT_PATH /api Path the browser uses for the API, so the API docs call the right URLs. /api at the site root; /knowtation/api when KNOWTATION_BASE_PATH is /knowtation
KNOWTATION_MAX_UPLOAD_MB 200 Largest upload in MB, enforced by both the web proxy and the API
KNOWTATION_MAX_SOURCE_MB 5000 Largest file downloaded from a URL source, in MB; URL sources are read in the background. Over the upload limit, a CSV's statistics still cover every row, some formats are profiled from their first rows and others are refused (see the overview)
KNOWTATION_ADMIN_USERNAME empty Username of the admin, created at the first start. Required until the admin exists
KNOWTATION_ADMIN_PASSWORD empty The admin's starting password (at least 12 characters). Read only while no admin exists; remove it afterwards and change the password in the app
KNOWTATION_COOKIE_SECURE true Send the sign-in cookie over HTTPS only. Browsers also accept it on http://localhost; set false only for plain HTTP on other host names
KNOWTATION_COOKIE_PATH / Path of the session cookie. / at the site root; the same value as KNOWTATION_BASE_PATH when the app is served under a path, so the cookie is not sent to other apps on that host
ANTHROPIC_API_KEY empty Anthropic key; without any LLM key, runs use the rules only
OPENAI_API_KEY empty OpenAI key
GOOGLE_API_KEY empty Google key
OLLAMA_BASE_URL empty Ollama server, for local models
KNOWTATION_DEFAULT_LLM_MODEL empty Model for runs that don't name one, such as anthropic:<model> or ollama:<name>
KNOWTATION_LLM_MAX_USD_PER_RUN 0.25 Most a run or trial may spend on LLM calls, in US dollars (priced per call with genai-prices), unless the admin set a cap for that person (server's keys) or they set their own (own keys). 0 turns the LLM off; for no practical cap, set a large value
KNOWTATION_LLM_MAX_TOKENS_PER_RUN 200000 Token cap per run or trial for models whose price is unknown (Ollama, new models)
KNOWTATION_LLM_PARALLEL_CALLS 4 How many LLM calls a run or trial sends at once; 1 sends them one after another. Higher is faster until the provider's rate limit
KNOWTATION_SECRET_KEY empty Encrypts the LLM keys people add on their account page. Needed before anyone can add one. Generate it with python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())". To replace it, put the new key first and the old one after a comma (new,old), so stored keys still decrypt. The API won't start when stored keys exist and this is missing
KNOWTATION_LLM_PRICE_UPDATES 1 Download current LLM prices (genai-prices' price file, from GitHub) at start-up and then daily. 0 keeps the prices built into the installed genai-prices, for servers without internet access. Prices the admin sets always win
KNOWTATION_LLM_CACHE_DAYS empty Delete cached LLM answers unused this many days. Empty keeps each answer until the last dataset that used it is deleted
KNOWTATION_SAMPLE_FEATURES 1000 How many features to read from each OGC API collection when profiling it
KNOWTATION_ALLOW_PRIVATE_HOSTS empty Comma-separated host names that may be read even though they resolve to private addresses (trusted internal sources); everything else private is refused
KNOWTATION_SOURCE_CORESTACK_KEY empty API key for the CoRE Stack source; add other KNOWTATION_SOURCE_* keys the same way

LLM models

The model list starts on none (rules only). It offers what each key can use, as the provider lists it (a free call), and asks for confirmation before using one:

  • The server's keys and its Ollama (below) are offered to the admin and to people the admin enabled on the Users page. Users who existed before this setting keep their access; new users start without it. Models the admin hides there are left out and refused, under any of their names (such as an undated Anthropic alias or Ollama's :latest) and as default.
  • Caps per run: KNOWTATION_LLM_MAX_USD_PER_RUN is the default. The admin can set another cap per person for the server's keys (Users page), and people set their own for their own keys (account page). The run's estimate says when a run won't fit under its cap.
  • People's own keys, added on their account page, need KNOWTATION_SECRET_KEY. Each key is checked by listing the provider's models, stored encrypted, shown only by its last four characters, and used only for runs and trials its owner starts on it. They can't bring an Ollama address: Ollama is the server's.
  • Other… takes any Pydantic AI model string, paid by the server's keys or the person's own.
  • Kept: each key's list is used for 24 hours, then asked for again on the next look; a list that failed is asked for again after 10 minutes, and the last good list is shown meanwhile. Refresh models asks at once (the server's keys only for the admin).
  • Where keys come from: Anthropic ANTHROPIC_API_KEY, Google GOOGLE_API_KEY, OpenAI OPENAI_API_KEY, and Ollama OLLAMA_BASE_URL, for the server; people's own keys for Anthropic, Google, OpenAI.
  • Anthropic keeps: every model.
  • Google keeps: Gemini and Gemma text models (not embedding, image, speech, live, robotics, computer-use or transcription variants).
  • OpenAI keeps: chat models (gpt-, o series, chatgpt-; not embedding, audio, realtime, image, speech, transcription, moderation or search models).
  • Ollama keeps: every local model.

The models below are suggested: tried with Knowtation's prompts and marked in the list.

Prices come from genai-prices: its price file is downloaded at start-up and then daily (KNOWTATION_LLM_PRICE_UPDATES; 0 keeps the table built into the installed version). The admin can set a price per model on the Users page, per million input and output tokens, which wins; $0 for an Ollama model puts its runs under the dollar cap instead of the token cap. Estimates are for a typical call; a run makes one call per 30 columns of each file, and one for documentation passages the rules couldn't settle, up to KNOWTATION_LLM_PARALLEL_CALLS at once; stored answers cost nothing.

Replacing KNOWTATION_SECRET_KEY: set new,old (the new key first), restart, and stored keys still decrypt; new ones are encrypted with the new key. Dropping the old key makes keys encrypted with it unreadable: their owners see "add it again". With stored keys and no usable secret, the API refuses to start.

Suggested model Server key One call (30 columns)
Claude Haiku 5.5 (anthropic:claude-haiku-5-5) ANTHROPIC_API_KEY $0.005
Claude Sonnet 5.5 (anthropic:claude-sonnet-5-5) ANTHROPIC_API_KEY $0.107
Gemini 3.5 Flash-Lite (google:gemini-3.5-flash-lite) GOOGLE_API_KEY $0.025
Gemini 3.8 Flash (google:gemini-3.8-flash) GOOGLE_API_KEY $0.040

Accounts

  • The admin: set KNOWTATION_ADMIN_USERNAME and KNOWTATION_ADMIN_PASSWORD before the first start; the API creates that admin when none exists, and refuses to start while there are no users and no admin settings. Once the admin exists, remove the password from .env and change it in the app (your name in the top bar).
  • Development: scripts/dev-setup.sh writes .env with random database passwords and an admin, and prints the admin's password once. It never changes values already in .env. An existing db-data volume keeps the database passwords it was created with (compose's defaults are knowtation and knowtation_app): put those in .env first, then run the script.
  • Users: the admin creates, resets, disables and deletes them on the Users page.
  • A forgotten admin password: run podman compose exec api python -m knowtation_api.admin reset-password <username> on the server; it prints a temporary password to change at sign-in. It works for any user.
  • Cookies: the sign-in cookie is sent over HTTPS only (browsers also accept it on http://localhost). For plain HTTP on another host name, set KNOWTATION_COOKIE_SECURE=false; better, add HTTPS (below). Under a path prefix, set KNOWTATION_COOKIE_PATH to that prefix.
  • Upgrading an instance from before accounts: the datasets, rule sets and policies already stored go to the admin at the first start.

Exposing it: HTTPS

Bind the app to localhost (KNOWTATION_PORT=127.0.0.1:8080) and put a reverse proxy in front that terminates TLS. Knowtation has its own sign-in, so the proxy only adds HTTPS. With Caddy, which gets certificates automatically:

knowtation.example.org, api.knowtation.example.org, docs.knowtation.example.org {
    reverse_proxy 127.0.0.1:8080
}

The web container can serve three hosts, worked out from each request. In production, set KNOWTATION_USE_SUBDOMAINS=1 and add DNS for all three names:

Address What
knowtation.example.org The app. It calls the API at /api on its own address, so sign-in cookies and the origin check need nothing more
api.knowtation.example.org The API for scripts (with an API token), and its docs at /docs
docs.knowtation.example.org This documentation

Leave KNOWTATION_USE_SUBDOMAINS empty on a laptop and when the app is served under a path: /docs/ and /api/docs stay on the app's address. Set it to 1 in production, and those paths redirect to the other two hosts. Opened by IP address, where subdomains can't work, the app serves them as paths either way. Keep the Host header (the sign-in's origin check compares it) and send X-Forwarded-Proto (Caddy does), so redirects keep https.

To serve the app under a path such as /knowtation instead of its own hostname, set KNOWTATION_BASE_PATH=/knowtation, KNOWTATION_COOKIE_PATH=/knowtation and KNOWTATION_ROOT_PATH=/knowtation/api, rebuild, and strip that prefix in the proxy:

location /knowtation/ {
    proxy_pass http://127.0.0.1:8080/;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_read_timeout 300s;
}

Single sign-on isn't built in yet (tasks). Allow long requests: uploading a large file can take minutes (the built-in proxy allows 300 s). URL sources, runs and trials work in the background, so they aren't limited by it.

Start on boot

Each service has restart: always. (With unless-stopped, rootless Podman counts a shutdown as a stop and skips the containers from the second boot on.) To keep the app off across reboots, use podman compose down.

  • Docker: the containers come back when the Docker daemon starts.
  • Rootless Podman: enable the restart service, and let your user's services run without a login session (without lingering, they also stop when you log out):

bash systemctl --user enable podman-restart.service sudo loginctl enable-linger "$USER"

scripts/dev-setup.sh prints these two commands while either is missing.

Update

git pull
podman compose up -d --build

Database migrations run automatically when the API starts. Back up first (next section); runs in progress when the API restarts are marked failed and can be started again.

Backups

scripts/db-backup.sh saves the database and the uploaded files; scripts/db-restore.sh puts them back. Run backups on a schedule (for example a systemd timer or cron) and copy them off the machine. Details: database.md.

Logs and troubleshooting

podman compose logs -f api     # identification runs, one line per LLM call, provider retries, errors
podman compose logs web        # proxy access log

The API log leaves out successful health checks (the container's, every few seconds); failed ones are logged. Podman prints Executing external compose provider … before each podman compose command; to hide it, put compose_warning_logs = false under [engine] in ~/.config/containers/containers.conf.

Symptom Likely cause
502 Bad Gateway The API is still starting or has stopped: podman compose ps, then the API log
Run fails with an LLM error Missing or wrong provider key, or an unknown model name
The docs return 404 The web image was built without the docs stage: podman compose build web
api. or docs. addresses don't open DNS (or the TLS proxy) covers only the app's name: add the two others
A file shows as failed The dataset's Overview tab lists it under What failed, with the reason and Retry; the other files are still processed

Run a second copy

To try a branch without touching a running instance, use another project name and port; it gets its own containers and volumes:

KNOWTATION_PORT=8081 podman compose -p knowtation-test up -d --build
podman compose -p knowtation-test down -v      # remove it, data included

Remove

podman compose down        # stop and remove the containers; data stays
podman compose down -v     # also delete the database and uploaded files