# Pocket researcher: answer questions from your own documents

Source: https://docs.surogate.ai/engine/examples/kits/research/

Qwen3.5-2B learns to answer multi-hop questions by searching a private document
collection: search, read, search again, then answer. Nothing leaves the machine. 40 GRPO
steps on one GPU take its answer F1 on 300 held-out questions from **26.0% to 63.6%**.

| Steps | Time on one L40S | Before | After | Held-out set | Adapter |
|---|---|---|---|---|---|
| 40 | about 1 h | 26.0% | **63.6%** | 300 questions, answer F1 | [Hub ↗](https://huggingface.co/cetusian/sonorca-2b) |

## The task

Questions come from [HotpotQA](https://huggingface.co/datasets/hotpotqa/hotpot_qa)
(CC BY-SA 4.0), the distractor setting, hard level only. Each question needs facts from
two documents. The kit uses 2,000 training questions and 300 held-out ones from the
validation split, both sampled with a fixed seed.

The collection is every Wikipedia paragraph attached to any of these questions: 22,184
paragraphs. So the two paragraphs a question needs sit among the paragraphs of all the
other questions. The model gets two tools as native tool calls, and has up to 8 turns:

- `search`: BM25 over the collection. It returns the 5 best matches, each as its title
  and opening words.
- `open_document`: the full text of one paragraph, by title.

The prompt asks for `<answer>...</answer>` with a short answer: a phrase, a name, a
number, or yes or no.

**Why the task is hard:** searching once with the raw question finds both supporting
paragraphs in the top 5 only 51% of the time (at least one: 96%). So the model has to
learn to read what it found and search again for the second fact.

**Reward:** answer F1, the HotpotQA and SQuAD token F1 after normalisation (lower case,
no punctuation, no articles). It scores the text inside `<answer>`, or the whole final
reply when there is no tag. A short right answer earns 1. A padded answer earns part, so
a list of guesses lowers the score. A yes or no answer earns 1 only when it matches
exactly. Logged but not rewarded: exact match, and whether the answer appears as whole
words in a reply of at most 300 characters.

## Run it

```bash
CUDA_VISIBLE_DEVICES=0 surogate grpo-colocate \
  --train examples/kits/research/train.yaml \
  --infer examples/kits/research/infer.yaml \
  --orch  examples/kits/research/orch.yaml
```

The HotpotQA files download from Hugging Face on first use, and the environment builds
the search index in memory when it loads. It needs no server and no network after that.

16 questions × 8 rollouts a step, up to 8 turns of 512 tokens each, thinking off, LoRA
rank 16. Learning rate 5e-5 with cosine decay to a tenth by step 40, the same schedule as
the [mcp kit](/engine/examples/kits/mcp/). The run evaluates before step 0 and every 10 steps, and keeps a
checkpoint every 10 steps. About one hour of training on one L40S.

This kit needs engine 1.5.17 or later. On 1.5.16, long multi-turn prompts at high
concurrency crashed the engine ([#381](https://github.com/invergent-ai/surogate/pull/381)).

## Measure again

| | Held-out answer F1 (300 questions) |
|---|---|
| Base Qwen3.5-2B | 26.0% |
| After 10 steps | 49.6% |
| After 20 steps | 58.6% |
| After 30 steps | 61.4% |
| **After 40 steps** | **63.6%** |

Greedy decoding, the same prompt and budget as training, one run. The score was still
rising at step 40, so a longer run may score higher.

## Use your own documents

The environment is two files in
[environments/pocket-research](https://github.com/invergent-ai/surogate/blob/main/environments/pocket-research/pocket_research.py).
To train on your own collection, change two things:

- `tasks.py`: return your documents as a `{title: text}` dict, and your questions, each
  with a short answer you can check.
- `SYSTEM` in `pocket_research.py`: describe your collection.

The search is plain BM25 in the standard library, so it needs no index server. Run
`python pocket_research.py` in the environment's directory first: it checks the scorer
and the tools on hand-written cases, then loads the full task. The full load downloads
the HotpotQA files the first time.

## Limits

- F1 pays for word overlap. A right answer in other words, such as "JFK" for "John F.
  Kennedy", scores low.
- One collection of short Wikipedia paragraphs. Long documents are cut to their first
  1,500 characters when opened.
- One run, one seed. We did not measure how much a second run would differ.

Next: compare the other [GRPO kits](/engine/examples/kits/), or read [RL Environments](/engine/guides/rl-environments/) to build a reward of your own.
