- a contract, with its amendments
- an invoice, with the payments booked against it
- a conversation, with its messages
Start with the simplest context
Decide what the question depends on before you add related documents, then try these options in this order:- Counts as features. Use counts when the question depends on how much or how often (how many amendments, or the total of the payments). Keep each number as a feature with
"render": false, so the engine does not read it. Once you post outcomes, the fit weighs the features and the engine’s answer together. For a question about what will happen, the counts and the fit carry the number, and the report’sfeatures_onlyshows what the engine adds. - A narrow judgment on each related document, counted. Use this when each related document needs reading. Ask a narrow question about each one (“Does this amendment change the price?”), count those answers on the contract with
count_where, and keep the count as a feature. See roll-ups. - Related text beside a narrow question about this document. Use this when the answer is in what the related documents say. Keep
last_nsmall, and show only the fields the question needs.
Define one
A related document points at the judged document through an ordinary attribute. Here the judged documents are contracts, and each amendment holds its contract’sid in attributes.contract_id:
theirs: "attributes.invoice_id") and for a conversation and its messages (theirs: "attributes.conversation_id").
applies_tosets which documents the judgment judges, answers and bills, so other documents have no answer for it and filters treat that answer as missing.matchselects the documents a relation reads.joinsays how they point at the judged document. A document belongs to the judged document whoseidequals itstheirsattribute.last_n,windowor both bound each relation, although a relation reads at most the newest 1,000 documents, whatever its bounds.fieldsare the paths shown from each document, a related document’s image included (asimages.<name>).aggregateadds numbers about the same documents, and itslatestcan take the newest document’s image. Each relation needsfields,aggregateor both.
The reference index
Brussle needs a reference index on the attribute the relation joins on, since the index is how it finds the judged document for each write. The first version that joins on a new attribute builds one with areference_index job for each new attribute (the create response lists them in job_ids). A version that joins on an indexed attribute over documents the index does not cover yet (with a different match, say) gets a job that builds the index again, although it is still one index. Until the job is done the answers are unavailable, except that under on_change a document written after the create reads pending.
A namespace has at most 8 reference indexes, one for each attribute its relations join on in either direction (blocking keys included). Brussle refuses a create that needs a ninth, and the error names the eight you have.
Newest created first, and what an edit costs
A relation sorts its documents bycreated_at, newest first, so “the last 8 amendments” means the 8 created most recently. window keeps the documents created within the window, and last_n keeps the newest n of them.
The window counts back from the later of two times, the newest write to the judged document (when Brussle got it) and the creation of its newest related document, and never from today. An edit to a related document therefore moves neither the list nor the window. A contract with no new writes keeps the same window, so a periodic judgment judges it again against that window and never against the current date.
created_at is when Brussle first got the document, unless the creating write gave its own. Send each record’s original creation time as created_at when you import existing data, and relations read your history in the order it happened. You cannot set the time of a write, however. After an import, the newest write to each judged document is the import, so a window of 365d then holds nothing created more than 365 days before it. Use last_n to read imported history, since it reads by created_at alone. To measure a judgment on that history, see backtest on history.
To select by another field (the invoices due soonest, or the oldest unpaid one), give the relation an order. The relation then sorts the newest 1,000 documents in the window by the order, and last_n keeps the first n. An edit to the order’s field can move a document into or out of the list, and Brussle judges the judged document again when that changes what the engine sees.
A write to a related document always marks its judged document as touched, but it causes an evaluation only when it changes what the engine sees:
- A new related document changes the list, so Brussle judges the judged document again after its writes stop.
- An edit to one of the last 8, in a field the relation shows, changes the context, and Brussle judges again.
- An edit to an older document, to a field no relation shows, or past a field’s
max_chars, changes nothing in the compiled context, so the answer stays and Brussle bills nothing.
match: one with a small last_n and fields, the other with a window and aggregate.
Debounce and its ceiling
debounce_ms makes Brussle wait until writes to the related documents stop, so 100 amendments in five minutes of negotiation cost one evaluation. max_wait_ms is the ceiling for a contract that never settles, and for a judgment with related documents it defaults to 12 × debounce_ms. Take a 10-minute debounce and a 1-hour ceiling, with a related document every minute for 3 hours. That costs 3 evaluations, not 180 and not 0. See freshness policies.
The answer reads pending while Brussle waits, so for a question about one event (whether one payment is fraud, say) keep a judgment of that one document.
The replay estimate
You might expect a judgment with related documents to cost in proportion to how many judged documents you have, but its cost depends on how often those related documents change. Before such a judgment starts underon_change, Brussle replays your namespace’s writes of the last 30 days through the relations, the debounce and the ceiling, and tells you what the judgment would have cost. This figure is the replay estimate. Two requests return it, and create nothing until you send confirm: true:
- a create of a version with
related, on a judgment whose policy ison_change - a change of such a judgment’s policy to
on_change
entitiesis the number of documents the judgment applies to now.judgments_per_monthis the number of evaluations the replay counted.row_units_per_monthis the rows kept that Brussle would bill for them, each counted by its size class (found from the compiled context and question of up to 1,000 of your judged documents) times the engine’s multiple. Each is a standard evaluation on Jev here, so it is twicejudgments_per_month.cost_usd_per_monthis their price at the tiers your organization would be in, including what it has already used this billing period.bulk_pool_shareis the part of the background judging rate available to this judgment that these evaluations would use. Above 1 the judgment cannot keep up with your writes, so raise the debounce or the ceiling, or narrow the relations.replayed_daysis less than 30 in a younger namespace, and the monthly figures are scaled up from it.
created_at, so it leaves out imported records older than the replayed days, and records imported without a created_at make the replay describe the import.
The replay sees only each related document’s creation and its latest write, not every edit. It is exact for documents you write once (events, messages and invoices). For documents you edit often the figures are a lower bound, so lower_bound is true and the dashboard shows them as “at least”. The replay also leaves out the evaluations that unchanged contexts save, which only make the bill lower, and it cannot count a fan-out at all.
Brussle refuses a confirmed request with budget_exceeded when its cost_usd_per_month is more than the namespace’s budget, which still caps the real spend. The dashboard warns you before you confirm.
What each answer and evaluation shows
An answer of a judgment with related documents has awatermark, which says how far into the namespace’s writes Brussle had read when it read the context, and the answer includes each write at or below it (to the judged document or to any document that points at it).
- A write to a related document makes its judged document
pendingat the next read, and it isfreshagain when an answer arrives with a watermark at or above that write. revisionstill gives the revision of the judged document itself.wait_forandwait_mswait only for the answer of the document you write or read, not of other documents. A write of an amendment withwait_for: ["auto_renews"]returns at once, becauseauto_renewsdoes not apply to amendments.
related_documents every related document the context read, rendered or aggregated, with its relation and the revision Brussle read. A named list also lists each id that rendered nothing, with unresolved: true. You get the list with include=history,context (include_history and include_context in Python, includeHistory and includeContext in TypeScript) or from GET /namespaces/{ns}/evaluations/{id}, and the dashboard’s evaluation page groups it by relation.
An outcome you post joins to an evaluation, and the evaluation names the amendments it read, so when an answer and its outcome disagree you can see what the engine read.
When the context is too long
The compiled context has a maximum, the lower of the recipe’smax_tokens and the engine’s limit (32,000 tokens with the longest question, on every engine today). Each relation’s bounds and its cap of 1,000 documents keep most contexts far below it. Over the maximum, Brussle cuts images first, then the records of the relations from the last name back (the farthest from the judged document first), then previous, then the judged document’s own fields. Brussle calculates aggregates before it cuts anything, and never cuts them. The evaluation records context_truncated: true and context_tokens, and Brussle bills for the context after the cut. Context recipes has the full order. If cuts happen often, lower last_n, show fewer or shorter fields, or move volume into aggregates.
Keep it affordable
- Keep
last_nsmall, so the judgment stays standard. A year of history can make it large or extra-large (which count as 4 and 16 rows before the engine’s multiple). - Use aggregates for how much or how often. A count is a few tokens, and with
"render": falsethe engine does not read it. - Show only the fields that matter, and the start of a long body with
max_chars. - Share recipes. Brussle answers judgments with the same context recipe together (
auto_renewsandnotice_period, for example), so each question after the first costs a quarter of a row, and a quarter more for each further 500 tokens of question text.
Records in sequence
Some questions are about one record in a sequence (“Is this message uncivil, given the thread?”, “Is this event unusual, given the session?”), and the judged document then reads the records just before it instead of the newest ones. Use a blocking relation with the sequence’s id as the key, and addrelative:
- The order is creation order:
created_at, thenidwhen two match. Import each record with its originalcreated_at, so each message reads the ones before it in the thread. - Each judged document reads its own neighbours.
"before"reads thelast_ndocuments of its block created just before it and"after"thelast_ncreated just after, never the judged document itself. The records show oldest first, and a message judged again a year later reads the same messages unless one of them changed. - No
windowand noorder. Brussle refuses either one besiderelativewithinvalid_request.last_nis at most 254, and 254 when you do not set it. - A change judges again only its neighbours. A document can be created, deleted, moved to another key, enter or leave
match, or change a field the relation shows. Brussle then judges again only the judged documents whoselast_nholds it, now or before the change, which is at mostlast_nof them, andfreshness.fanout.scopedoes not limit these re-judges. Each judged document of the block readspendinguntil Brussle checks the write, and one whose documents did not change keeps its answer, with nothing billed for it. Each re-judge counts against the rolling limit. - Other policies. Under a policy other than
on_change, a write to a document of the block makes each judged document of the blockstale, as for any blocking relation. block_capstill applies. A block with more judged documents thanblock_capwaits for a higher cap or a finer key.- The replay estimate counts each document created in the last 30 days as a touch of each earlier judged document whose
last_nit lands in. It cannot see edits and deletes, andexcludessays so.
Read what happened to related documents
You can ask “were this customer’s last orders refunded?” by showing the outcomes you posted for the related documents.outcomes.<judgment>.value is a document’s newest outcome for that judgment, as posted:
count_where counts the refunded orders and labelled the orders with an outcome, and you can name either as a feature. Put {"outcomes.refunded.value": {"exists": true}} in match to read only orders with an outcome. When more than 1,000 orders match and too few of the newest 1,000 have one, the evaluation shows relations_capped: true, and capped in its relation statistics names the relation.
Brussle judges each reader again after its debounce when you post an outcome, as a write to the order would, and the re-judges count against the reader’s rolling limit. The replay estimate counts the outcomes of the last 30 days that changed a document’s newest value. What happened to related documents says which outcome a relation reads and what it cannot read.
Not available yet
- The oldest documents of a relation with more than 1,000 matches, such as the first messages of a long thread. An
orderwith"desc": falsereads oldest first, although it sorts only the newest 1,000 (see pick documents with order). - Named collections. Use
applies_toon an attribute such askind. - Chains of answer reads more than three judgments deep, or that loop. See at most three levels.