﻿---
title: Suggest
description: suggest turns a diagnosis into an experiment. It asks the model for new request templates. It runs every one against the whole set. It then compares each...
url: https://docs-v3-preview.elastic.dev/llm/suggest
---

# Suggest
`suggest` turns a diagnosis into an experiment. It asks the model for new request templates. It **runs every one against the whole set**. It then compares each with the
current template, on the queries the model saw and on the queries it did not.
```text
$ judy suggest wands.judgements.yaml --target lexical --variants 3
ran 480 queries against lexical in 12.2s
including the index mapping and settings (556 characters); --no-index-info leaves them out
ran 480 queries against lexical+min-should-match-75 in 12.1s
ran 480 queries against lexical+phrase-boost-product-name in 12.0s
ran 480 queries against lexical+semantic-hybrid-product-semantic in 14.8s
ndcg@10 on lexical: 0.594; model claude-haiku-5-5 saw 8 of 336 training queries; holdout 144 queries

variant                      train                  holdout                verdict
min-should-match-75          -0.006 (93w 68l, p=0.60) -0.049 (35w 30l, p=0.03) no gain
phrase-boost-product-name    +0.003 (9w 7l, p=0.25) +0.004 (6w 1l, p=0.11) better on both
semantic-hybrid-product-semantic +0.033 (130w 35l, p=0.00) +0.037 (60w 16l, p=0.00) better on both

Nothing was changed in your configuration. To adopt a variant, copy its file over the target's template and confirm with: judy compare <results> <results>.
```

(The model's reason for each variant and the file it was written to are printed under its row.)
```mermaid
flowchart LR
    All["All queries"] --> Train["Train: 70%<br/>the model sees these"]
    All --> Hold["Holdout: 30%<br/>the model never sees these"]
    Train --> M(("Model"))
    M --> V["Variants"]
    V --> Both["judy runs every variant<br/>on both halves"]
    Hold --> Both
    Both --> Verdict["Better on both, no gain,<br/>or likely overfit"]
```

What makes this trustworthy:
- **A holdout.** judy splits the queries by a hash of their id, and 30% (`--holdout`) never reach the model. With fewer than four
  queries there is no split, and judy warns. Every variant is measured on both halves. A gain on the seen queries that does not
  carry over is reported as *likely overfit*.
- **Bad ideas are caught.** `min-should-match-75` sounds sensible. It lost 0.049 nDCG on the held-out queries (35 better, 30 worse,
  p = 0.03), and judy says "no gain".
- **The good idea is measured.** Putting the `semantic_text` field into the query gained 0.033 on the queries the model saw. It
  gained 0.037 on the 144 it did not see, with 60 queries better and 16 worse.
- **Validated before it runs.** A variant has to parse, use `{{query}}` (or `?query` for ES|QL), and differ from the current
  template. Variants that do not are dropped, with the reason on standard error.
- **A variant that breaks is reported, not scored.** In another run the model wrote a `semantic` query with the field in the wrong
  place. Every request failed, and judy said so instead of showing a zero:
  ```text
  semantic-query-boost   failed: 480 queries errored, first: POST /wands/_search returned 400: x_content_parse_exception:
                         [1:278] [semantic] unknown field [product_semantic]
  ```
  The same run flagged `minimum-should-match-and-description-boost` as *likely overfit*: no change on the queries the model saw
  (0.000) and worse on the held-out ones (-0.020).
- **Your configuration never changes.** Each variant is written next to the set, such as
  `wands.lexical.semantic-hybrid-product-semantic.json`. Adopt one by copying it over the template.

`suggest` works on `dsl` and `esql` targets.

| Option                  | Meaning                                                           |
|-------------------------|-------------------------------------------------------------------|
| `--variants <n>`        | how many variants to ask for (default 3)                          |
| `--max-queries <n>`     | how many of the worst training queries the model sees (default 8) |
| `--holdout <fraction>`  | the share of queries kept from the model (default 0.3)            |
| `--metric <kind@k>`     | the metric to improve (defaults to nDCG)                          |
| `--dry-run`             | say what would be sent, and send nothing                          |
| `--no-index-info`       | leave the mapping and settings out                                |
| `--provider`, `--model` | the LLM, overriding `judy.yaml`                                   |


## Reading the results with care

A variant that scores better is a hypothesis. With a small set the p-values stay high, so check a promising variant on queries the
set does not hold. The advisors do not yet know which retrieval mode a query used, so a suggestion can ignore that a query was
answered semantically.