Sub topic 12
Measuring quality: acceptance rate, latency and retention
This chapter covers the three numbers most teams use to judge a completion or next edit suggestion feature, and the ways each one misleads. It assumes you know how a suggestion is requested, debounced, cancelled, post-processed and shown (earlier chapters), that you can read Python, and that you know what a percentile is.
Why one number is not enough
A completion feature can be tuned to look good on any single metric.
- Show only suggestions the model is very sure about, and acceptance rate rises while the feature helps less often.
- Use a smaller model, and latency drops while the suggestions get worse.
- Accept everything in a trial, and acceptance looks fine until you check whether the code survived.
So you read the metrics as a set. Acceptance rate says whether users liked what they saw. Latency says whether they saw it in time. Retention says whether accepting it was a good decision.
The event funnel
Every metric comes from a log of events along the path of one suggestion. If the logging is wrong, every metric built on it is wrong.
Log at least these events, each with a request ID so you can join them:
- Request sent, with a timestamp.
- Response received, with a timestamp and the suggestion length.
- Suggestion shown. A suggestion that arrives after the user has moved on is not shown.
- Accepted, fully or partially, with the number of characters accepted.
- Retention check, taken after a fixed delay.
Acceptance rate
Acceptance rate is accepted suggestions divided by suggestions shown. The choice of denominator causes most of the errors.
| Denominator | What it measures | Typical problem |
|---|---|---|
| Requests sent | End-to-end yield, including cancellations and filtering | Falls when you debounce more, though nothing got worse |
| Suggestions shown | How good the visible suggestions are | Rises when you filter aggressively |
| Suggestions visible for a minimum time | Suggestions the user could actually read | Needs a visibility timer, which is easy to get wrong |
Many teams count a suggestion as shown only after it has been visible for a short time, often a few hundred milliseconds. Without that rule, a suggestion that flashes up and vanishes while the user types counts as a rejection. That drags the rate down for reasons unrelated to quality.
Other things that distort acceptance rate:
- Suggestion length. Short suggestions such as a closing bracket are accepted often. Long multi-line ones are accepted less. A feature that suggests only brackets has a high rate and little value.
- Partial acceptance. If the user accepts one word at a time, a binary accepted flag hides the effect. Track accepted characters as well as accept events.
- Context. Acceptance differs by language, file type and whether the user is writing new code or editing old code. Compare like with like.
- Habit. Some users press Tab out of habit and delete the text afterwards. Acceptance alone cannot see this.
A useful companion is the share of characters. This is accepted characters divided by all characters typed or accepted in the session. It measures how much of the text came from the feature, but it also rewards verbose suggestions, so read it next to retention.
Acceptance for next edit suggestions
A next edit suggestion often takes two steps. The user first jumps to the proposed location, then applies the change. Log both, because a high jump rate with a low apply rate means the location is right and the content is wrong. A low jump rate means the model is predicting edits the user does not want to make at all. Edit suggestions are also fewer and larger than completions, so compare their rates with completions only after normalising by characters changed.
Latency
Latency is the delay between the user's last keystroke and the suggestion appearing. A completion that arrives after the user has typed three more characters is useless, so the budget is tight.
Break it into parts so you know which one to fix:
- Debounce wait. A deliberate delay you chose, such as the 150 ms in the provider example earlier in this tutorial.
- Context assembly. Reading the prefix, the suffix and related files, and building the prompt.
- Network round trip. Distance to the server, connection reuse and TLS setup.
- Time to first token. Queueing plus processing of the prompt. Long prompts cost more here.
- Generation time. Tokens produced times time per token. Shorter suggestions finish sooner.
- Post-processing and rendering. Trimming, filtering and drawing the ghost text.
Report percentiles and not averages. The mean hides the slow tail that users notice. Track p50 for the typical case and p95 or p99 for the worst experiences. Measure from the keystroke that triggered the request, not from the moment the request was sent, or you will leave out the debounce and context assembly.
Latency and acceptance are linked. A suggestion that arrives late is more likely to be ignored or to be stale by the time it shows. Plot acceptance rate against latency bucket. If acceptance falls steeply above some bucket, that bucket is your real budget.
Retention
Retention asks whether accepted text is still in the file after some time. After a delay such as 30 seconds, then again at a few minutes, compare the accepted text with what is now at that location. Retention is the share of accepted characters that remain unchanged, or nearly unchanged.
- High retention means the user accepted the text and moved on.
- Low retention means the user accepted it and then rewrote or deleted it. The suggestion cost attention and did not save work.
Implementation choices matter:
- Use more than one delay. A short window catches immediate undo. A longer window catches fixes made after running the code.
- Track the text by position, but expect edits above it to shift offsets. Use the editor's range tracking, or a diff, and do not store a fixed offset.
- Use an edit distance threshold. A renamed variable should count as mostly retained, and a full rewrite should not.
- Accept that retention can be hidden by deletions made through version control, or by files closed without saving.
Computing the metrics
This script computes the three metrics from a small event list. Each record is one request. Run it as is.
events = [
{"id": 1, "shown": True, "accepted": True, "latency_ms": 180, "chars": 40, "kept": 38},
{"id": 2, "shown": True, "accepted": False, "latency_ms": 220, "chars": 25, "kept": 0},
{"id": 3, "shown": True, "accepted": True, "latency_ms": 950, "chars": 60, "kept": 30},
{"id": 4, "shown": False, "accepted": False, "latency_ms": 400, "chars": 0, "kept": 0},
{"id": 5, "shown": True, "accepted": False, "latency_ms": 310, "chars": 12, "kept": 0},
{"id": 6, "shown": True, "accepted": True, "latency_ms": 240, "chars": 20, "kept": 20},
]
def percentile(values, p):
"""Nearest-rank style percentile on a list of numbers."""
ordered = sorted(values)
index = round(p / 100 * (len(ordered) - 1))
return ordered[index]
requests = len(events)
shown = [e for e in events if e["shown"]]
accepted = [e for e in shown if e["accepted"]]
acceptance_per_shown = len(accepted) / len(shown)
acceptance_per_request = len(accepted) / requests
accepted_chars = sum(e["chars"] for e in accepted)
kept_chars = sum(e["kept"] for e in accepted)
retention = kept_chars / accepted_chars
latencies = [e["latency_ms"] for e in shown]
print(f"acceptance (per shown): {acceptance_per_shown:.1%}")
print(f"acceptance (per request): {acceptance_per_request:.1%}")
print(f"retention: {retention:.1%}")
print(f"latency p50: {percentile(latencies, 50)} ms")
print(f"latency p95: {percentile(latencies, 95)} ms")The output is:
acceptance (per shown): 60.0%
acceptance (per request): 50.0%
retention: 73.3%
latency p50: 240 ms
p95 shown belowThe last line above is a mistake in the listing, so use this correct output instead:
acceptance (per shown): 60.0%
acceptance (per request): 50.0%
retention: 73.3%
latency p50: 240 ms
latency p95: 950 msNotice that suggestion 3 was accepted after a 950 ms wait, and only half of it survived. With six records this is an anecdote, but at scale the same pattern would suggest that slow suggestions are accepted carelessly.
Common errors
- Mixing denominators. Comparing a per-request rate from one dashboard with a per-shown rate from another.
- Counting hidden suggestions. Including suggestions that were never visible, which lowers acceptance.
- Optimising acceptance alone. Filtering or shortening suggestions until the rate looks good.
- Averages for latency. Reporting the mean and missing a p95 that users feel.
- No retention window. Treating Tab as success without checking what happened next.
- Ignoring cohorts. Pooling languages, editors, and new and existing users, so a mix change looks like a quality change.
- Collecting too much. Logging the suggestion text or file contents when counts and lengths are enough. See the privacy chapter for what to avoid storing.
Using the metrics to decide
Treat the metrics as guardrails in an experiment. When you change a model, a prompt or a debounce time, compare the control and the new version on all three, and require that none of them gets clearly worse. A change that raises acceptance while retention falls has probably only made suggestions easier to accept. A change that cuts p95 latency but lowers acceptance may have traded quality for speed, which can still be the right call if the latency gain is large. Decide that trade in advance, not after you see the numbers.
Exercise
A team adds a filter that hides low-confidence suggestions. Acceptance per shown rises from 28% to 41%, but accepted characters per user per day falls by 30%. Explain what likely happened and which extra metric you would check next.
Show answer
The filter removed suggestions that users would sometimes have accepted, so the remaining ones are accepted more often, but fewer are shown, and so fewer characters come from the feature. Acceptance per shown rewards this. Check acceptance per request, or the share of characters from suggestions, to see the whole effect, and check retention to see whether the remaining suggestions are also better in the long run.
Exercise
Your p50 latency is 200 ms and your p95 is 1,400 ms. Users complain that suggestions "often come too late". Why is the p50 not enough, and how would you find the real latency budget?
Show answer
The p50 describes the typical request, and the complaints come from the slow tail, which the p95 shows. To find the budget, bucket requests by latency and plot acceptance rate for each bucket. The bucket where acceptance drops sharply is the point at which late suggestions stop being useful. Then split latency into debounce, context assembly, network, time to first token and generation to find which part makes up the tail.