Min, Max, Percent, and Clip
Cutoffs, rates, and clip keep scores in a safe range. Agents use them for thresholds, budgets, logs, and evals.
min picks the smallest number. max picks the largest. clip means “if it is too small, raise it; if it is too big, cut it.”
Agents use these all day:
- A threshold is a cutoff: if cosine is below 0.35, do not quote the chunk.
- A budget is a max: stop at 8 steps.
- A rate is “how many out of 100”: 29/32 pass is about 91%.
- Clip keeps a chance in
[0, 1]or a temperature above a tiny floor.
A wrong picture
A wrong picture is: “clip is smoothing” or “clip trains the model.” Clip does not learn. It cuts. Values inside the range pass through. Values outside jump to the wall. If you clip a cosine that is 0.12 up to 0.35, you lied about retrieval quality. Clip is for safety of the next formula (no log of negatives, no negative tokens left), not for making a bad score look like a hit.
Another wrong picture is reporting only a percent. 91% of 32 tickets is 29/32. 91% of 11 tickets is 10/11. Those are different amounts of evidence. Always keep the counts. A third wrong picture is using min/max on the wrong axis: taking max cosine across documents is ranking; taking max across random seeds is hiding variance. Say what you maxed.
The formula in words
min(a, b, ...)is the smallest.max(a, b, ...)is the largest.clip(x, lo, hi) = min(hi, max(lo, x)). Ifxis already inside, you getx. If it is belowlo, you getlo. If it is abovehi, you gethi.- A percent is a rate times 100. Rate is passed divided by total. Percent is
100 * passed / total. - A ratio is one count divided by another. Precision and recall (last lesson) are ratios. Cost per ticket is a ratio.
max(0, budget - used) is clip on the low side: leftover tokens cannot be negative.
A tiny example
Scores [0.91, 0.12, 0.40, 0.77]. Best is 0.91. Worst is 0.12. Keep if ≥ 0.35: you keep 0.91, 0.40, 0.77. You drop 0.12. That is a threshold, not a clip: the 0.12 stays 0.12 in the log; you just do not quote that chunk.
clip(1.2, 0, 1) is 1. clip(-0.1, 0, 1) is 0. clip(0.4, 0, 1) is 0.4. Passed 29 of 32: rate 29/32 ≈ 0.906, percent about 90.6. Tokens left max(0, 800 - 950) is 0, not -150.
Outside 0 and 1 the clip line is flat. Inside, it is just x. Clip bounds a value; a threshold decides keep vs skip.
clip(x) to the range 0 through 1Percent and rate
A percent is a rate times 100. Always keep the counts. 29/32 is more honest than “91%” when the set is small. If you later average percents from two days, go back to counts: (29+40)/(32+50), not the average of 91% and 80%.
A ratio is one count divided by another. Precision and recall are ratios. Cost per ticket is a ratio. If the denominator is 0 (no predicted yeses, no tokens), the ratio is undefined. In code, return 0.0 or skip — and log that the denominator was 0. Do not print 100%.
Clip
Clip is three numbers: the value, a low bound, a high bound.
def clip(x, lo, hi):
return min(hi, max(lo, x))Use clip on:
- probabilities that drifted to 1.0000001 from rounding (so they stay in
[0, 1]) - a chance you will
log(must stay positive, so the low bound might be1e-12, not 0) - a learning rate that must stay positive
- a similarity you will treat as a weight (weights should not be negative if your formula assumes that)
Do not clip a retrieval score up to the threshold and then call it a hit. Thresholds filter. Clips bound.
Run to execute this in your browser. Nothing is sent to a server.
Read the prints. Best is 0.91, worst 0.12. The keep list has three scores; 0.12 is gone. Rate is about 0.906, percent 90.6. Clips: 1.2 becomes 1, -0.1 becomes 0, 0.4 stays 0.4. step < max_steps is True (3 < 8). Tokens left is 0, not -150. You cannot have negative tokens left. max(0, ...) is the same idea as clip on the low side.
A retriever without a cutoff always returns k neighbors, even if every score is junk. if score < 0.35: refuse is min/max thinking. A retry loop is min(attempt, max_tries). Eval dashboards that only show percent hide small n. Print passed/total.
How agents use this
Cutoffs, budgets, and floors are product decisions you write with min, max, and clip.
- RAG: log
cosine=0.22 threshold=0.35 skip. Later you tune the cutoff from data (precision/recall). Without a cutoff, top-k always stuffs k chunks into the prompt, including noise. - Loops:
step < max_stepsis a max budget.min(retries, 3)caps hammering a dead API. - Chances: clip to
[1e-12, 1]beforelog, so you never log a negative from rounding and you never log exact 0. - Temperature:
max(T, 1e-5)so you never divide logits by 0. - Evals: print counts. Clip nothing. A percent without
nis a poster, not a measurement. - Tokens left:
max(0, budget - used). Negative leftover is a bookkeeping bug that will look like “free tokens.”
Write the cutoff next to the score in the log. Write the budget next to the step. Write passed/total next to the percent. Min, max, and clip are how agents stay in a legal range. They are not how agents get smarter.
Tip:Write the cutoff next to the score in the log: cosine=0.22 threshold=0.35 skip. Later you can tune the cutoff from data.Check your understanding