Skip to content

Local Development

RAG is driven by mise tasks (which load the env) and dependencies are managed with uv. It builds on Railway with Railpack (railpack.json) and starts with python -m app.temporal.worker.

  • mise — provisions Python 3.12, goose, the Railway CLI, and more.
  • Docker — only for the optional local pgvector Postgres.
  • Railway access — mise run env pulls config from Railway.
  • A GITHUB_TOKEN — the huddlesurety-api SDK is git-installed from a private repo; the build rewrites https://github.com/ to use the token.
  1. Install tools + dependencies:

    Terminal window
    mise install # provisions the toolchain; uv resolves Python deps
  2. Pull environment variables from Railway:

    Terminal window
    mise run env # writes .env.json (gitignored); mise auto-loads it
  3. Point at the database. The Railway database (RAG ParadeDB) is private. Set DATABASE_URL in .env.local to localhost:5433 (DB_PORT); the tunnel opens in the next step.

  4. Run the worker:

    Terminal window
    mise run run # pulls env, starts the db-tunnel daemon, runs the worker
Task What it does
mise run run Pull env, start the db-tunnel daemon, run the Temporal worker
mise run check test + fmt + lint (what CI runs)
mise run test pytest tests/unit
mise run fmt ruff format
mise run lint ruff check app
mise run clean Remove generated files
mise run db:migrate goose up (schema document)
mise run db:status goose migration status
mise run db:nuke goose reset
mise run db:ui Postgres TUI (rainfrog)
mise run env Pull env vars from Railway → .env.json
mise run log Tail Railway logs

Runtime config comes from Railway via mise run env → .env.json (gitignored); .env.local holds dev overrides. Key variables:

  • API: BASE_URL (Go API). No API key — calls authenticate with the requester’s workflow token from the Temporal header.
  • DB: DATABASE_URL
  • Temporal: TEMPORAL_SERVER_URL, TEMPORAL_TASK_QUEUE_RAG, DEPLOYMENT_ENVIRONMENT
  • LLM gateway: LITELLM_PROXY_API_BASE, LITELLM_PROXY_API_KEY — both required (the worker holds no provider key; the gateway does). See LLM Gateway.
  • Models: VERTEX_MODEL (the extraction model — the name is legacy; it now names a LiteLLM gemini/… model), FIND_BOND_MODEL, FIND_FINAL_BOND_MODEL, FILL_BOND_FILTER_MODEL (detect, validate, and fill), EMBEDDING_MODEL, EMBEDDING_DIMENSION, RERANK_MODEL (a voyage/… gateway alias), RERANK_ENABLED, ADDITIONAL_WARRANTIES_MODEL, JEV_MODEL (default jev-1.14.0), and ADDITIONAL_WARRANTIES_JEV_FILTER (default true; turns the Jev page filter off), and EVIDENCE_JEV_DEDUPE (default true; turns off the Jev step of the evidence dedupe, #187). The additional-warranties service (#183) isn’t called by any workflow yet, but Jev itself now runs in GenerateFieldWorkflow.
  • Tuning: RAG_*, CHUNK_MIN_CHARS / CHUNK_MAX_CHARS, FUZZY_MATCH_THRESHOLD. The older CHUNK_* target, size, and overlap variables no longer apply.
  • Fill: STANDARD_FORM_PATH (off | prompt | template, default template). See Find & fill.
  • OTel: OTEL_EXPORTER_OTLP_ENDPOINT (unset disables OTel) and SERVICE_NAME (required). This used to list OTEL_EXPORTER_OTLP_PROTOCOL, which nothing reads: the exporters are fixed to HTTP/protobuf.
  • Python 3.12, type hints throughout. Dataclasses for Temporal activity I/O (must serialize across the boundary); pydantic models for domain types and LLM structured-output schemas.
  • Lazy imports inside activities to keep the workflow sandbox light.
  • Per-call LLM timeouts + retry — every litellm.completion call sets an explicit timeout (LLM_TIMEOUT_MS 30s for the extractor, FILL_LLM_TIMEOUT_MS 36s for the filler, FIND_LLM_TIMEOUT_MS / FINAL_FIND_LLM_TIMEOUT_MS 30s for the finders). This is load-bearing: LiteLLM’s own default request_timeout is 6000s, so an un-timed call can hang for ~27 min. The finder calls route through a shared services/llm_retry.py completion_with_retry(timeout_s, …) — 429s honor the server delay (capped at 15s), 5xx/transport errors back off exponentially, and a client-side Timeout is not retried. The filler’s complete_json takes a reasoning-effort ladder (default medium → low; AIA, EJCDC, and federal forms run low only) and downshifts on a timeout/truncation rather than failing outright. Each rung is a single request (max_retries=0, #182): a medium call that times out drops to low after one 36 s attempt instead of after the SDK’s three (about 108 s). The filler no longer retries 429s or 5xx errors inside the call; Temporal retries the whole activity (RetryPolicy(maximum_attempts=3)). The blank validator runs at low only (medium was several times slower at the same accuracy). No explicit temperature is passed anymore — LiteLLM applies Gemini 3’s default of 1.0 (structure stays pinned by the strict json_schema).
  • Memory hygiene — activities free memory (gc + malloc_trim) in finally, and never pass images across activity boundaries (they re-download/re-render).
  • Settings via pydantic-settings with an env-var fallback for unlisted keys.

Unit tests live in tests/unit/ (mise run test); OCR parser tests skip where Tesseract isn’t installed. benchmark/ stays gitignored. CI (.github/workflows/ci.yaml) runs three jobs on every push: Test (pulls env from the Railway development environment, then mise run test), Format (mise run fmt, fails if it changes anything), and Lint (mise run lint). mise run check runs all three locally. This page used to say there were no committed tests and no in-repo CI; #172 added both.