Skip to main content
Write each record that you judge as a document. Queries filter on its attributes, while judgments read its state and the images that their recipe names. Every write gives the document a new revision, and every answer names the revision that it read, so you can tell whether the answer is still current. This document is a payment.

Fields

  • attributes is a flat map of at most 64 attributes, each a string, a number, a boolean, an array of strings or null. Queries can filter and sort on attributes. Brussle sends an attribute to an engine only if a judgment’s context recipe names it.
    • All the documents of a namespace have at most 1,024 different attribute names, and Brussle refuses a write that adds one more name with too_large and details.limit attribute_names. In that error, details.id names the document, details.path its first new attribute (attributes.customer_8812, for example), and details.attribute_names gives the current count. A name counts from the first write that uses it until you delete the namespace, so put values that vary (ids, dates and tags) in attribute values rather than in attribute names. Write {"customer": "8812"}, not {"customer_8812": true}.
    • A number reads back as you wrote it, and an integer keeps its exact value in the full signed and unsigned 64-bit range (1790799482246605123 comes back as 1790799482246605123). Filters and ranking compare integers exactly.
    • A number with a fraction or an exponent, such as 2.5 or 3.0, is a 64-bit float, and it comes back as a float. A filter treats 3 and 3.0 as equal.
    • null means no value, so an upsert leaves that attribute out, a patch removes it, a get does not return it, and Exists false matches it.
  • state is the JSON content that judgments read, a JSON object of at most 1 MB that queries cannot filter on. Nothing in state is ever an image, whatever its shape.
  • images maps a name to one image or a list of images, at most 16 images in all. A write sends each image as a data URL, such as "data:image/png;base64,...". Brussle stores the image once, and the document holds a reference to it, such as {"digest": "sha256:...", "type": "image/png", "width": 1440, "height": 960}. A get always returns images ({} when the document has none), and images do not count toward the 1 MB of state. A judgment reads an image only where its recipe names it, as images.<name>, and only engines that read images see it. See images in documents.
  • revision is the version number of the document, and it goes up each time a write changes the document (an upsert always does, even with the same content). Its value is the namespace’s sequence number at the change, so it always goes up but can skip numbers. Only your writes change it, so judging the document, a backfill, posting outcomes, a calibration fit or a new judgment leaves it as it was, and an if_revision from your last read still matches.
    • A document that you wrote once has the same revision and incarnation. The documents of one request always share a revision, although documents written in different requests usually do not, so an import gives each of its batches a different revision even though it writes each document once.
    • Each answer names the revision that it is for, and an answer that reads other documents also names its watermark (each write at or below that position is in the answer).
    • The answer reads pending or stale once the document changes after it. See freshness.
  • incarnation is the sequence number at which Brussle created the document. If you delete a document and write the same id again, the new document has a new incarnation and starts with no answers and no history, but the evaluations of earlier incarnations stay readable with all_incarnations=true.
  • created_at is when the document was created, which is the time of the write that created it or the created_at that write gave (at most 5 minutes in the future). Give a record’s original creation time when you import existing data. A later write never changes created_at, but a new incarnation gets a new created_at. Relations read related documents newest created_at first.

Writing

POST /namespaces/{ns} writes documents, at most 1,000 documents or 64 MB in one request. A namespace holds at most 100,000,000 documents or 256 GB, and Brussle refuses a write past either limit with too_large. A write to a namespace that does not exist creates it, at most 1,000 new namespaces a minute for each organization. See namespace limits. Brussle applies the operations of a request in this order: upsert, patch, append, delete. A request commits as one unit, never split across two commits. You can always retry a write safely, since each write has the same result if Brussle applies it again. System behavior tells what a late retry does. A write returns when its batch is durable (speed and limits).

Wait for answers

Add wait_for to a write to wait until the named judgments have answers for this revision.
  • wait_timeout_ms sets the longest wait, 5,000 by default, and Brussle lowers a value above 10,000 to 10,000.
  • An empty wait_for is the same as no wait_for.
  • The write is still committed if the wait times out, and the answers that were not ready come back pending, which here means only that they were not ready in the wait time.
  • Brussle judges the first 16 documents of a large write at interactive priority and the rest in the usual order, so the answers for the rest usually come back pending.
A get works out freshness from the stored answer, so a get can show a different freshness for the same answer. The answer is unavailable if the document was never judged in its current incarnation, and stale if its policy will not judge the new revision without a request from you.

Conditional upserts

An upsert can have if_revision, and the write then commits only if the document’s current revision is exactly that value. 0 means “only if the document does not exist” (it was never written, or it was deleted). Use if_revision to write back a document that you read, without overwriting a change that someone made after your read.
POST /v1/namespaces/acme%2Fprod
An upsert replaces the whole document, so if the document has images, send its images back as you read them. Brussle stores nothing again, and bills only the references. If the revision of any document differs, Brussle refuses the whole request with conflict and writes nothing in it. details.revisions gives the current revision of each document that did not match, or null if the document does not exist or has a write that is not committed yet.
After a conflict, read the document again and decide what to write.
  • A retry of a conditional write can also get conflict if the first attempt committed and the revision moved on, so read the document to find out.
  • if_revision is for upsert only, so a patch or an append always applies.
  • A document from a request that is not committed yet has no revision to match, so a conditional write to it gets conflict (with null for that document) until the other request commits.

Concurrent writes

Brussle applies the writes to one document in the order that they commit, so concurrent patch and append writes from different clients all stand. Brussle can refuse a write with rate_limited during a failover. Retry the write, as the SDKs do for you. See system behavior.

Reading

GET /namespaces/{ns}/documents/{id} returns the document with its answers.
  • Add include=history to get its evaluations, newest first.
  • Add include=history,context,raw to also get the compiled context and the raw engine response of each evaluation.
  • In the SDKs these are flags: ns.get(id, include_history=True, include_context=True, include_raw=True) in Python, and ns.get(id, { includeHistory: true, includeContext: true, includeRaw: true }) in TypeScript.
GET /namespaces/{ns}/images/{digest} returns an image that a document names (images in documents). POST /namespaces/{ns}/query filters, ranks and pages documents. See querying answers.