Skip to content

Architecture

This page describes the comparative study and its arms. For the current clinical product, see the BiobadamexAI workflow.

No single repo has this page. Each repo documents its own service. This page shows how the two code repos (pokta-care-monorepo and pokta-grader-bioagent) work together.

Term Meaning
Harness The method that does the extraction. The code has three: plain, rheumaai and grader.
Arm One combination of a model, a harness and an optional prompt. The STUDY_ARMS environment variable sets the arms at runtime.
Sweep One full run: all notes through all arms.
Cell One (note, arm) pair in a sweep.
Gold The correct value of a field, certified by a clinician.

The file pokta-care-monorepo/apps/api/src/services/biobadamex-study-harness.ts sets the harnesses: STUDY_HARNESSES = ["plain", "rheumaai", "grader"]. The code has no fixed list of models.

Harness How the code calls it Where the code is
plain LLM call in the same process as the monorepo. It uses no external repo. pokta-care-monorepo (plainInvoker)
rheumaai HTTP to RHEUMAI_STRUCTURED_URL Separate service apps/bioagent in pokta-care-monorepo, route POST /v1/study/rheumaai-reply
grader HTTP to GRADER_STRUCTURED_URL Separate service pokta-grader-bioagent (its own repo), route POST /v1/chat/completions

The fourth arm is not a separate harness. The fourth arm is an LLM that a different rheumatologist tunes. It uses the plain harness with the promptId rheum-v1. The code registers this prompt, but the prompt is empty. If a sweep calls this arm, the code stops with an error. The code does not run with an incorrect prompt. This arm is not built.

Request flow: the orchestrator calls the three arms, the arms write outputs, scoring writes the analysismonorepo · apps/apiOrchestratorsweep + pg-bossin processplaindirect LLM callRailway · HTTP + API keymonorepo · apps/bioagentrheumaai/v1/study/rheumaai-replypokta-grader-bioagentgrader/v1/chat/completionsstudy_arm_outputsOutputs1 row for each note × armbiobadamex-eval.tsScoring4 verdicts for each fieldstudy_analysisAnalysisno per-note keyOnly apps/apiknows the three arms.rheumaai and grader do not call each other.
Figure 1. Request flow. Arrows are calls or writes. The dotted frame contains the separate services.

rheumaai and grader are independent HTTP services. Each service has its own Railway deployment and its own API key. The two services do not call each other and do not share a process. Only apps/api in the monorepo knows that the three arms exist.

One link is only in a comment. The file apps/bioagent/src/study/rheumaai-reply-route.ts says that it copied its authentication method from structured.ts in pokta-grader-bioagent. The code is copied, not imported. The two services have no runtime dependency on each other.

The rheumaai code is in the monorepo, but apps/api does not import it. apps/api calls rheumaai over HTTP at RHEUMAI_STRUCTURED_URL, as it calls grader. Before, this code was in the rheuma-ai-bioagent repo. That repo is retired.

The script pokta-care-monorepo/apps/api/scripts/biobadamex-sweep-run.ts does these steps. The numbers in Figure 2 are the numbers in this list.

Sweep sequence across the script, the queue, the workers, the arm and Postgresscriptssweep-runqueuepg-bossapps/apiWorkersinvokerArmDBPostgresThe operator starts the sweep1 · load the corpus, note_id = sha2562 · read STUDY_ARMS (empty: stop)3 · PLAN_ONLY=1: print the plan and stop4 · check for undrained runs, make study_run5 · one job for each (note, arm)6 · take a job6 · call the arm6 · JSON record6 · write the output row7 · check every 5 s, 45 min maximum7 · cells settled8 · final report by failure cause
Figure 2. Sweep sequence. Time goes down. Dashed arrows are replies. Step 3 is optional.
  1. Load the corpus. The script lists the .docx files in CORPUS_DIR. CORPUS_DIR is a filesystem path outside all git repos. The script calculates note_id = sha256(filename)[:12]. The filename is PHI (the name of the patient). The script does not log or keep the filename.
  2. Resolve the arms. The script reads STUDY_ARMS. If STUDY_ARMS is empty, the script stops and changes nothing.
  3. Dry run (optional). With PLAN_ONLY=1, the script prints the plan (notes × arms) and stops. It makes no provider calls. It does not write to the DB.
  4. Check earlier runs. The script stops if an earlier run is not complete. Then it makes a study_run.
  5. Queue the jobs. For each note, the script reads the note and makes one job for each (note, arm) pair. The jobs go into pg-boss.
  6. Run the jobs. The workers take the jobs. Each worker calls the invoker of the arm. A semaphore limits the number of simultaneous calls to each provider. The worker writes the output to the DB.
  7. Wait for the cells. Every 5 s, the script checks if all cells are settled. A cell is settled if it has an output row or if it has no more retries. The script waits for a maximum of 45 min.
  8. Report. The script counts the expected, settled, output and failed cells. It groups the failures by cause.

The function compareField (biobadamex-eval.ts) compares each field with the gold. It gives one of four verdicts:

Verdict Condition
match The two values are unknown, or the two values are the same. For patient.sex, the comparison uses a catalog similar to HL7 AdministrativeGender, not an exact text comparison.
mismatch The two values are known and are different.
missing The gold has a value. The extraction has no value.
unexpected The extraction has a value. The gold has no value.

The function always uses an explicit “unknown” test, never a falsy test. Thus a real 0 does not count as missing.

Table Contents
biobadamex_study_arm_outputs One row for each (run_id, note_id, arm_id). Columns: model_id, harness, record (the extracted JSON), das28, missing_required, latency_ms and tokens. note_id has no FK. This is intentional.
biobadamex_study_analysis Aggregated data only, in long format. It has no per-note key. This is intentional: it prevents re-identification. Columns: run_id, arm_id, model_id, harness, scope, field_key, metric, numerator, n, value and confidence intervals.

To see the results field by field, filter biobadamex_study_analysis with scope="field" and metric="field_present_rate". For example, this shows the sex field.

The real corpus is outside all repos, at the path in CORPUS_DIR. The census script biobadamex-instrument-census.ts makes sure that this path is not in a git working tree. The code has this comment: “Real patient notes must never be committable”. This is a rule in the code, not only a convention.