> This page is for RFD4-Proteina, version 1.1.0 (Latest) (default).
> For other versions, use one of these documentation indexes:
> - 1.1.0 (Latest) (default): https://docs.nvidia.com/nim/bionemo/rfd4-proteina/1.1.0/llms.txt
> - 1.0.0: https://docs.nvidia.com/nim/bionemo/rfd4-proteina/1.0.0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nim/bionemo/llms.txt.

# Reward-Guided Search

A plain request returns whatever the model samples. A request carrying a
`search` block instead runs a beam search over the generation trajectory: at
fixed points along the trajectory it branches each surviving candidate,
scores the branches, and keeps the best ones to continue.

This is not best-of-N. Best-of-N pays for every sample in full and throws most
of them away at the end. A beam search spends its budget on trajectories that
are already going somewhere, and abandons the rest partway through, which is
why it returns better designs at the same cost.

Everything on this page is optional. Requests without a `search` block are
unaffected.

## How a Search Runs

At each step in `step_checkpoints`:

1. Every surviving candidate is branched into `n_branch` copies.
2. Each branch is rolled out to a finished structure, purely so it can be
   scored. These are *scoring rollouts*, and they are where a search spends
   its time.
3. Each rollout is scored against the reward: the weighted sum of the metric
   values named in `weights`.
4. The best `beam_width` candidates survive and continue from the checkpoint.
   The rest are discarded.

The first entry of `step_checkpoints` is the start of the trajectory, where
there is nothing yet to prune, and the last is the end of it. So the number of
branch-and-prune rounds is one less than the number of checkpoints.

Cost is roughly `beam_width * n_branch * (len(step_checkpoints) - 1)` scoring
rollouts per replicate. Each deployment enforces its own ceiling on this; refer
to [Deployment Limits](/nim/bionemo/rfd4-proteina/configuration-alternatives#deployment-limits) for
`NIM_MAX_SEARCH_ROLLOUTS`.

## The `search` Block

| Field | Default | Purpose |
|---|---|---|
| `step_checkpoints` | required | Steps at which to branch and prune. Two to 21 entries, starting at `0`, strictly increasing, ending at `num_steps`. |
| `n_branch` | `2` | Branches generated per surviving candidate. 1 to 16. |
| `beam_width` | `3` | Candidates kept after each checkpoint. 1 to 16. All survivors are returned. |
| `reward_metrics_tags` | required | Tags gating which metrics run while scoring. Independent of `metrics.tags`. |
| `weights` | required | Weight per `metric.output_key`. The reward is the weighted sum; a negative weight penalizes. |
| `clip_values` | `{}` | Per-key `min`/`max` applied before weighting, so a term stops contributing past the bound. |
| `checkpoint_overrides` | `{}` | Reward changes taking effect at a given step, keyed by step. |
| `intermediate_save_min_reward` | unset | Also return non-surviving scoring rollouts that reached this reward. |
| `scoring_chunk_size` | unset | Decoded rows per scoring chunk, to bound peak memory. |

`reward_metrics_tags` and `metrics.tags` are separate on purpose. The first
decides what the search scores against while it runs; the second decides what
is reported on the designs that come back. A metric can be in either, both, or
neither.

`clip_values` is how a multi-objective search stops one term from dominating.
A hydrogen-bond count with no upper bound will happily trade away everything
else to add one more bond; clipping it at six says "six is enough, now
optimize something else". Clipping changes only the reward, never the metric
values reported in the response.

### Keeping Intermediates

A scoring rollout that loses its branch is still a complete, finished design,
and it has already been paid for. `intermediate_save_min_reward` returns the
good ones instead of discarding them, which raises the number of usable
designs per GPU-hour at no extra compute cost. A threshold rather than a
boolean, because "all" would bury the beam in near-misses.

Setting it makes the design count exceed `sampling.num_replicates`. Designs
kept this way carry origin `search_intermediate`.

## Choosing a Reward

Any metric the deployment can run may be weighted, including the refolding
oracle's confidence. Scoring against the oracle *during* generation, rather
than only checking it at the end, is the strongest signal a search can use.

This NIM ships with no oracle built in. Without one, a search is not merely
unscored on that axis; it is restricted to the non-oracle metrics, a
meaningfully smaller set of signals. Refer to [Oracles](/nim/bionemo/rfd4-proteina/oracle).

A tag the running deployment cannot satisfy is rejected at request time rather
than silently scoring nothing.

## What Comes Back

A searched response carries a `search` report alongside the designs:

| Field | Meaning |
|---|---|
| `step_checkpoints`, `n_branch`, `beam_width` | What actually ran. |
| `completion_rollouts` | Trajectories rolled to a clean structure purely to score a branch. The honest cost figure. |
| `rollouts` | The same count, kept for compatibility. Read `completion_rollouts`. |
| `reward_keys` | The metric keys the reward was computed from, in weight order. |
| `best_reward` | Highest reward among the returned designs. |
| `intermediates_kept` | Non-surviving rollouts returned because they met `intermediate_save_min_reward`. |
| `state` | Present only for a handover; refer to [Handing the Beam Back](#handing-the-beam-back). |

`completion_rollouts` is not the number of designs returned, and it is usually
much larger. Read it when you want to know what the request cost.

Each design carries an `origin` saying how it was produced. The service sets
it; a request never does.

| Origin | Meaning |
|---|---|
| `sample` | Plain sampling. No search ran. |
| `search_final` | Survived the final pruning step. Chosen over competitors. |
| `search_intermediate` | A completed scoring rollout from an earlier checkpoint, kept because it scored well. Not a member of the final beam. |
| `search_candidate` | A branch handed back unpruned for the caller to rank. Nothing survived anything. |

Branch on `origin`, not on position in the list. `search_final` and
`search_intermediate` always carry a `search_reward`, and `sample` never does.
`search_candidate` carries one too, on every backend: an export scores the
checkpoint it stops at and skips only the pruning, so each branch comes back
with the reward the service would have ranked it by, and with the metrics
`metrics.tags` asked for. That is what makes a local prune reproduce the
service's own.

## Replicates, One Per Batch

<Warning>
A `search` block and a batch cannot combine. A beam returns its survivors and
any kept scoring rollouts as one flat list per replicate, and a batch leaves
no way to attribute an entry to the replicate it came from, so the two are
refused together rather than returning designs whose origin and seed are
guesses. Because `batch_size` defaults to `num_replicates`, a search with
`sampling.num_replicates > 1` must set `sampling.batch_size: 1` explicitly.
</Warning>

Several replicates are supported, and each runs as its own batch. That is
what shapes the handover below: the service makes one model call per
replicate, so the candidates of replicate 0 all arrive before any of
replicate 1's.

Refer to [Replicates and
Batching](/nim/bionemo/rfd4-proteina/prerequisites#replicates-and-batching).

## Handing the Beam Back

The service prunes using the reward you described. Sometimes the model that
should decide which candidates survive is one the service has never heard of, such as your own scoring model, a wet-lab constraint or a human looking at structures.

Two fields let you take that decision. The service branches, hands the
candidates back, and stops. You rank them on your own time, while the GPU
serves other requests. Then you send the survivors back and the trajectory
continues from where it paused.

| Field | Effect |
|---|---|
| `search.export_candidates` | Stop at the first checkpoint past the start and return every branch along with the state needed to continue it. The branches are scored to reach that checkpoint, so the call costs one interval of rollouts; what it skips is the prune. |
| `search.resume` | Continue a beam returned earlier: `{state, selection, seed}`. |

The service never prunes a handover. Every branch comes back and you choose,
which is the entire point of splitting the run. `export_candidates` and
`resume` are the two halves of one round trip, so send one per call.

### The Returned State

A handover response carries `search.state`:

| Field | Meaning |
|---|---|
| `payload` | Base64 search state. Opaque. Send it back unmodified. |
| `backend` | Which backend wrote it: `bioir`, or `native` for either OSS backend. This is an internal label and does not match `model.execution_backend`. |
| `step` | The sampling step the state belongs to. |
| `candidates` | Candidates the state carries, in the order the designs are returned. |
| `num_replicates` | Inputs the state carries. Candidates are grouped by input: candidates `[r * candidates / num_replicates, ...)` belong to input `r`. |

The service keeps no copy and holds nothing between calls. The state is yours,
and a resume is just another stateless request that happens to carry one.

### Choosing Survivors

Designs come back in candidate order: design `i` is candidate `i`. So ranking
the returned structures gives you the indices directly, and you never parse
the payload.

Send those indices as `resume.selection`, one entry per beam slot per input,
in slot order. With several replicates, entry `j` must name a candidate of
input `j % num_replicates`. A selection that moves a candidate from one input
to another is refused: every shape would still be valid, and the results would
silently mix.

The entries are interleaved by input; the candidates are not. Each design
reports its own `replicate_index`; read that rather than deriving an input
from the index.

With `beam_width: 2`, `n_branch: 2` and `num_replicates: 2`, an export returns
eight candidates: rows 0–3 are input 0 and rows 4–7 are input 1, because each
replicate ran as its own batch. A selection then names one candidate per slot
per input, interleaved by input:

```json
{ "search": { "resume": { "selection": [0, 4, 1, 5], "seed": 11 } } }
```

Slot 0 keeps candidate 0 for input 0 and candidate 4 for input 1; slot 1 keeps
1 and 5. `[0, 1, 2, 3]` is refused, because candidates 1 and 3 belong to input
0 and sit at positions that name input 1. Repeating an index within its own
input is allowed; a beam may keep one branch twice.

A selection is always required. Nothing was pruned before the handover, so
the service has no way to know which candidates you kept.

`resume.seed` seeds the continued branches and is independent of the seed the
first call used, so a resume may continue on a new stream. It names the whole
request, not one replicate: replicate *i* continues on `(resume.seed + i) mod
2**63`, the same rule `sampling.seed` follows under [Replicates and
Batching](/nim/bionemo/rfd4-proteina/prerequisites#replicates-and-batching).

Set it equal to the first call's `sampling.seed`, and set `sampling.seed` on
both calls, and the split run returns designs **identical** to the
uninterrupted one whenever you keep what the service would have kept. Both
conditions are needed: the resume rebuilds the input features, and an input
whose length is a range is drawn again without a seed.

On a resume, `step_checkpoints` begins at the step the state belongs to rather
than at `0`, and still ends at `num_steps`.

### A State Belongs to Its Backend

The backends do not share a trajectory, so a state is refused by any backend
other than the one that wrote it. Resume it where it was made. Refer to
[Execution Backend and Compile
Tuning](/nim/bionemo/rfd4-proteina/configuration-alternatives#execution-backend-and-compile-tuning).

### Limits and Refusals

- A state is at most 64 MiB of base64 text. It grows with candidates and token
  count, not with the schedule length.
- A selection names at most 256 candidates.
- A state holds one block per replicate, each at that replicate's own padded
  token count. A resume must featurize each input to the length its block
  records, which is what sending the same `sampling.seed` guarantees.
- A state is rejected, rather than reinterpreted, when it comes from a
  different release, different checkpoints, a different backend, or an input
  whose padded token count does not match. Each refusal names what differs.
- The payload is read back with `weights_only=True`, so loading a state cannot
  execute code.
- **The state is not signed.** Nothing in it authenticates its contents, so a
  payload altered in transit may load with changed tensor values rather than
  being rejected; and the backends differ on how far they notice. Treat a
  state as data you are responsible for, keep it on a path you trust, and do
  not accept one from a third party.
- The rollout ceiling counts one interval for a handover call, not the whole
  schedule, so a split run is never refused for being more expensive than the
  single call it replaces.

### Round Trip

A `small_molecule_binder` request that branches at step 30 and stops, with the
candidates to be ranked externally. The input file is elided for readability;
refer to [Example Requests](/nim/bionemo/rfd4-proteina/example-requests) for a complete one.

```json
{
  "task": "small_molecule_binder",
  "input": {
    "format": "annotated_cif",
    "example_id": "sam_hbonds",
    "file": { "filename": "sam_hbond_donor_acceptor.cif", "content": "..." }
  },
  "sampling": {
    "recycle_strategy": "thinking_medium",
    "num_replicates": 1,
    "seed": 7
  },
  "search": {
    "step_checkpoints": [0, 30, 60],
    "n_branch": 2,
    "beam_width": 2,
    "export_candidates": true,
    "reward_metrics_tags": ["interchain_interactions"],
    "weights": { "interchain_interactions.hbond_atom_pair_count_coi": 1.0 }
  },
  "metrics": { "tags": ["design", "interchain_interactions"] }
}
```

The response returns every branch with origin `search_candidate`, plus
`search.state`. Rank those designs however you like, then continue the two you
chose:

```json
{
  "task": "small_molecule_binder",
  "input": {
    "format": "annotated_cif",
    "example_id": "sam_hbonds",
    "file": { "filename": "sam_hbond_donor_acceptor.cif", "content": "..." }
  },
  "sampling": {
    "recycle_strategy": "thinking_medium",
    "num_replicates": 1,
    "seed": 7
  },
  "search": {
    "step_checkpoints": [30, 60],
    "n_branch": 2,
    "beam_width": 2,
    "reward_metrics_tags": ["interchain_interactions"],
    "weights": { "interchain_interactions.hbond_atom_pair_count_coi": 1.0 },
    "resume": {
      "state": "<search.state.payload from the first response>",
      "selection": [2, 0],
      "seed": 11
    }
  },
  "metrics": { "tags": ["design", "interchain_interactions"] }
}
```

The two calls together cost the same completion rollouts as the single
uninterrupted call they replace. Splitting the search buys you the choice, not
extra compute.