Skip to content
MSO CloudDocumentation

ADR 0062 — Brief matcher: a brief in, ranked entities and topic nodes out, configured as data

On this page
  • Status: Accepted (2026-11-13; the operator asked for a generic, reusable feature and delegated the design decisions)
  • Date: 2026-11-13
  • Owners: Content Intelligence (packages/metrics, apps/web/src/server, apps/worker, dashboard audience family).
  • Related: ADR 0022 (audience pillar), ADR 0024 (audience widgets), ADR 0037 (AI Card), ADR 0042 (dataset packs).

Context#

A content-intelligence tenant asked for a page where a planner types a key message and gets back the communities (sources, groups) and the topics inside them that fit it, each with a reason and a content direction. Nothing in the platform did this: deck chat answers free questions over aggregates, and an AI Card writes prose over a fixed scope. Neither takes reader input or returns rows a reader can drill into.

The request is generic. Any corpus with an entity dimension (a community, a channel, a source) and a topic hierarchy can answer it, so it is built once as a widget, and everything tenant-specific is widget config.

Decisions#

D1 — One audience widget kind, brief_match

A new kind in WIDGET_REGISTRY (family audience_structural, data source audience, template-allowed, not offered in the picker, never emitted by the deck generator). Its config block briefMatch names:

  • entityDimKey: the dimension whose values are ranked;
  • topic.childDimKey and optional topic.parentDimKey: the topic nodes and their grouping;
  • entityFilters (at most 4): a panel record dataset measure keyed by the entity's value, cut into half-open buckets [min, max) (at most 8, ascending, disjoint). The platform ships no default edges;
  • maxCandidates (at most 400), direction (tenant voice for the prompt), placeholder.

The schema refuses an entity dim equal to a topic dim, equal parent and child, overlapping or unordered buckets and repeated filter keys. At run time a dimension the corpus does not declare, or a missing cross pair entity × child (and parent × child), is a config error on the card, never a silent empty.

D2 — The model picks ids from a list the server built; every count comes from our readers

resolveBriefCandidates builds the candidate set inside the procedure's brand-scoped RLS transaction: entity × child cells that are non-zero in the page's scope, restricted to entities that pass the selected buckets, each child carrying its catalog label and definition. Above maxCandidates the largest are kept and the result says it was truncated.

The model sees the brief and catalog labels and definitions only — never mention text, authors or links. It receives run-local ordinals, not keys. filterBriefMatchToInputs drops unknown ordinals, nodes of another entity, repeats and entities left empty; reasons and directions are length-capped plain text. Counts are not stored with the result: result reads them live from the same cross read, and each count opens the existing record drill-down for entity + node.

D3 — A queued ai job, outcome in ai_insight_cache, no new table

The flow copies the taxonomy proposer: audienceBriefMatch.request (rate-limited brand mutation) checks the plugin, the corpus and the audience AI budget, returns a live cached answer, or enqueues audience-brief-match:<key> on queue ai through the outbox with an audit row holding the brief's hash and length, never its text. The worker always stores an outcome — ready, empty or failed — so the card can tell running from failed. result is a mutation so the brief travels in the request body, not a URL.

The cache key hashes org, brand, dataset, taxonomy version, the candidate set (which folds in the viewer's brand mask), the normalised brief, direction, locale and a prompt version. TTL: 24 h for ready/empty, 5 min for failed — proposals with no sourced policy behind them, to be revisited with usage.

D4 — Out of v1

Run history (needs an org-scoped table, an ask-first schema change), XLSX export and result checkboxes, a deck chat tool, a streamed progress log, corpora with no entity dimension, hierarchies deeper than two levels.

Consequences#

  • Any tenant whose pack installs the widget gets a new AI spend path, metered by organizations.audience_ai_budget_tokens. NULL means unlimited (packages/ai/src/server.ts), so such an org is bounded only by the request rate limit (10 per window per org; the polled result read is capped per viewer). Both caps are proposals, not sourced policy.
  • The card config travels from the client like other audience cards, so a member can vary direction as freely as the brief. Both are prompt text only; the output is still filtered against the server's own candidate list.
  • Web and worker deploy together: an unknown job-name prefix would fall through to another processor. No pack may install the widget before both are live.
  • Public share links render an abstain line; the card runs only inside the app.

Enforcement#

packages/metrics/src/content-brief-match.test.ts (cross-entity node, repeated node, bucket edges, cache key inputs, failed decoded as ready), apps/worker/src/processors/__tests__/brief-match-boundaries.test.ts (no catalog or mention import, always stores an outcome), apps/web/src/__tests__/brief-match-config.test.ts (schema refusals, pack page parse), apps/web/src/__tests__/audience-brief-candidates.test.ts (scope, buckets, undeclared pairs). Existing audits cover the paths: durable-job-outbox.py, ai-truncation-guard.py, runtime-acl-mutation-coverage.py, brand-input-asserted.py, deck-presentation-shape-ratchet.py (audit-ok-presentation-field on the registry entry).