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.
Prerequisites
Section titled “Prerequisites”- mise — provisions Python 3.12, goose, the Railway CLI, and more.
- Docker — only for the optional local
pgvectorPostgres. - Railway access —
mise run envpulls config from Railway. - A
GITHUB_TOKEN— thehuddlesurety-apiSDK is git-installed from a private repo; the build rewriteshttps://github.com/to use the token.
-
Install tools + dependencies:
Terminal window mise install # provisions the toolchain; uv resolves Python deps -
Pull environment variables from Railway:
Terminal window mise run env # writes .env.json (gitignored); mise auto-loads it -
Point at the database. The Railway database (
RAG ParadeDB) is private. SetDATABASE_URLin.env.localtolocalhost:5433(DB_PORT); the tunnel opens in the next step. -
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 |
Environment
Section titled “Environment”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 LiteLLMgemini/…model),FIND_BOND_MODEL,FIND_FINAL_BOND_MODEL,FILL_BOND_FILTER_MODEL(detect, validate, and fill),EMBEDDING_MODEL,EMBEDDING_DIMENSION,RERANK_MODEL(avoyage/…gateway alias),RERANK_ENABLED,ADDITIONAL_WARRANTIES_MODEL,JEV_MODEL(defaultjev-1.14.0), andADDITIONAL_WARRANTIES_JEV_FILTER(defaulttrue; turns the Jev page filter off), andEVIDENCE_JEV_DEDUPE(defaulttrue; 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 inGenerateFieldWorkflow. - Tuning:
RAG_*,CHUNK_MIN_CHARS/CHUNK_MAX_CHARS,FUZZY_MATCH_THRESHOLD. The olderCHUNK_*target, size, and overlap variables no longer apply. - Fill:
STANDARD_FORM_PATH(off|prompt|template, defaulttemplate). See Find & fill. - OTel:
OTEL_EXPORTER_OTLP_ENDPOINT(unset disables OTel) andSERVICE_NAME(required). This used to listOTEL_EXPORTER_OTLP_PROTOCOL, which nothing reads: the exporters are fixed to HTTP/protobuf.
Conventions
Section titled “Conventions”- 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.completioncall sets an explicittimeout(LLM_TIMEOUT_MS30s for the extractor,FILL_LLM_TIMEOUT_MS36s for the filler,FIND_LLM_TIMEOUT_MS/FINAL_FIND_LLM_TIMEOUT_MS30s for the finders). This is load-bearing: LiteLLM’s own defaultrequest_timeoutis 6000s, so an un-timed call can hang for ~27 min. The finder calls route through a sharedservices/llm_retry.pycompletion_with_retry(timeout_s, …)— 429s honor the server delay (capped at 15s), 5xx/transport errors back off exponentially, and a client-sideTimeoutis not retried. The filler’scomplete_jsontakes 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 explicittemperatureis passed anymore — LiteLLM applies Gemini 3’s default of 1.0 (structure stays pinned by the strictjson_schema). - Memory hygiene — activities free memory (
gc+malloc_trim) infinally, and never pass images across activity boundaries (they re-download/re-render). - Settings via pydantic-settings with an env-var fallback for unlisted keys.
Tests and CI
Section titled “Tests and CI”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.