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 three harnesses
Section titled “The three harnesses”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
Section titled “Request flow”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.
Sweep flow
Section titled “Sweep flow”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.
- Load the corpus. The script lists the
.docxfiles inCORPUS_DIR.CORPUS_DIRis a filesystem path outside all git repos. The script calculatesnote_id = sha256(filename)[:12]. The filename is PHI (the name of the patient). The script does not log or keep the filename. - Resolve the arms. The script reads
STUDY_ARMS. IfSTUDY_ARMSis empty, the script stops and changes nothing. - 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. - Check earlier runs. The script stops if an earlier run is not complete. Then it makes a
study_run. - 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. - 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.
- 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.
- Report. The script counts the expected, settled, output and failed cells. It groups the failures by cause.
Scoring: what “completeness” means
Section titled “Scoring: what “completeness” means”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.
Where the results are
Section titled “Where the results are”| 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.
Real note corpus
Section titled “Real note corpus”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.