ai-powered-conversational-intelligence

Deployment

How to run this project outside a developer’s local pip install + uvicorn workflow — Docker/Compose, environment configuration, connecting containers to an external Ollama and database, and what’s deliberately not included (Kubernetes, a bundled database, a bundled LLM server).

Read SECURITY.md and docs/PRODUCTION_CHECKLIST.md before deploying this anywhere beyond your own machine — this document covers how, not whether you should yet.

What’s provided, and what isn’t

Quick start

cp .env.example .env
# edit .env: point DB_* at your database (a genuinely read-only account --
# see SECURITY.md), and OLLAMA_HOST at your Ollama server.

docker compose build
docker compose up -d

# One-time (and after any real schema change):
docker compose exec api python scripts/build_embeddings.py

# Dashboard: http://localhost:8000/
# API:       http://localhost:8000/health

docker compose config will render your actual .env values into its output (including secrets) — don’t paste that output anywhere, and be careful running it in a shared terminal/CI log.

Connecting to Ollama running on the host

The api service declares extra_hosts: ["host.docker.internal:host-gateway"] in docker-compose.yml. Set in .env:

OLLAMA_HOST=http://host.docker.internal:11434

This resolves automatically on Docker Desktop (Windows/Mac). On Linux (Docker Engine 20.10+), host-gateway makes it resolve too. If your Ollama runs somewhere else entirely (another host, a dedicated Ollama container/server), just point OLLAMA_HOST at that instead — nothing else needs to change.

Connecting to an external database

Same .env mechanism as running locally — DB_TYPE/DB_HOST/DB_PORT/ etc., or DB_CONNECTION_STRING as a full override (see .env.example, docs/CONFIGURATION.md). Nothing Docker-specific here: the containers reach out to whatever host your .env names, same as the local dev workflow.

DB_TYPE=mssql note: this image’s unixodbc-dev covers pyodbc’s build requirement, not Microsoft’s ODBC Driver 17/18 for SQL Server itself (a separate, larger install from Microsoft’s own apt repo). If you’re connecting to SQL Server, extend the base image:

FROM text-to-sql-dashboard:latest
USER root
RUN curl -sSL -O https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb \
    && dpkg -i packages-microsoft-prod.deb \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y --no-install-recommends msodbcsql18 \
    && rm -rf /var/lib/apt/lists/* packages-microsoft-prod.deb
USER app

Kept out of the base image so Postgres/MySQL/Oracle-only deployments don’t carry that extra weight — see Dockerfile’s own comment on this.

Persistent vector storage

The Chroma schema index lives in a named Docker volume (chroma_index, mounted at /app/embeddings/.chroma) so it survives container restarts/recreates without needing build_embeddings.py re-run every time. Rebuilding the image does not clear this volume; only docker compose down -v or an explicit docker volume rm does.

After a real schema change:

docker compose exec api python scripts/build_embeddings.py

(Cheap to run when nothing changed — embeddings.schema_indexer.build_index skips re-embedding if the schema fingerprint hasn’t changed.)

Multi-source RAG / web search (optional)

Nothing Docker-specific here either if you turn these on (docs/MULTI_SOURCE_GUIDE.md) — same .env mechanism:

Voice mode (on by default)

Nothing Docker-specific to configure — ENABLE_VOICE_MODE=true is the default, and both faster-whisper and Piper run fully inside the container. Two one-time model-download steps still apply the same as a bare-metal install:

Set ENABLE_VOICE_MODE=false if you’d rather not carry either dependency in a deployment that has no use for spoken input/output.

AI-guided image editing (optional, off by default)

ENABLE_IMAGE_EDITING shares the exact same outbound-network/secret consideration as ENABLE_MEDIA_GENERATION just below — real, metered HTTPS calls to IMA Studio, gated behind the same IMA_API_KEY. No separate Docker/volume concern beyond that: a generated edit is stored as a normal attachment (ATTACHMENT_STORAGE_DIR — see docs/CONFIGURATION.md’s “Chat attachments” section), not a separate cache.

Media generation (optional, off by default)

Turning on ENABLE_MEDIA_GENERATION means the container makes outbound HTTPS calls to IMA Studio’s API carrying question text and (for a confirmed generation) real, metered spend — the same “one exception to the fully-local posture” consideration as WEB_SEARCH_API_KEY above. Nothing else is Docker-specific: IMA_API_KEY is just another .env secret (see “Production secrets” below), and generated media is cached in-process (media_gen/cache.py, 100-entry FIFO) rather than written to a volume — a container restart loses any not-yet-fetched generated media, an accepted tradeoff, not something to work around with a mount.

Media search (optional, off by default)

The heaviest optional feature to run in a container, in three ways:

  1. A real dependency-footprint increase. ENABLE_MEDIA_SEARCH=true pulls torch/sentence-transformers (local CLIP embeddings) and opencv-python/scenedetect (video scene detection) into the image — meaningfully larger than the rest of this project’s dependencies (see requirements.txt’s own comments). Leave the flag off for a deployment that doesn’t need this feature rather than paying that image size unconditionally.
  2. Tesseract is not in the base image. OCR (media/ocr.py, via pytesseract) needs the system Tesseract binary, the same “extra manual layer” shape as DB_TYPE=mssql’s ODBC driver above — it is not installed by this project’s Dockerfile. Add it yourself if you need OCR:
    FROM text-to-sql-dashboard:latest
    USER root
    RUN apt-get update && apt-get install -y --no-install-recommends tesseract-ocr \
        && rm -rf /var/lib/apt/lists/*
    USER app
    

    Without it, media/ocr.py fails open — indexing still succeeds, on- screen text in video frames just isn’t part of what’s searchable, not a hard failure.

  3. A real library folder must be mounted into the container. MEDIA_LIBRARY_PATH needs to resolve to something inside the container’s filesystem — bind-mount or volume-mount your actual media folder at that path in docker-compose.yml, then run indexing the same way schema embeddings are built:
    docker compose exec api python scripts/build_media_index.py
    

    Persist a Chroma-backed media index the same way the schema index is (the chroma_index volume already mounted at /app/embeddings/.chroma covers this — media search reuses the same PersistentClient, no second volume needed).

Captioning (MEDIA_VISION_MODEL) reuses your existing Ollama connection — no additional container-networking concern beyond what “Connecting to Ollama running on the host” above already covers, just an additional ollama pull <model> on whichever Ollama instance OLLAMA_HOST points at.

Health checks

Reverse proxy and auth

By default (nothing configured), neither the dashboard nor the API has real authentication (see docs/RISK_REGISTER.md’s R-001, docs/API.md’s “Auth” section) — suitable only for local/trusted-network use. Two of Settings.auth_mode’s four values do provide real, per-user identity: local (LOCAL_AUTH_ENABLED=true, this app’s own self-hosted accounts, optionally including Google sign-in — see below) and oidc (OIDC_ISSUER set, any standard external identity provider) — configure one of these for a genuinely multi-user deployment, rather than relying on the reverse-proxy pattern below as the only boundary. For anything still short of that (or as defense-in-depth on top of it), put an authenticating reverse proxy in front of the service — e.g. oauth2-proxy, or your platform’s managed auth/ingress layer. The service needs no code to know this exists; point the proxy at api:8000 and terminate TLS + auth there. The API’s optional API_AUTH_TOKEN shared-secret check can also layer underneath either mode (defense in depth) but should never be the only layer for anything but a single trusted caller.

Local accounts, Google sign-in, and conversation sharing

If you set LOCAL_AUTH_ENABLED=true, run the identity database’s migrations before first use (and after pulling any update that touches identity/models.py — including this project’s own Google sign-in and conversation-sharing tables):

alembic -c identity/alembic.ini upgrade head

Then seed the RBAC roles/permissions tables (idempotent — safe, and necessary, to re-run after any update that adds a new permission code, including this one, since this codebase has no automatic “re-seed on startup” hook):

python scripts/bootstrap_admin.py

To also enable Google sign-in, set GOOGLE_OAUTH_CLIENT_ID (see docs/AUTHENTICATION.md for the Google Cloud Console setup steps — a public client ID only, no secret involved). To allow an owner to create “anyone with the link” shares (off by default), set SHARE_PUBLIC_LINKS_ENABLED=true — see docs/SHARING_SECURITY.md and docs/CONFIGURATION.md’s own reference table for every tunable.

Once you put a reverse proxy/load balancer in front of this app, also set TRUSTED_PROXY_COUNT (default 0) to the exact number of proxy hops between the internet and this process — usually 1. Without this, every rate limiter and audit-log entry keyed by client IP (security/client_ip.py) sees only the proxy’s own address for every caller, collapsing every distinct user into one shared rate-limit bucket — a real availability problem (innocent users rate-limited together), not just an inaccuracy. This is deliberately opt-in and an exact hop count, never “trust the header if present” — a misconfigured count fails closed to the direct TCP peer rather than trusting a client-suppliable header.

docker-compose.yml’s port mapping is bound to 127.0.0.1 by default (${API_BIND_HOST:-127.0.0.1}:8000:8000) — an unqualified "8000:8000" mapping binds every host interface, reachable from the whole network the host sits on, not just the host itself. Set API_BIND_HOST in .env (e.g. to 0.0.0.0, or the specific interface your reverse proxy connects from) only once that proxy is actually in place — the localhost-only default is what makes “put a reverse proxy in front of it” a real boundary rather than something a network-reachable port mapping already bypassed.

Streaming (POST /ask/stream) behind a reverse proxy

POST /ask/stream returns text/event-stream. A proxy that buffers responses will hold every event until the run finishes, which produces no error and no warning — the stream simply arrives all at once, and the feature silently does nothing. Plain POST /ask is unaffected.

The app already sets the headers that ask a proxy not to buffer:

X-Accel-Buffering: no
Cache-Control: no-cache, no-store
Connection: keep-alive

nginx honours X-Accel-Buffering automatically. If you have an explicit location block for the API, make the intent explicit and give the stream a read timeout longer than your slowest question:

location /ask/stream {
    proxy_pass              http://app:8000;
    proxy_buffering         off;
    proxy_cache             off;
    proxy_http_version      1.1;
    proxy_set_header        Connection "";
    proxy_read_timeout      300s;   # >= your longest expected run
}

Other layers worth checking, because each defaults to buffering or to a short idle timeout:

Layer What to set
nginx proxy_buffering off (or rely on X-Accel-Buffering)
Apache mod_proxy SetEnv proxy-sendchunked 1, and raise ProxyTimeout
AWS ALB / ELB raise the idle timeout above your longest run
Cloudflare buffers by default on some plans; verify before relying on SSE
Any CDN exclude /ask/stream from caching entirely

How to confirm it works — events should arrive progressively, not in one burst at the end:

curl -N -X POST https://your-host/ask/stream   -H 'Content-Type: application/json'   -H 'Authorization: Bearer <token>'   -d '{"question":"how many orders were there in 2012?"}'

-N disables curl’s own buffering. You should see event: open almost immediately, then event: progress lines as the pipeline advances, then event: result and event: done. If everything appears at once, something between curl and the app is buffering.

A buffering proxy degrades gracefully: the UI falls back to its plain “Thinking Ns…” badge with no stage name, and the answer itself is unaffected.

Horizontal scaling considerations

Backup & recovery

Prompt 25 (production readiness & release gate) closed a real, previously-disclosed gap: no backup/recovery procedure existed anywhere in this project’s docs. Scoped honestly: this app is a read-only client of whatever business database you connect it to (db.connection.get_read_only_engine) — it never writes to that database and has no opinion on, or mechanism for, backing it up. That remains entirely your own infrastructure’s responsibility, same as before. What follows is a real procedure for the things this app itself owns.

Rollback

Also new in this pass — a documented procedure where none existed.

If you outgrow this

Kubernetes becomes worth the operational overhead once you need: multiple independently-scaled replicas with autoscaling policies, rolling deploys across a fleet, or multi-region placement. None of that is this project’s current shape (a demo/small-team tool, per SECURITY.md). If you get there, the natural migration is: containerize identically (this Dockerfile needs no change), move the Chroma volume to a PersistentVolumeClaim or an external Chroma/vector-DB service, and put the rate limiters behind a shared store (Redis) first — Kubernetes itself solves none of that on its own.

Production secrets

Reproducible builds

requirements.txt is fully version-pinned (see its own header comment). Both base images the Dockerfile uses — python:3.11-slim (the final application image) and node:22-slim (the frontend-build stage) — are digest-pinned (@sha256:...), not just tag-pinned: a floating tag can be silently repointed at a different image by the upstream maintainer at any time, the digest can’t. Re-verify and update either digest deliberately (a real, reviewed bump), not automatically — see each FROM line’s own comment in the Dockerfile for how the digest was obtained.