Skip to content

Calibrating dedup thresholds

Zentri compares each new task with the project’s active, queued, and finished tasks and calls it new, partial_overlap, active_duplicate, or already_done. A set of per-project thresholds decides where those lines fall. A second, fixed threshold decides when two sessions’ symbol names look like the same thing. This guide shows how to measure both on labeled data and how to change the project thresholds.

The method and every shipped number come from two decision records in the Zentri repository: ADR-0006 for intents, and the calibration section of ADR-0007 for symbols. Both are under docs/adr/.

  • A clone of the Zentri repository and the Go toolchain. The scripts build zentri-server from source.
  • For the semantic embedder and the judge: an Ollama server, or Docker for a throwaway one.
  • For the symbol threshold: Docker, or a Postgres with the pg_trgm extension.
  • To change a project’s thresholds: a lead or admin user token. Any project member can read them.
Threshold What it decides Hash default Semantic default
duplicate_cosine At or above this similarity, a match is a duplicate: active_duplicate against an active or queued task, already_done against a finished one. 0.79 0.95
partial_cosine At or above this, a match is a partial_overlap. It may not exceed duplicate_cosine. 0.79 0.95
area_jaccard Overlap of the touched areas (paths) at or above this also makes a partial_overlap. 0.5 0.5
judge_cosine The bottom of the band in which the LLM judge reads a candidate. The band ends at duplicate_cosine. 0.3 0.4
dedup_window_ms For this long after a task is registered, a near copy of it is a duplicate whatever the caller chose. 0 turns the window off. 5000 5000
dedup_cosine The similarity that counts as a near copy inside that window. 0.97 0.97
  • An embedding model whose name starts with hash- gets the hash defaults. Every other model gets the semantic ones, because the two score on different scales.
  • The same ticket on both sides makes a duplicate whatever the similarity. Different tickets on the two sides stop a duplicate by similarity. A ticket that a prompt names only in passing counts for neither.
  • The judge runs only when the coordinator has an LLM and a data key (ZENTRI_DATA_KEY_FILE), because it reads raw prompts.

The intents and dedup page explains the pipeline.

The rule: the best macro F1 while active_duplicate and already_done precision stay at or above 0.95. A false duplicate stops real work, so the sweep gives up recall before that precision.

Terminal window
make build-go

This builds bin/zentri, bin/zentri-server, and the bin/zt link.

The hash embedder is the offline default. Scoring it needs no database and no network:

Terminal window
bin/zentri-server intents calibrate --embedder hash

It replays the 349 labeled pairs in examples/intents/pairs.jsonl through extraction, embedding, and classification, and prints precision and recall for each class. The start of the report:

embedder hash-v1, text normalized, 349 pairs
model time per check: p50 0 ms, p95 0 ms, max 1 ms over 349 checks
duplicates without a shared ticket whose own task is the closest 1, 3, 5: 50, 68, 74 of 125
shipped defaults: duplicate_cosine 0.79, partial_cosine 0.79, area_jaccard 0.5, judge_cosine 0.30
accuracy 0.573, macro F1 0.565
class support predicted precision 95% CI recall 95% CI F1
new 100 247 0.401 0.34-0.46 0.990 0.95-1.00 0.571
partial_overlap 96 47 0.979 0.89-1.00 0.479 0.38-0.58 0.643
already_done 47 16 1.000 0.81-1.00 0.340 0.22-0.48 0.507
active_duplicate 106 39 1.000 0.91-1.00 0.368 0.28-0.46 0.538
by kind: different_feature_same_area 38/38, different_ticket_same_words 13/14, incidental_ticket 9/15, injection 4/12, near_identical 16/16, overlap 42/85, paraphrase 0/73, repaste 11/11, same_ticket 27/27, story_vs_code 2/11, symptom_vs_fix 4/13, unrelated 34/34

scripts/calibrate-intents.sh runs the same command, and then scores an Ollama embedder when one answers. Step 4 covers that.

Section What it tells you
model time per check Time spent in the embedder and judge per check. Use it only from a run without --cache.
duplicates ... closest 1, 3, 5 How often a true duplicate’s own task ranks first, in the top 3, or in the top 5 by similarity. With --judge-top 3, the judge reads only the 3 closest, so this caps what it can find.
shipped defaults The class table at the defaults for this embedder. Precision is how many of the predicted pairs were right. Recall is how many of the true pairs were found. The 95% columns are Wilson intervals.
by kind Pairs right per kind, out of all pairs of that kind. paraphrase 0/73 means the hash embedder found no reworded duplicate.
best on this set The thresholds a sweep picks on this set under the rule above, and their table.
two-fold macro F1 The sweep fitted on one half and scored on the other. A large drop from best on this set means the sweep overfits.
cosine by kind Minimum, median, and maximum similarity per kind. Look for kinds whose ranges overlap.
misses at the shipped defaults Every wrong pair, as <id> <kind>: want <label>, got <class>. Look the ID up in the dataset.

For the hash embedder, best on this set equals the shipped defaults, and the two-fold scores are 0.602, 0.518. On this run, cosine catches near copies and repastes, the ticket rule catches same-ticket pairs, and reworded duplicates go through as new.

Add --json for the full report.

4. Score a semantic embedder and the judge

Section titled “4. Score a semantic embedder and the judge”

The shipped semantic setup is embeddinggemma:300m for embeddings and qwen3:4b-instruct as the judge. These are the commands behind ADR-0006’s shipped rows. --ollama-container starts a throwaway Ollama on a random local port, pulls the models, and removes the container and its volume afterwards:

Terminal window
H="--heldout examples/intents/heldout/pairs.jsonl --heldout examples/intents/heldout-v2/pairs.jsonl --heldout examples/intents/heldout-v3/pairs.jsonl"
ZENTRI_EMBED_MODEL=embeddinggemma:300m ZENTRI_LLM_MODEL=qwen3:4b-instruct ZENTRI_MODEL_TIMEOUT=5s \
scripts/calibrate-intents.sh --ollama-container --judge --judge-floor 0.4 --judge-ceiling 0.95 --judge-top 3 $H

Drop --ollama-container to use an Ollama that already answers at OLLAMA_URL, which defaults to http://127.0.0.1:11434. The throwaway container runs each model on 4 threads (OLLAMA_THREADS changes that) and keeps both loaded, as the Compose service does, so give your own Ollama the same settings before you compare latency. Drop --judge and its flags to score the embedder alone.

  • A check makes 3 to 6 chat calls when every candidate is in the judge’s band. At 5 s, ADR-0006 measured a median check of 4.2 to 5.6 s on a laptop CPU, with Ollama on 4 threads.
  • --cache DIR keeps model answers on disk, so a rerun is fast. Latency means nothing in a cached run.
  • ZENTRI_MODEL_TIMEOUT is the per-call limit. The shipped value is 5 s. All the model calls of one check also share a 25 s budget.
  • A reasoning model needs ZENTRI_LLM_REASONING_EFFORT=none. The judge allows 32 completion tokens.

What ADR-0006 measured on 2026-12-01, CPU only, with Ollama on 4 threads:

Set Setup Macro F1 active_duplicate precision / recall
Training, 349 pairs hash, no judge 0.565 1.000 / 0.368
Training, 349 pairs embeddinggemma:300m + judge, 5 s (shipped) 0.760 0.952 / 0.755
Held-out v2, 174 pairs embeddinggemma:300m + judge, 5 s (shipped) 0.806 0.896 / 0.827
Held-out v3, 176 pairs hash, no judge 0.356 0.727 / 0.133
Held-out v3, 176 pairs embeddinggemma:300m + judge, 5 s (shipped) 0.767 0.905 / 0.633

A set the sweep never fitted on shows how far the training numbers carry. Pass one or more with --heldout:

Terminal window
bin/zentri-server intents calibrate --embedder hash --heldout examples/intents/heldout-v2/pairs.jsonl

After the training report, it scores the held-out set twice, at the shipped defaults and at the thresholds the sweep fitted:

held-out set heldout-v2, 174 pairs, nothing fitted on it
model time per check: p50 0 ms, p95 0 ms, max 0 ms over 174 checks
duplicates without a shared ticket whose own task is the closest 1, 3, 5: 42, 46, 52 of 61
held-out at the shipped defaults: duplicate_cosine 0.79, partial_cosine 0.79, area_jaccard 0.5, judge_cosine 0.30
accuracy 0.425, macro F1 0.403
class support predicted precision 95% CI recall 95% CI F1
new 46 141 0.312 0.24-0.39 0.957 0.85-0.99 0.471
partial_overlap 46 9 1.000 0.70-1.00 0.196 0.11-0.33 0.328
already_done 30 10 0.900 0.60-0.98 0.300 0.17-0.48 0.450
active_duplicate 52 14 0.857 0.60-0.96 0.231 0.14-0.36 0.364

If the fitted thresholds beat the defaults on training but not on the held-out set, keep the defaults.

The shipped sets are synthetic and describe fictional products. To measure on tasks like yours, write pairs in the same JSON Lines format and pass the file with --dataset:

{"id":"p001","kind":"paraphrase","label":"active_duplicate","existing":{"prompt":"...","status":"active"},"incoming":{"prompt":"..."},"note":"short why"}
  • label is active_duplicate, already_done, partial_overlap, or new.
  • existing.status is active, queued, or done.
  • examples/intents/README.md lists the kinds and the labeling rules.
Terminal window
bin/zentri-server intents calibrate --embedder hash --dataset my-pairs.jsonl

No zt command sets thresholds. Use the HTTP API with a lead token, your own user token. zt doctor says where it is on its config line, and Invite your team shows how to read it from each store. On macOS, with the account zt doctor names:

Terminal window
ZT_TOKEN=$(security find-generic-password -s zentri -a 'you@https://zentri.example.com' -w | sed 's/^go-keyring-base64://' | base64 --decode)
SERVER=https://zentri.example.com
curl -fsS -H "Authorization: Bearer $ZT_TOKEN" "$SERVER/v1/projects"

The response lists the org’s projects with their id. Read the current thresholds:

Terminal window
PROJECT=<project id>
curl -fsS -H "Authorization: Bearer $ZT_TOKEN" "$SERVER/v1/projects/$PROJECT/intent-thresholds"

The response has effective, the values in use; defaults, the defaults for the coordinator’s embedder; override, the project’s settings; embedding_model; and updated_at.

Set an override:

Terminal window
curl -fsS -X PUT -H "Authorization: Bearer $ZT_TOKEN" -H "Content-Type: application/json" \
-d '{"duplicate_cosine": 0.9, "partial_cosine": 0.85}' \
"$SERVER/v1/projects/$PROJECT/intent-thresholds"
  • A PUT replaces the whole override. A field you leave out, or set to null, goes back to the default. Send every field you want to keep.
  • Each cosine and area_jaccard must be above 0 and at most 1. partial_cosine may not exceed duplicate_cosine. dedup_window_ms is 0 to 600000.
  • ticket_patterns takes up to 10 RE2 patterns. An empty list means the defaults, [A-Z][A-Z0-9]+-\d+ and #\d+.
  • To turn the judge off for a project, set judge_cosine at or above duplicate_cosine.
  • Every change is written to the audit log as intent_thresholds.update.
  • New checks use the new values. Classes already recorded do not change.

The embedder is coordinator-wide, set with ZENTRI_EMBEDDER (hash, ollama, or openai) and its variables. See the configuration reference. Matching compares only vectors from the same model, so after a change, re-embed the stored tasks once:

Terminal window
zentri-server intents reembed --all

With the Compose stack, run it in the server service, which has the database and model settings:

Terminal window
docker compose -f deploy/docker-compose.yml run --rm --no-deps server intents reembed --all

Until it runs, tasks embedded with the old model match on tickets and touched areas only.

9. Measure the symbol near-duplicate threshold

Section titled “9. Measure the symbol near-duplicate threshold”

The pre-commit hook sends the public symbols a session added or changed. When two active sessions have symbols of the same kind with similar names, such as ParseInvoiceLine and parseInvoiceLines, the coordinator raises a symbol_near_duplicate notice. It compares names with Postgres pg_trgm similarity, and the cutoff is 0.63.

Terminal window
scripts/calibrate-symbols.sh

The script starts a throwaway pgvector/pgvector:pg16 container on a random local port, so each score is the same similarity() the coordinator uses, and removes it when done. Set ZENTRI_DATABASE_URL to use a Postgres you already have. It needs pg_trgm and runs only SELECT.

It sweeps thresholds from 0.30 to 0.95 in steps of 0.01 on the 240 tuning pairs and picks the best F0.5, which weighs precision twice as much as recall. A tie goes to the higher threshold. It prints picked threshold, then a table per set with TP, FP, FN, TN, precision and recall with 95% intervals, and F0.5, then each miss with its similarity. ADR-0007 measured:

Set Threshold Precision [95% CI] Recall [95% CI] F0.5
Tuning, 240 pairs 0.63 (picked) 0.696 [0.606, 0.774] 0.650 [0.561, 0.729] 0.687
Held-out, 200 pairs 0.63 0.710 [0.611, 0.792] 0.660 [0.563, 0.745] 0.699
Held-out, 200 pairs 0.60 0.686 [0.592, 0.767] 0.720 [0.625, 0.799] 0.692

0.63 beats 0.60 by less than the noise, and every interval overlaps. A team that prefers recall can take 0.60.

Trigrams see spelling, not meaning. Synonyms are missed: Customer and Client score 0.067. Versions are flagged: ForecastModelV1 and ForecastModelV2 score 0.800.

This threshold is not a project setting. It is the constant NearDuplicateSimilarity in server/internal/overlap/overlap.go. Changing it means building and deploying your own coordinator.

Doc comments raise the same notice when names miss (Live overlap). Each doc scorer has its own threshold. Measure the one your embedder selects:

Terminal window
scripts/calibrate-symbol-docs.sh

With ZENTRI_EMBEDDER unset or hash, the script measures the offline lexical scorer. With an Ollama or OpenAI embedder and its variables set, it measures that model reading the docs, and --cache DIR keeps its answers on disk for a faster rerun. It starts the same throwaway Postgres for the name scores.

It sweeps doc thresholds from 0.30 to 0.99 on the 140 tuning pairs in examples/symbols/docs, keeps those that flag at most 0.1% of the set’s unlabeled pairs, and picks the best F0.5. A pair is flagged when its names reach 0.63 or its docs reach the threshold. Then it scores the 120 frozen held-out pairs by names alone, at the picked threshold, and at the shipped one. On the held-out set, ADR-0017 records precision 0.508 and recall 0.517 for the lexical scorer at 0.47, against 0.375 and 0.100 for names alone.

The doc thresholds are constants too, DocCosineLexical and SemanticDocCosine in server/internal/overlap/doc.go. A model with no entry in SemanticDocCosine uses the lexical scorer, so its docs never leave the coordinator. Adding a model means measuring it with the script and adding its entry.

Symptom Cause and fix
=== ollama embedder: nothing answers at ..., skipped No Ollama at OLLAMA_URL. Start one, or pass --ollama-container.
Many judge calls fail and recall drops Ollama may run on too many threads, or unload the judge between checks. Set LLAMA_ARG_THREADS on the Ollama container to your number of performance cores (OLLAMA_THREADS in deploy/.env for Compose), and OLLAMA_KEEP_ALIVE=-1. If calls still fail, the 5 s per-call timeout is too short for your hardware. Compare runs at a longer ZENTRI_MODEL_TIMEOUT, which also makes each check slower.
A reasoning model’s judge calls all fail Set ZENTRI_LLM_REASONING_EFFORT=none.
The PUT returns 400 The body breaks a rule in step 7, or names an unknown field. The error.message says which.
The PUT returns 403 Your role is below lead.
Matching seems to ignore old tasks after an embedder change Run intents reembed --all, as in step 8.
scripts/calibrate-symbols.sh or scripts/calibrate-symbol-docs.sh prints FAIL: Postgres did not start Docker could not start the container. Check Docker, or set ZENTRI_DATABASE_URL.
  • All the labeled sets are synthetic. No real project’s prompts have been measured.
  • Hosted embedders such as OpenAI’s text-embedding-3 models, and hosted chat models, were not measured.
  • Concurrent checks were not measured. Ollama answered one call at a time, so checks from several users queue behind each other.
  • No measured setup reached both 0.95 duplicate precision and 0.80 recall on a held-out set.
  • No zt command reads or sets thresholds.
  • The symbol thresholds, for names and for doc comments, are compiled in and are the same for every project.