|
| 1 | +# LLM-judged response match |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Evaluates the shared home-automation agent with `final_response_match_v2`, a |
| 6 | +criterion that uses a judge model to decide whether the agent's final answer |
| 7 | +is *semantically* equivalent to a reference response. Because the judge reasons |
| 8 | +about meaning rather than word overlap, it tolerates phrasing and formatting |
| 9 | +differences that `response_match_score` (ROUGE-1) would penalize, for example |
| 10 | +"The temperature in the Kitchen is currently 24°C." vs. the reference "It's |
| 11 | +currently 24 degrees Celsius in the Kitchen." |
| 12 | + |
| 13 | +This criterion needs a model credential for the judge (a Gemini API key or |
| 14 | +Vertex), in addition to the credential used for the agent's own inference. |
| 15 | + |
| 16 | +## Sample Inputs |
| 17 | + |
| 18 | +The eval set (`home_automation.evalset.json`) contains one single-turn case: |
| 19 | + |
| 20 | +- `How warm is the Kitchen right now?` |
| 21 | + |
| 22 | +The reference answer is deliberately phrased differently from how the agent is |
| 23 | +likely to respond, so ROUGE-1 would score low while the semantic judge passes. |
| 24 | + |
| 25 | +## How To |
| 26 | + |
| 27 | +Run the sample from the workspace root: |
| 28 | + |
| 29 | +```bash |
| 30 | +adk eval contributing/samples/evaluation/home_automation_agent \ |
| 31 | + contributing/samples/evaluation/llm_judge_match/home_automation.evalset.json \ |
| 32 | + --config_file_path contributing/samples/evaluation/llm_judge_match/eval_config.json \ |
| 33 | + --print_detailed_results |
| 34 | +``` |
| 35 | + |
| 36 | +`adk eval` takes the agent folder and the eval-set file as two separate |
| 37 | +arguments, so this folder holds only eval data (`home_automation.evalset.json`), |
| 38 | +the criteria config (`eval_config.json`), and this README, with no agent code. |
| 39 | + |
| 40 | +### `judge_model_options` |
| 41 | + |
| 42 | +`final_response_match_v2` is configured through `judge_model_options` in |
| 43 | +`eval_config.json`: |
| 44 | + |
| 45 | +- `judge_model`: the model that acts as the judge. It is resolved through the |
| 46 | + standard ADK model registry, so it is a normal model name (here |
| 47 | + `gemini-2.5-flash`). The judge is a separate model from the one the agent uses |
| 48 | + for its own inference. |
| 49 | +- `num_samples`: how many independent judgements to request from the judge |
| 50 | + model (here `5`). The criterion takes a majority vote across those samples |
| 51 | + and converts the fraction of "equivalent" votes into the score, which reduces |
| 52 | + the impact of any single noisy judgement. |
| 53 | + |
| 54 | +The `threshold` is `0.8`, so at least a strong majority of the judge samples must |
| 55 | +find the responses equivalent for the case to pass. |
| 56 | + |
| 57 | +### Semantic vs. lexical matching |
| 58 | + |
| 59 | +Use `final_response_match_v2` when a correct answer can legitimately be worded or |
| 60 | +formatted many different ways and you care about *meaning*, not exact wording: |
| 61 | +paraphrases, reordered clauses, "24°C" vs. "24 degrees Celsius", extra polite |
| 62 | +framing, and so on. A lexical metric like `response_match_score` (ROUGE-1, used |
| 63 | +in the `basic_criteria` sample) only measures word overlap, so it would penalize |
| 64 | +these harmless rephrasings and force you to lower the threshold until it no |
| 65 | +longer distinguishes right answers from wrong ones. The trade-off is that the |
| 66 | +LLM judge requires a model call per sample (cost and latency) and, being |
| 67 | +model-based, can vary slightly between runs; `response_match_score` is fully |
| 68 | +local and deterministic. Reach for the semantic judge when meaning matters more |
| 69 | +than phrasing, and keep the lexical metric when you need cheap, deterministic |
| 70 | +scoring. |
| 71 | + |
| 72 | +## Related Guides |
| 73 | + |
| 74 | +- Evaluation overview: https://adk.dev/evaluate/ |
| 75 | +- Evaluation criteria reference: https://adk.dev/evaluate/criteria/ |
0 commit comments