# Similarity scans

On this page you scan a dataset for items that are alike in meaning: near-duplicate chats or triplets,
negatives that sit too close to their positive, and more. You see the price before it starts, set a
ceiling it never crosses, stop it at any time and compare it with an earlier scan.

A **similarity scan** embeds every item of a dataset once with an embedding model you choose, then
compares the vectors. It **reports** what it finds. It never changes, excludes or deletes an item: you
read each finding and decide.

**Thresholds are not calibrated.** The lines that decide what a scan flags are starting values chosen
by us, not values measured on your data. One of them, the far-positive line, was moved after a check
on public labelled data ([below](#what-a-scan-finds)); it is still not calibrated. A finding is a lead
to read, not a verdict: a flagged pair can be fine, and a pair that is not flagged can still be a duplicate. The API
says so with `calibrated: false` on every scan.

## What a scan finds {#what-a-scan-finds}

| Dataset | What to compare | Findings |
| :-- | :-- | :-- |
| Chats | `user_turns` (default): each chat's user turns, with a system prompt shared by most chats left out | **Near-duplicates** (`near`): chats whose user turns are close in meaning |
| Chats | `whole_chat`: every message, up to the model's input limit | Near-duplicates |
| Triplets | `anchors_passages` (default): anchors, positives and negatives | Near-duplicates (`near`) and three more findings, below the table: `label`, `far` and `neg` |
| Triplets | `anchors_only` | Near-duplicate anchors |

The three findings that only `anchors_passages` adds:

- **Negative nearly as close as the positive** (`label`): a negative nearly as close to the anchor as its positive, that is,
  within the margin of the positive's score (5% by default: within 5% of its score). The margin is a share of the positive's score, not a gap,
  and the flag is not an error check: a good hard negative is meant to be close, so many flagged
  negatives are right.
- **Positives unusually far from their anchor** (`far`): the anchor and its positive score under the
  far-positive line. A warning, never a block: a positive this far may be the wrong passage, or a loosely
  related positive that is right. The line was measured on `ReOpenly/Qwen3-Embedding-0.6B` only; with
  another scan model, treat it as a rough guide.
- **Hard negatives to review** (`neg`): up to ten close passages of other triplets, for a triplet that has no negative.
  A triplet whose closest passages are all near copies of its positive gets none; the list counts those triplets as
  `without_candidates` (`null` after a scan of anchors only, which mines nothing).

The flag lines a new scan starts from today are 0.90 cosine similarity for chats, 0.92 for triplets, a
close-negative margin of 5% (you may change it, from 1% to 50%) and 0.40 for a positive unusually far from its
anchor. They are product settings. Anchors are compared with anchors and passages with passages, and a triplet's own passages are
never each other's neighbours.

**Why the far-positive line is 0.40.** It was 0.50 until November 18, 2026. We scored public
labelled sets of query and relevant-passage pairs with the smaller embedding model
(`ReOpenly/Qwen3-Embedding-0.6B`) the way a scan does. At 0.50 the flag fired on a tenth to a third of the
positives those sets call relevant, on all but one set. At about 0.40 it fired on 2% (English) to 11%
(Portuguese) of them and still caught most passages swapped in from another pair. No fixed line works for
topical data, where positives are loosely related to the query: on one such set most good positives
scored low whatever the line. That test is only the smaller model, on public data and not yours, and a
swapped passage is an easy mistake to catch, so 0.40 is a better starting value, not a calibration. A
scan keeps the line it was started with: `thresholds.far_positive_line` in the scan says it, so a scan
made before the change still reads 0.50 and a new one reads 0.40. The near-duplicate lines and the 5%
margin did not change.

Scores are the model's cosine similarity on the first 512 values of each vector. How well that matches
your own idea of "alike" has not been measured, and a score is never compared across two models.

**Read the text of a near-duplicate group.** `POST .../suggestions/near-duplicates/search` takes an optional `content`
(`{"max_chars", "max_messages"}`) and then carries each member's **current** text, bounded as for exact-copy groups: a page
holds at most 5 groups, at most 10 members of a group carry text and a page carries at most 200,000 characters. The
scan's own stored text for an item is read at `GET .../scans/{scan_number}/items/{item_number}`, whose answer also carries
the item's `source`. See [Read a group](./dataset-health.md#group-reads).

## Price and ceiling {#price-and-ceiling}

**A scan costs what the embedding API costs for the model you pick, per token, and nothing else.** There
is no setup fee, storage fee or margin. Each batch is charged like any other embedding request, at the
embedding input price per million tokens for that model (a hosted fine-tune of it carries the same
multiplier as when you call it), and every request is charged at least the
[per-request minimum](../billing/pricing-and-credits.md#how-inference-is-billed). A scan is therefore
many small charges, one per batch; the scan's `charges` field gives their count and total.

The price is shown **before** the scan starts:

```text
POST /api/v1/projects/{owner_slug}/{project_number}/datasets/{dataset_number}/scans/estimate
{
  "model": "ReOpenly/Qwen3-Embedding-4B",
  "compare": "user_turns"
}
```

It answers the number of texts and input tokens, `price_per_million_usd`, `surcharge_percent` (always
`"0"`: a scan only uses your own project's models), `estimated_usd` and whether the default ceiling
covers it. **It is an estimate.** Above 2,000 texts the tokens are counted on a sample of 1,000 and
scaled, and `tokens_exact` is `false`. The app shows the same figures beside **Run scan**.

The **ceiling** is the most the scan may spend: from $0.01 to $100, default $0.05, sent as a decimal
string (`ceiling_usd`). **A scan never spends more than its ceiling.** Before each batch the scan checks
that its spend plus that batch's price stays within the ceiling; a batch that would cross it is not sent
and the scan ends **Stopped at ceiling**. A ceiling below the estimate is allowed, and the app says the
scan will stop early. The ceiling also counts against your
[spending caps](../billing/spending-caps.md#at-the-cap) from the moment the scan starts, and what the
scan does not spend is released when it ends. A balance too low for the first batch refuses the scan
with `402 insufficient_funds`.

## Run a scan {#run-a-scan}

In the app, choose **Similarity scans** on the dataset's page, then **Run a scan**: pick the model (the
bases first, the 4B base marked as the default, then your hosted embedding models), what to compare, the
ceiling and, for triplets, the close-negative margin (`label_margin` in the API). Through the API:

```text
# The models, comparisons, ceiling bounds and thresholds
GET .../scans/models

# The price (above)
POST .../scans/estimate

# Start; header Idempotency-Key, 1 to 128 characters
POST .../scans

# Recent scans, newest first
GET .../scans

# One scan
GET .../scans/{scan_number}

# Stop it
POST .../scans/{scan_number}/stop

# Progress while it runs
GET .../operations/{operation_id}
```

Operation progress keeps `done` and `total` in embedding inputs for compatibility. The additive `items_done` and
`items_total` fields count chats in text datasets and triplets in embedding datasets. The app shows these item counts
while a scan runs and after it stops. Selecting **Stop scan** immediately changes the button to **Stopping…** and
disables it; the current embedding batch completes, then the scan stops before starting another.

```json
{"model": "ReOpenly/Qwen3-Embedding-4B", "compare": "user_turns", "ceiling_usd": "0.50"}
```

`GET .../scans/models` lists each model with its `price_per_million_usd` (what the scan is charged per
million input tokens: the embedding price, times the multiplier for a hosted fine-tune) and `fine_tuned`;
`null` for a price means the model is not ready to price, never "free". The top level carries
`minimum_per_request_usd`, the least any request is charged.

Reads need `data:read`. Starting and stopping need `data:write` **and** `inference`; a key that lacks
one gets `403 insufficient_scope`. Starting with the same `Idempotency-Key` returns the scan that key
already made. A missing or foreign dataset or scan is `404 not_found`.

What can refuse a start:

| Code | Meaning |
| :-- | :-- |
| `scan_ceiling_invalid`, `scan_compare_invalid`, `scan_label_margin_invalid`, `idempotency_key_invalid` | A value outside its bounds |
| `scan_model_not_offered`, `scan_model_unavailable` | The model is not one of the choices, or cannot be used right now |
| `scan_in_progress` | One scan at a time runs in a project |
| `scan_capacity_busy` | Scans are busy platform-wide; `retry_after` says when to try again |
| `scan_too_large`, `scan_dataset_too_small` | More than 300,000 texts, or fewer than two items |
| `vector_quota_exceeded` | The project has no room to keep the vectors (below); `bytes_needed` and `bytes_free` say how much |
| `insufficient_funds` | Balance too low for the first batch |
| `key_cap_reached`, `project_cap_reached` | A spending cap would be crossed; nothing is written |
| `dataset_archived` | Unarchive the dataset first |

A refusal changes nothing. A scan is `queued`, `running`, `done`, `stopped`, `stopped_ceiling`,
`stopped_balance` or `failed`, and `failure_code` says why a failed one failed (`insufficient_funds`,
`scan_model_changed`, `scan_model_unavailable`, `key_cap_reached`, `project_cap_reached` or
`embedding_input_refused`). A scan that runs checks, on every batch, that the model is still the one you
chose, so scores of two models are never mixed, and that whoever started it could still start it: a key
that was deleted, deactivated or has expired, lost the `data:write` or `inference` scope or the project, or
a person who left the workspace, ends the scan `failed` with `actor_gone` before its next batch. What it
embedded before is kept and charged.

## Stop a scan {#stop}

**Stop scan** (or `POST .../scans/{scan_number}/stop`) ends a scan after the batch in progress. You are
charged for the tokens it already embedded and nothing more. Stopping a scan that already ended returns
it as it is.

A scan that ends before it read every item, because you stopped it, it reached its ceiling, a spending
cap or your balance stopped it, or it failed part-way, **is not wasted**: it becomes a
[partial scan](#partial) and its findings are used. A scan that ended before it reached two items has
nothing to compare: it has no findings, keeps no vectors, and the findings of the scan before it stay
the latest.

## Partial scans {#partial}

A partial scan compared the items it **reached**: an item is reached when every text the scan reads of it
(a chat; a triplet's anchor and passages) was embedded. A scan that has embedded every text is finished, not partial, even
when its last batch reached the ceiling exactly or you pressed Stop while that batch was running. Its findings cover those items only, and it is the
latest scan like a finished one: its findings reach dataset health, Find similar and the item pages. The
scan says so:

| Field | Meaning |
| :-- | :-- |
| `usable` | Its findings are used (a finished scan, or a partial one) |
| `partial` | It ended part-way; its findings cover the items it reached |
| `stop_reason` | `stopped` (you), `ceiling`, `spending_cap` (the project's), `key_spending_cap`, `balance` or `failed` (failed part-way); `null` while it runs and once it finished |
| `api_key_name` | The name of the API key whose cap stopped it, when one did |
| `coverage` | `items_compared` of `items_total` (the items reached), `inputs_compared` of `inputs_total` (their texts), `pairs_compared` of `pairs_total` |
| `stale` | Your dataset changed since it ran: its findings are kept as history and it cannot be continued |
| `continuable`, `continue_blocked_by` | Whether you can continue it now, and the code that blocks it when you cannot |
| `previous_full_scan` | The last full scan before it, `{number, finished_at}` |

**What the counts mean.** A scan compares every reached text with every other reached text of its pool
(chats with chats; anchors with anchors; passages with passages, never two passages of the same triplet).
So a near-duplicate is found only when **both** of its items were reached, and pairs grow with the square
of the items: reaching half the items compares about a quarter of the pairs. `pairs_compared` of
`pairs_total` says exactly how many. An item not reached was compared with nothing, so it carries no
`label`, `far` or `neg` finding either.

**Statuses against the last full scan.** A partial scan's findings are read against the last scan that
finished. A finding of that scan whose items the partial scan reached and no longer finds is `resolved`;
one with an item it did not reach is `not_rescanned` and keeps its old figures (the app shows it "From"
that scan's date), so nothing you had to review disappears.

**A failure that leaves untrustworthy vectors** (`failure_code` `embedding_output_invalid`) is not partial:
it has no findings and the scan before it stays the latest.

**Continue.** `POST .../scans/{scan_number}/continue/estimate` prices only the texts the scan has not
embedded, in the shape of a scan estimate; then `POST .../scans/{scan_number}/continue` with its own
`ceiling_usd` (and an `Idempotency-Key`) runs the same scan on to the end:

```json
{"ceiling_usd": "0.10"}
```

The texts it already embedded are **never charged again**. The ceiling is the most the continuation may
spend, and counts against your spending caps like a new scan's; the scan's `ceiling_usd` becomes what it
had spent plus this one. While it runs, the partial findings stay in use. Continuing needs `data:write`
and `inference` and is refused with `409 scan_not_partial`, `scan_in_progress`, `scan_stale` (the dataset
changed: run a new scan), `scan_superseded` (a newer scan replaced it), `scan_not_continuable` (it failed
in a way a continuation would meet again) or `scan_model_changed`; the balance and the caps refuse it as
they refuse a new scan.

**Delete.** `POST .../scans/{scan_number}/delete` removes a partial scan's findings and vectors; the
findings of the last full scan are the dataset's again. The scan stays in the list with what it cost
(`results_deleted: true`). Only a partial scan that is not running can be deleted, or a scan that failed without
publishing anything (it has no findings, so only `results_deleted` changes); anything else is refused (`409 scan_not_partial`).

**Rescans** build on a finished scan: while the latest scan is partial, a rescan is refused with
`409 scan_partial` (continue it, or run a new scan). The validation overlap of a run estimate reads
finished scans only, because a partial scan cannot say an item has no copy.

**A scan that cannot make progress ends.** A scan that embeds nothing new for 30 minutes over several
attempts (the model never becomes ready, or every attempt fails) ends `failed` with `scan_stalled` instead
of waiting for ever; what it reached is kept as a partial scan. A model whose files cannot be read ends it at once, `failed` with `scan_target_unavailable`.
A scan whose analysis (the comparison after embedding) fails three times ends `failed` with
`scan_analysis_failed`, or `stopped` with that code if you stopped it. It publishes nothing, its ceiling no
longer counts against your balance, only the embedding it did is charged, and you can run a new scan.

## Rescan some items {#rescan}

After you edit a few items, you do not need to scan the whole dataset again. A **rescan** embeds only the
items you select, again, with the model and the input of your latest finished scan, and keeps every other
item exactly as that scan had it. It is a **new scan**: it gets the next number and, when it finishes, it
is the latest scan. Its findings are read against the scan before it, so a finding whose items no longer
reach the line is `resolved`, and the older scan's vectors are dropped. A rescan that is stopped or fails
changes nothing: the older scan stays the latest.

```text
# The price of rescanning these items; counts toward no cap
POST .../rescans/quote

# Start; header Idempotency-Key, 1 to 128 characters
POST .../rescans
```

```json
{"selection": {"item_numbers": [12, 40]}, "ceiling_usd": "0.05"}
```

`selection` is the one the bulk item calls take: `item_numbers`, or a `filter` (a rescan then needs
`expected_count`, and a different count now is `409 selection_changed`). One request covers at most 1,000
items (`422 rescan_too_many`). Items in Trash or with no text have nothing to embed: they are skipped and
counted in `skipped_items`, and if none is left the answer is `422 rescan_nothing_to_scan`.

**A rescan costs what the same tokens cost in a scan**: the model's embedding price per million tokens,
charged per batch, and nothing else. The quote returns the figures of a scan estimate for only the
selected items, and its `estimated_usd` is the charge when `tokens_exact` is `true`. The `ceiling_usd`
works as a scan's: it counts against your spending caps from the start and a rescan never spends more.
Quoting needs `data:read`; starting needs `data:write` **and** `inference`. The scan it returns has `kind`
`rescan` and `rescan_of`, the number of the scan it was made from.

A rescan needs a finished scan (`409 no_scan`), the vectors of that scan (`409 scan_vectors_dropped`) and
the same model: if the model changed since the scan, run a new scan (`409 scan_model_changed`). One scan or
rescan runs at a time in a project, and while it runs the project's vector space holds both scans' vectors.
Repeating a rescan in parts of 1,000 is not available.

## Validation overlap in the run estimate {#run-estimate-leakage}

When you choose a validation tag for a run, the estimate (`GET .../runs/estimate-messages` for a text
project, `POST .../runs/estimate` for an embedding project) returns a `leakage` block: how many validation
items have a near-duplicate on the training side, read from the latest finished scan of the dataset
(`count`, `scan_number`, `checked_at`). A near-duplicate of a validation item in training makes the
validation score flatter the model. `count` is a floor when `capped` is `true`.

A pair you kept (**Keep both**, or a [group you kept](#kept-groups)) is not flagged by later scans, so
`count` leaves it out. `kept` counts the validation items that have such a kept copy on the training side,
read from your decisions rather than from the scan: `count: 0` with `kept` above 0 means no open
near-duplicate, not "no copies". The **New run** page and the dataset's **Health** card then say "No open
near-duplicates between validation and training. You kept N as is." (queries for an embedding project: "You kept both
copies of N").

`leakage` is `null` when no scan has finished, and **null is not zero**: it means nobody checked. It is
also `null` when the validation set is not a tag. The scan's own line decides what counts as a
near-duplicate (see the thresholds above, which are not calibrated), nothing is recomputed, and an item
outside the run's selection still counts as training, so the number is an upper bound for a run that
trains on fewer items.

## Findings {#findings}

A finished scan has findings. Open the scan's **Findings** tab, or read them:

```text
GET .../scans/{scan_number}/findings?check=near&status=new&limit=25&cursor=
```

A finding names its items **by number** (a chat reads `Chat #12`), never by name or text, and carries a
`score`, a `status` and a small `detail` (for a hard negative, its candidates with their scores and
shares of the positive's score). Each item opens as the scan read it: the revision recorded when the scan
started, read-only, even if you have edited or trashed the item since. An item purged since has no text
to show.

`status` compares with the last finished scan before it: `new`, `still_open`, `resolved` (found before,
gone now) or `not_rescanned` (the earlier scan found it and this one did not run that check, or, for a
[partial scan](#partial), did not reach one of its items). A partial scan's answer also carries `partial`
and `coverage`, and `compared_with_finished_at` dates the scan it is read against. The **Findings** tab draws
them as the badges **New**, **Still open**, **Resolved** and
**Not rescanned**. A finding is matched across scans by the items it names, never by its score. The **All items** tab and
`POST .../scans/{scan_number}/items/search` list every item the scan read with its nearest neighbour and
whether it was flagged, changed since or is in Trash.

## Groups you kept {#kept-groups}

A [group you kept whole](./dataset-health.md#group-decisions) (`keep_all` on copies or conflicts) keeps its pairs out of
later scans, like a `not_duplicates` decision: the scan does not flag them again while the decision covers both chats at
their current revisions. Editing either chat ends it for that pair; the other pairs of the group stay kept, as Checks
still shows them.

## Compare two scans {#compare}

`GET .../scans/{scan_number}/compare?with={other_scan_number}` (the **Compare** tab) says why the
findings changed between two finished scans, in groups, in the order you should review them: **after your edits**, **from items
added since**, **checked for the first time** (the older scan did not run that check), **scan setup
only** (no item changed: the model, the input or a flag line differs) and **fixed by your changes** (gone
now after an edit or a move to Trash). When the two scans used a different model or a different input,
`like_for_like` is `false` with the reasons, findings are still matched item by item, and scores are not
compared. On the latest scan, a group whose findings are all of one check has **Review N** (**Check N** for scan
setup only), which opens dataset health on that check; the fixed group and an older scan's comparison have none.

**Either order.** `with` may be an earlier or a later scan than `scan_number`, which is the scan the page is about; the
same scan twice answers `400 compare_same_scan`, and both scans must have findings, finished or partial
(`409 scan_not_finished`). When one of them is partial, the comparison reads only the findings whose items
**both** scans reached: `partial` is `true`, `shared_items` says how many items that is, and
`outside_coverage` (`{earlier, later}`) counts each scan's findings left out. What
**new** and **resolved** mean never changes with the order: they read from the earlier scan to the later one. A finding
is `new` when only the later scan has it, and `resolved` when only the earlier scan has it and the later scan ran that
check (`not_rescanned` when it did not). The groups say why, so they are the same in both orders. Asking about Scan 5
with Scan 7 therefore says that a finding is not in Scan 5 and is new in Scan 7, and that a finding in Scan 5 is
resolved by Scan 7. The answer says which way you asked and what it means for the scan you asked about:

- `direction` is `forward` when `with` is the earlier scan and `backward` when it is the later one, with
  `earlier_scan_number` and `later_scan_number`.
- Each finding has `present_in`, the numbers of the scans it appears in, in ascending order.
- `presence_counts` is `{only_in_scan, only_in_with, in_both}`: the same totals as `counts`, from the point of view of the
  scan in the path. Asking the other way round swaps the first two numbers.
- `group_counts` is the size of each group, always present.

Read one group at a time with `group` (`after_edits`, `items_added`, `first_check`, `setup_only` or `fixed`), `limit`
(0 to 500, 100 by default) and `cursor`; the answer then holds that group only and `next_cursor` continues it, in
either order. `limit=0` answers the counts only. Without `group` every group is returned whole, as before.

**On the Compare tab.** The picker lists every other finished scan, newer ones too, and **Swap** exchanges the two scans,
so the scan you look at can be the earlier one. Swapping changes no status and no count: a finding that is new in the later
scan reads **Appears in** that scan, one resolved by it reads **Resolved by** that scan, and the line under the picker says
how many findings are only in this scan, only in the other and in both. Each group shows its first findings and **Show
more** reads the next ones. **Review N** appears only when the scan you look at is the latest finished scan.

## Storage {#storage}

Only the **newest finished scan keeps its vectors**; finishing a scan drops the older ones'. A partial
scan keeps its own vectors so it can be continued, and the older scan keeps its vectors until a scan
finishes. A vector is
1,024 bytes, and the vectors count toward the project's 256 MiB for vectors, shared with
[Search indexes](../models/playground-and-search.md#search). Findings stay after the vectors are dropped.

## Limits of what a scan tells you {#limits}

- Thresholds are starting values (see above), and a score is one model's cosine, not a measure of how
  good your data is.
- A scan reports. Nothing is kept out of training because a scan found it, and a scan does not change
  how a run mixes your examples.
- A chat longer than the model's input limit is cut at the limit; the scan's item rows say which were cut.
- A dataset of more than 300,000 texts, or with fewer than two items, cannot be scanned.
