Skip to main content
One judgment, settles, picks the open invoice that each payment settles, or says that none does. When you record the match your team books, that outcome calibrates the judgment. The correction makes its numbers true on your data, and your own numbers about each invoice can help it pick. Each payment reads only the open invoices that share its key, and settles picks among them in one engine call (rather than one yes/no judgment for each pair). Brussle judges again the payments that read an invoice when that invoice is paid, cancelled or created. The payments that settles is unsure of wait in a queue, which your application reads with one query, and a webhook tells you when a payment enters or leaves it. Each payment gets one match at most, and your outcomes measure whether the picks are good on your data.

Write the key

A block is all the documents that hold the same value in one attribute you write, and that value is the block’s key. The payments and invoices in block acme-gbp are candidates for each other, while nothing in block acme-usd is a candidate for them.
  • Put every condition of a match in the key. A payment and an invoice in different currencies can never match, so the currency goes in the key.
  • Do not make it coarse. A key such as the week puts hundreds of unrelated invoices in front of each payment, and each of them causes new judging when it changes.
  • Write it as a valid document id: up to 128 bytes of letters, digits, ., _, -, : and /, such as a normalised counterparty name and a currency. A document with no key, or an invalid one, is in no block, so it reads no candidates and is no document’s candidate.

Define the matcher

Create the judgment with POST /namespaces/{ns}/judgments, or ns.judgments.create in an SDK. The starter payments.settles makes the same judgment from the names of your attributes.
  • The blocking relation (see candidates that share a key). join names the same attribute on both sides. The relation reads the newest open invoices in the block, at most last_n of them (which can be up to the candidate limit), created within the window before the newest invoice in the block. You must set window unless the relation has relative. When more invoices qualified than last_n, the context and the evaluation show capped: true. A blocking relation reads its candidates’ attributes and state and never their answers, so Brussle refuses a path under answers..
  • The options. options.from names the relation, and each invoice the payment reads becomes one option, newest first, followed by none_of_the_above. An option’s value is the invoice’s id, and its description is the invoice’s label fields as text. Brussle refuses a label that names an image with invalid_request.
  • The threshold. unmatched is true when the probability of none_of_the_above is 0.3 or more, and the payments where it is true make up the queue (see read the answer).
  • max_tokens is the most context the engine reads for one payment, and Brussle cuts part of the context past it (see inspect an unexpected answer).
  • The scope. created_within: null keeps old unmatched payments in scope, since with the default scope of 30 days an older payment keeps its old answer when its block changes.
  • The policy. on_change keeps the queue current without a read. Brussle judges a payment when it changes, and judges it again after the fan-out debounce (10 minutes by default) when an open invoice in its block changes.
Next, give settles the outcome rule that records each match. Outcome rules are a setting, so you send them in a PATCH /namespaces/{ns}/judgments/settles once the judgment exists.
The rule fires when state.settles changes from absent to set, and from takes the matched invoice’s id from that field (see record outcomes from your own writes). A change to the question, the options, the key attribute or the relation makes a new version of settles with its own fit, so answers from the earlier version read stale (older_version) until the payment changes or a backfill judges it again.

Write the invoices and payments

Write them as documents, with the key in attributes.block. The code writes to acme/prod, which needs a key whose scope covers acme/prod (such as acme/*), since the key you got at sign-up cannot reach it, and only an organization with a card on file can create one that does (get an API key). It writes two open invoices and one payment for Acme, in pounds, and wait_for makes the write wait (for at most wait_timeout_ms) until the payment has its answer.
In production, your sync writes them as your records change. Give a payment that can never match (a refund, for example) a status outside applies_to.

Read the answer

The first answer usually picks inv_2043, since the reference names it and the amount fits. If freshness is pending, the first answers took longer than the wait, so read again in a few seconds.
  • value is the matched invoice’s id, or none_of_the_above.
  • escape_p is the probability that no candidate matches.
  • dist holds only the candidates with a probability above zero, so read it as a shortlist rather than a ranking. Jev rounds to two decimals, so after the first few candidates the probabilities are equal at zero. Each engine’s page says how its probabilities come.
  • thresholds gives each threshold as true or false, and here unmatched is false.
  • evaluation_id names the evaluation, which keeps the exact text the engine read and the invoices it read, at their revisions. revision, judgment_version and engine_version say what was judged, and how.
A payment whose block has no open invoice gets none_of_the_above with escape_p 1, and Brussle makes no engine call and bills nothing. The candidates keep their order, newest first, so the same candidates give the same context and Brussle keeps the answer with no engine call. A new candidate, however, can change the pick. The unmatched queue is a threshold on escape_p. You use the pick below it, and at or above it the payment waits for a person. Before you have outcomes, start at about 0.3 (a starting value, not a measured one), so that only payments with a low escape_p use their pick. Once you have recorded matches, replace it with the recommender’s. GET .../thresholds/recommend?target=precision:0.98 gives the threshold at which the picks it lets through are right at least that often.

See the pick follow a paid invoice

An invoice can leave the block for reasons that have nothing to do with this payment (a credit note cancels it, or another payment settles it), and Brussle then judges again each unmatched payment in the block. To see this happen, mark the matched invoice paid and write only the invoice.
  1. The payment’s answer is pending from the moment Brussle acknowledges the write, and answers: "fresh_only" leaves it out.
  2. Brussle waits for the fan-out debounce, a quiet period in the block of 10 minutes by default (and at most max_wait_ms, 1 hour by default, if the block keeps changing), then reads the block once. inv_2043 is no longer open, so it is no longer a candidate. See freshness for what counts as a change.
  3. Brussle judges the payment again, and this time the engine sees only inv_2051, so the new evaluation’s related_documents no longer lists inv_2043.
The new answer usually picks none_of_the_above, since no open invoice fits the reference or the amount, and the payment enters the queue. The engine can also pick the other invoice, but with a lower probability that differs a little from one evaluation to the next. wait_for cannot wait for this, since it waits only for the documents in the write and settles does not judge invoices. To see the change at once in a test, set fanout.debounce_ms low, as the quickstart does. In production, keep the default and let the subscription tell your application.

Query the unmatched queue

The queue is one query, for the payments whose unmatched threshold is true, with fresh answers only.
  • The filter reads the threshold, not escape_p, so a new threshold moves the queue with no change to your code.
  • answers: "fresh_only" leaves out answers that are pending, stale or failed (see freshness).
  • applies_to limits the query too, so the reconciliation write takes a payment out of the queue.
To hear of changes, create a subscription with the same filter and a webhook endpoint. The subscription sends subscription.entered when a payment starts to match and subscription.exited when it stops, and an endpoint with no events receives only what its subscriptions send it.
Verify each delivery with verifyWebhook or verify_webhook (see receive webhooks). A delivery’s cause is change for a write to the payment, or fanout for a change to an invoice in its block. Keep the highest sequence you saw for each payment and drop older events. A subscription checks a payment only once its answer has settled, so a write never sends exited on a pending answer and then entered when it lands. The first check is silent, so payments that already match join without an event and one subscription.synced event (reason created) says how many. A new threshold or a backfill also sends one synced event rather than one for each payment. After each synced event, fill your receiver with ns.subscriptions.query("unmatched-payments"). Subscriptions lists every event field. Without an endpoint, the events go only to the events feed.

Record the match: the reconciliation shape

When your team or your system settles a payment, write the match and the payment’s new status in one write.
  • The outcome rule fires. state.settles changed from absent to set on a payment inside applies_to, so {"on": "state.settles", "from": "state.settles"} records inv_2043 as the right answer. The outcome joins the payment’s answer as it was immediately before the write, which is the evaluation whose candidates still held the invoice.
  • The payment leaves applies_to and the queue. Brussle no longer judges it, and the subscription sends subscription.exited. The evaluation that found the match stays in the log.
  • The invoice leaves the block when you mark it paid, so the other payments stop reading it as open.
If you split this into two writes, a change to the block between them can judge the payment again first, so its answer can change to “no match” a moment after you acted. A payment that never matches stays in scope, and Brussle judges it again each time a candidate in its block changes. The rule records only the payments you match. The correction needs both kinds, so when you close a payment as unmatched, post none_of_the_above as its outcome (see post what did not happen too).

Let your outcomes correct the numbers

Brussle fits a correction to settles each night from the matches you recorded. The first correction (stage early) comes at 50 outcomes, with at least 15 that name an invoice and 15 that say none_of_the_above (see when you get a correction). The recommender needs 100 outcomes that name an invoice, with at least 20 right picks and 20 wrong ones. Features need 100 outcomes, with 20 of each kind. The calibration report reads two things from the same outcomes:
  • Whether a match exists. 1 − escape_p says how probable a match is, and the correction fits it, so the answer’s calibrated.escape_p (with its 95% interval) says how often payments like this one had no match on your outcomes.
  • Whether the pick was right, in selection, which is the share of outcomes naming an invoice where the answer picked that invoice.
Without features, the correction moves the answer only toward or away from none_of_the_above and never changes the order among the invoices. The queue’s threshold still reads the engine’s escape_p.

Let your own numbers help pick

The engine reads the payment and each invoice’s label, so it never weighs numbers it does not see (how much is already paid against an invoice, for example). Keep those numbers as features, and your outcomes decide how much they count.
candidates.count describes the payment and helps decide whether a match exists. candidates.each(...) describes each invoice the engine read, helps decide which invoice it is, and is kept under the answer’s candidate_features. A candidate’s answers cannot be a feature, so keep the number on the invoice’s state, written by your own system. The answer’s escape_p, dist and value are the corrected ones when the fit is applied, and raw keeps the engine’s:
  • The pick can change. The invoice your numbers favour can rise above one they do not at equal engine confidence. Brussle uses the fit only when it picks right at least as often as the engine on outcomes it did not use.
  • The queue, filters and the recommender read the corrected escape_p, so a new fit can move a payment in or out of the queue, and Brussle judges again (and bills) the invoice judgments that read the matches.
See features on a choice among candidates.

When a pick looks wrong

Tune a matcher shows how to open the evaluation behind a pick, read match_misses by cause, reach the oldest open invoice in a large block, and size the key against the cost and limits.

Read the matches from the invoice

A judgment on each invoice (“do the payments matched to this invoice settle it in full?”) can read the payments that settles picked for it through a link, whose join is the matcher’s answer.
The link follows the current pick below unmatched. Read a matcher’s picks from the invoice covers links, what a link count measures, and how to count the matches with no judgment on each invoice.

Duplicates within one kind of record

The judged documents can be their own candidates, such as listings with "match": {"attributes.kind": "listing"} and the same key on both sides. Each listing reads the other listings in its block but never itself, and names at most one of them as its duplicate. Each write to a listing changes its block, so a block of n listings that change often costs up to n judgments for each change. To get every duplicate pair rather than only the best one for each listing, keep one pair document for each pair with a yes/no judgment on each (see judge a document with the document it points at).