Skip to main content
Some answers depend on the documents that point at the judged one. Brussle reads them beside it, and judges the answer again, once, after they change. Counts from those documents can also be features, which the fit on your outcomes weighs beside the engine’s answer. Whether a contract still renews automatically depends on its amendments as well as on the contract, so the amendments are its related documents. Other pairs have the same shape:
  • a contract, with its amendments
  • an invoice, with the payments booked against it
  • a conversation, with its messages
Without a relation, you copy the related records into the judged document and write it again each time one of them changes. With one, Brussle finds the judged documents that each write touches, waits until a burst of writes stops, and judges each one once. Each evaluation records the related documents it read. The document it points at covers the other direction, where the judged document names one document (an order line names its product), and relations lists every kind.

Start with the simplest context

Decide what the question depends on before you add related documents, then try these options in this order:
  1. 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’s features_only shows what the engine adds.
  2. 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.
  3. Related text beside a narrow question about this document. Use this when the answer is in what the related documents say. Keep last_n small, and show only the fields the question needs.
For example, a contract can keep two numbers about its amendments as features:
The second option costs the most, since Brussle bills each related document’s judgment too (unless you already have that judgment for its own purpose). To select related documents by another judgment’s answer, select by topic, not by verdict. Measure each design on your outcomes before you rely on it, with the correction and the report.

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’s id in attributes.contract_id:
The engine reads the renewal clause and the last 8 amendments as text, while the count of the year’s amendments is a feature it does not read. The same shape works for an invoice and its payments (theirs: "attributes.invoice_id") and for a conversation and its messages (theirs: "attributes.conversation_id").
  • applies_to sets which documents the judgment judges, answers and bills, so other documents have no answer for it and filters treat that answer as missing.
  • match selects the documents a relation reads.
  • join says how they point at the judged document. A document belongs to the judged document whose id equals its theirs attribute.
  • last_n, window or both bound each relation, although a relation reads at most the newest 1,000 documents, whatever its bounds.
  • fields are the paths shown from each document, a related document’s image included (as images.<name>). aggregate adds numbers about the same documents, and its latest can take the newest document’s image. Each relation needs fields, aggregate or both.
The context recipe guide describes each key and the limits.

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 a reference_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 by created_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.
The judgment therefore does not see activity on an old related document. If that activity matters, record it as a new document (an event, say) rather than as an edit. Aggregates count the same documents the relation selects, so to show a few documents but count many you use two relations with the same 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 under on_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 is on_change
  • a change of such a judgment’s policy to on_change
  • entities is the number of documents the judgment applies to now.
  • judgments_per_month is the number of evaluations the replay counted.
  • row_units_per_month is 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 twice judgments_per_month.
  • cost_usd_per_month is their price at the tiers your organization would be in, including what it has already used this billing period.
  • bulk_pool_share is 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_days is less than 30 in a younger namespace, and the monthly figures are scaled up from it.
The replay counts a document as created at its 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 a watermark, 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 pending at the next read, and it is fresh again when an answer arrives with a watermark at or above that write.
  • revision still gives the revision of the judged document itself.
  • wait_for and wait_ms wait only for the answer of the document you write or read, not of other documents. A write of an amendment with wait_for: ["auto_renews"] returns at once, because auto_renews does not apply to amendments.
Each evaluation lists in 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’s max_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_n small, 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": false the 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_renews and notice_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 add relative:
  • The order is creation order: created_at, then id when two match. Import each record with its original created_at, so each message reads the ones before it in the thread.
  • Each judged document reads its own neighbours. "before" reads the last_n documents of its block created just before it and "after" the last_n created 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 window and no order. Brussle refuses either one beside relative with invalid_request. last_n is 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 whose last_n holds it, now or before the change, which is at most last_n of them, and freshness.fanout.scope does not limit these re-judges. Each judged document of the block reads pending until 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 block stale, as for any blocking relation.
  • block_cap still applies. A block with more judged documents than block_cap waits 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_n it lands in. It cannot see edits and deletes, and excludes says so.
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:
Each order shows its outcome, or nothing when it has none. 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 order with "desc": false reads oldest first, although it sorts only the newest 1,000 (see pick documents with order).
  • Named collections. Use applies_to on an attribute such as kind.
  • Chains of answer reads more than three judgments deep, or that loop. See at most three levels.