decisions 0.2.0: Gemini, Venn and a test of Box (design)

plans/2026-11-24-decisions-0.2.0-design.md

# decisions 0.2.0: Gemini, Venn and a test of Box (design)

Date: 2026-11-24. Decisions: D301 to D307, D310 to D312. Status: approved by fmm on 2026-11-24 (D313), after the builder check.

## Intent

decisions 0.1.x calls Jev (TypeSafe), the OpenAI Decisions API, OpenRouter, Microsoft Foundry and SystemOne servers. Two new decision models appeared in November 2026:

- **Gemini Decisions API** (Google, beta from 2026-11-11, model `gemini-decision-1`). fmm wants it with the use cases of the paper and the tests that gpt-6-luna had (D302).
- **Venn** (venn-vdm, Mark Russinovich, MIT, version 0.1.0, model `venn-1`): a local Python server. fmm wants it for text and for single images (D306).

Box (the localization primitive of Jev 1.14) goes in only if it works well in the examples of the package (D307). A test on the `textiles` data of the package decides.

Version 0.2.0 goes to CRAN when the work on Gemini and Venn is done (D310, which replaces the date of D305). Box does not hold the release. Users can install the new features from GitHub before that.

## Goals

1. `decider_gemini()` and `decider_venn()` work with `decide()`, `decision_setup()`, `score_setup()` and the calibration of a setup, as the other deciders do.
2. Gemini is in the vignettes "Choosing a model", "Images" and the case study "Industrial image inspection", with the same treatment as gpt-6-luna (D197, D302).
3. Venn is in the vignette "Open models", on the injury texts, with a calibration step (D306).
4. The test of Box on the textiles gives a clear yes or no for Box in 0.2.0 (D307).

## Non-goals

- No change to the Space (decisions-space) in this milestone.
- No reference images for Venn: the in-memory index and `nearest_reference` stay out (D306).
- No batch requests (several inputs in one request) for any provider.
- No Gemini `resolution` setting for images, and no Gemini audio, video or PDF input.
- No GPU set-up for Venn (`venn serve` runs on CPU only).

## Anti-goals

- No paid call without a budget row (D301: gemini, USD 15; D307: typesafe, USD 0.10).
- No result in a vignette that a reader cannot rerun from `data-raw/`.
- No claim in a vignette that the numbers do not support. Venn is weaker on text and at chance on images without references; the vignettes say so.
- No change to the request bodies of the existing providers. The saved fixtures of 0.1.x must still pass.

## Constraints

- CRAN: no network call in tests, examples or vignettes. Vignettes read saved results from `inst/extdata`. URLs in DESCRIPTION must not redirect (use `https://aistudio.google.com/docs/decisions-api`, not `ai.google.dev`).
- Imports stay as in 0.1.1. R 4.3.0 or newer.
- The Gemini API is beta (`/v1beta/`). Venn is a research preview with an `alpha` endpoint. The documentation of each decider says so.
- Code style of the package: httr2, purrr, native pipe, `pkg::fun`, roxygen with markdown. Writing in the record: 80% ASD-STE100.

## Approaches

| Part | Approach considered | Result |
|---|---|---|
| Release | Two releases: 0.1.1 now, 0.2.0 later (chosen, D305); 0.2.0 at a fixed date or when Gemini and Venn are done (chosen, D310) | fmm chose two releases, and 0.2.0 when Gemini and Venn are done |
| Gemini request | A new format `gemini` (chosen); the OpenAI builder (its questions are an array, noul is `predicate`, references sit in the questions: Gemini questions take text only); the SystemOne builder (Gemini has no `assets` and no `state`) | One sensible way (stated on 2026-11-24, no objection) |
| Gemini answers | `parse_systemone()` as it is (chosen): the answers have the same shape (checked with 8 real calls on 2026-11-24) | - |
| Venn | Text and single images (chosen, D306); or also references through the in-memory index | fmm chose text and single images |
| Box | A test on the textiles first (chosen, D307); or Box out of 0.2.0 | fmm chose the test |

## Design

### 1. Gemini

**Decider.** `decider_gemini(model = NULL, credentials = NULL, input = NULL)`. Provider `"gemini"`, format `"gemini"`, base URL `https://generativelanguage.googleapis.com`, path `v1beta/decisions`, default model `gemini-decision-1` (with the message of `default_model()`). The key comes from `GEMINI_API_KEY`. The key goes in the header `x-goog-api-key`, redacted (not a bearer token). `provider_name()` gives "Google Gemini".

**Input types.** A new row: `"gemini"`, `"^gemini-decision-"`, `"text+image"`, checked 2026-11-24.

**Request body** (`build_gemini()`), verified with real calls on 2026-11-24:

- `model`, `questions` and `input`.
- `questions` is an object keyed by question name. Each question has `type` (`noul`, `choice`, `score`), `instructions`, and `criteria` when needed:
  - noul: `criteria` = `{true_description, false_description}` only when an answer has a description; else no `criteria`.
  - choice: `criteria` maps each answer to its description, `""` for an answer with no description.
  - score: `criteria` is an array of level texts, lowest first, `"<name>: <description>"` (or the name alone), as `systemone_question()` does.
- `input` is the text alone (one string) when there is no image and no reference. Else it is an array of content blocks: for each answer with references, a text block "Reference images of the answer `<answer>`:\n" and its image blocks; then the text block "`inspection_image`, the image to inspect:\n" and the image block; then the text of the input, if any. Each text block ends with "\n", because Gemini joins adjacent text blocks with no separator. An image block is `{type: "image", mime_type: "image/jpeg", data: <base64, no line breaks>}`. The shared parts come first (D171).

**Checks before any request** (in `decide()`, for the Gemini format): each question name matches `^[A-Za-z0-9_-]{1,64}$`; each choice has 2 to 255 answers; each score has 2 to 255 levels; no answer name has a space at its start or end, and none is longer than 128 characters. Each failed check stops with a message that names the rule.

**Answers.** `parse_answers()` uses `parse_systemone()` for the format `gemini`. The input tokens come from `usage.total_input_tokens` when `usage.input_tokens` is missing. Gemini reports no cost, so `.cost` is `NA`, as for OpenAI. The documentation says that Gemini clamps a noul to 0.01 to 0.99.

**Tests.** `data-raw/probe_providers.R` gets the provider `gemini` with the same cases as OpenAI (noul, noul with descriptions, choice, score, several questions, image, image with references, a refused request). The responses become fixtures. Unit tests cover `build_gemini()` (the body of each case, the order of the blocks, the newlines), the checks before a request, the header, and the reading of each fixture. `test-live.R` gets one Gemini call (with `DECISIONS_LIVE_TESTS`).

### 2. Venn

**Decider.** `decider_venn(model = "venn-1", base_url = "http://127.0.0.1:8000", input = NULL)`. Provider `"venn"`, format `"venn"`, path `api/alpha/decisions`, no key (`provider_key()` gives `NULL`). `provider_name()` gives "Venn". Input types row: `"venn"`, `"^venn-"`, `"text+image"`, checked 2026-11-24.

**Request body** (`build_venn()`), from the trial of D304:

- Text: the SystemOne body (`build_systemone()`): `state = {text}`. A real call with this body gave HTTP 200 and the same answer as a plain string.
- Image: `state = {image: <base64, no line breaks, no data URI>}` and the header `X-Venn-Experimental: media`. One image in each request.
- A text and an image in the same input: stop before any request. Venn ignores the text when it gets an image.
- Reference images: stop before any request (D306).

**Answers.** `parse_systemone()`. The `venn` block of each answer is not read. Venn reports 0 tokens and 0 cost: `.input_tokens` and `.cost` are `NA` for Venn. Errors on the Host and Origin checks come back as plain text; `failed_result()` keeps them word for word.

**Documentation.** `decider_venn()` gives the install and start commands (Python 3.12, `pip install ".[embedding]"`, `venn download-embedder`, `venn serve`), says that the server is a research preview that runs one request at a time on CPU, that its probabilities are not calibrated, and that its image input is experimental and was at chance on the textiles without references (AUC 0.48, D304).

**Tests.** Fixtures from the saved responses of D304 (noul, noul with descriptions, choice, score, several questions, image noul and choice, the errors of an unknown model and of a missing media header). Unit tests cover `build_venn()`, the header, the stops for text plus image and for references, and the reading of each fixture. `test-live.R` gets one Venn call (with `DECISIONS_LIVE_LOCAL`).

### 3. Vignettes

All new results are saved runs, made by `data-raw/vignette_results.R` and `data-raw/study_again.R`, with each paid call in `calls/gemini-calls.csv` of the study (D301).

- **Choosing a model:** Gemini is the fourth model on the same 75 injury reports and the same question. The tables of performance, cost and time get a Gemini row. The table of providers and keys gets `decider_gemini()` and `GEMINI_API_KEY`.
- **Images:** Gemini on the same 46 textile images, with and without the 4 reference images. The table of performance gets the Gemini rows.
- **Industrial image inspection (case study):** Gemini gets the treatment of gpt-6-luna (D197): its own description loop on each of the four datasets (one fresh agent for each dataset in a blind sandbox, the loop instructions of the study, two references per class, at most 6 candidates, candidate 1 the generic description, scored with `score_setup()`), then the grid, the calibration, the folds and the test, with the cost and time. The section "Reruns" reports a second run of the vignette code for Jev, gpt-6-luna and Clef-Flash (D213); that second run scored the test images again. Gemini gets a second full run, with the test, for that section (D311). The first run stays the reported result.
- **Open models:** a section on Venn: the start of the server, `decider_venn()`, the 464 injury reports (`ohio_injuries`) with the 5-way choice of "Choosing a model", accuracy and AUC, and a calibration step: a calibrator fitted with probably on one half of the rows and scored on the other half, with the probabilities before and after.

### 4. Box test on the textiles (D307)

- **Truth boxes:** the 14 input images with a local defect, and the local-defect reference `local_textile_0471.jpg`, get a truth box. Claude Code first tries to make the textiles again with the code that made them (`fine_tuned_jev/imgs/textile_images/extract_textile_images_from_r_textile_pkg.R`, `set.seed(2024)`, `spc4sts::imposeDefect()`). If the new files match the old ones pixel for pixel, the truth boxes come from the location of the simulated defect. Else Claude Code draws them. In both cases fmm checks them on a contact sheet and corrects or accepts them (Claude Code's call).
- **Inputs fixed before any call** (Claude Code's call): the references of T (the two nominal references as nominal crops, and a square crop around the truth box of the local-defect reference); the two Box wordings ("the defect", and one sentence for the textiles that Claude Code writes before the run); and the score of the image decision (1 minus the probability of the option "none" of the tile Choice of T, as in D303; the whole-image Noul for Z). fmm sees them on the same contact sheet. Nothing is changed after the first call, because the 46 images are both the data and the gate. The 9 images with a global defect have the whole image as the truth box and count only in the image decision.
- **Strategies** (from D303): T, one Choice over 9 tiles with the reference crops, then a Box in the best tile at 1024 px; Z, a Box on the whole image at 1568 px, then a Box in a crop of 3 times that box. The textiles are 250 x 250 px, so both enlarge the image first. Model `jev-1.14.0`.
- **Measures:** images pointed (the center of the box in the truth box, 2% margin), IoU 0.3 and 0.5, the image decision on the 23 nominal and 23 defective inputs (AUC), calls and USD for each image.
- **Gate** (D312): Box goes into decisions if the better of T and Z points to the defect in at least 12 of the 14 local-defect images. Then a short design of the Box functions follows, with its own approval. Box joins 0.2.0 only if those functions are ready when Gemini and Venn are done (D310); else it goes in a later release. If Box fails the gate, it stays out, and the study M7 goes on.
- **Code and budget:** the worktree `fine_tuned_jev-box` (branch `m7-box`), scripts `box/scripts/d307_*.R`, results in `box/results/d307_textiles/`. At most 400 calls and USD 0.10 (budget row of D307).

### 5. Order of the work and release

1. The Box test (section 4) starts first, because the truth boxes wait on fmm.
2. Gemini (sections 1 and 3, without the case study), then Venn (sections 2 and 3), then the Gemini case study.
3. Each part is a branch of decisions that merges into `main` after its tests and an R CMD check pass. `main` stays installable from GitHub.
4. When Gemini and Venn are done (D310): version 0.2.0, NEWS, README (the table of providers), DESCRIPTION (the Description names 'Google Gemini' and 'Venn' with their URLs), the agent skill in `inst/skills/decisions`, `data-raw/formats.md`, the checks of 0.1.1 (local with the S7 of CRAN, GitHub Actions, R-hub, win-builder), cran-comments.md (fmm sees it first), and the submission by fmm.

## Left to the builder

- The names and the order of the new tests; the split of the work into tasks.
- The words of the documentation and of the vignette sections, within the facts above.
- The seed and the split of the Venn calibration.
- How the Box scripts reuse the code of D303.