| 1 | # 0011 · A mapping is configuration |
| 2 | |
| 3 | - **Status**: Implemented · `concept_mappings` table and wiring (#126, the same commit as |
| 4 | this record), a standalone Data Mappings page (#140), moved out of the Review queue (#148) |
| 5 | · of the three things to rebuild, the Review flow and history are done, the evidence chain |
| 6 | is not · one of two open questions answered (2026-09-02 check) |
| 7 | - **Written**: 2026-08-31 · condensed into English 2026-09-03 |
| 8 | - **Related**: [0009](0009-no-type-is-a-type.md) removes the builtin entity classes, |
| 9 | [0010](0010-no-relation-is-no-relation.md) the fallback relation, #125 the other eight |
| 10 | seed relations — this record is the last step on that line: **only vocabulary remains in |
| 11 | the ontology** |
| 12 | |
| 13 | ## The problem |
| 14 | |
| 15 | The semantic layer stored "business concept → data asset definition" as a fact: subject a |
| 16 | concept entity (Metric / Dimension), predicate `mapped_to` — a row in `relation_types` |
| 17 | beside `works_at` — object an `object_value` JSON `{ source, table?, expr?, sql?, unit?, |
| 18 | summary? }`, confidence 0.6 proposed / 1.0 confirmed. `review_routes` picked it up as a |
| 19 | low-confidence fact (< 0.75), Confirm set 1.0, and `chat.rs` read `confirmed_mappings` (≥ |
| 20 | 0.75) into the query prompt. |
| 21 | |
| 22 | The reuse was deliberate and bought three real things: a Review flow with zero new UI, |
| 23 | bitemporal history for free, and an evidence chain like any other fact's. Splitting means |
| 24 | rebuilding all three. |
| 25 | |
| 26 | ## Dead ends |
| 27 | |
| 28 | - **Keep the mapping as a fact.** Rejected on four grounds: |
| 29 | 1. It is not an assertion about the world. The ontology answers "what exists and how |
| 30 | things relate"; `mapped_to` answers "how this number is computed in our database". The |
| 31 | third application of one sentence: 0009 (`concept` is control flow), 0010 (`related_to` |
| 32 | is control flow), here `mapped_to` is configuration. |
| 33 | 2. It appeared where it should not: the ontology page listed it, the extraction prompt |
| 34 | offered it, ontology size counted it, and after #125 it was the **only** seed relation |
| 35 | — a new KB's ontology held exactly one thing, unrelated to the graph the user wants. |
| 36 | 3. "Confirm" already broke the ledger's foundation: `UPDATE facts SET confidence = 1.0` in |
| 37 | an append-only table where a correction inserts a new row with `supersedes`, because |
| 38 | the change of belief is itself information (0001 P0). Confirming changes not our belief |
| 39 | but whether a configuration is in effect; it only worked because that state happened to |
| 40 | fit in one float. |
| 41 | 4. The shape was wrong. The real fields `source / table / expr / sql / unit / summary` sat |
| 42 | inside JSONB: unqueryable ("which concepts map to `orders`"), unconstrainable |
| 43 | (uniqueness per (concept, source) hidden in JSON, closed by process rather than by the |
| 44 | database), unexplainable (`mapped_to` has no range — the object is neither an entity |
| 45 | nor a datatype). |
| 46 | - **Bitemporal history for the new table.** A definition has one axis, "when it took |
| 47 | effect"; forcing the ledger's two axes would move complexity rather than solve it. |
| 48 | |
| 49 | ## Decisions |
| 50 | |
| 51 | 1. **Its own table, `concept_mappings`**: concept entity id → definition, fields as columns, |
| 52 | `UNIQUE (kb_id, concept_id, source)` (a constraint; `id` is the primary key), plus a |
| 53 | `derived` column for derived metrics. `mapped_to` leaves `relation_types`, |
| 54 | `DEFAULT_RELATION_TYPES` empties, and a new KB seeds no relations at all. |
| 55 | 2. **Review without borrowing the low-confidence tier.** A proposal is configuration, not a |
| 56 | knowledge assertion. Built first as its own Review group, then (#140) as a standalone |
| 57 | Data Mappings page, with Review keeping only a count and a link (#148: a mapping is |
| 58 | neither a queue nor a history). The approval endpoints stay in `review_routes`, where the |
| 59 | `mapping.decided` audit stream lives. |
| 60 | 3. **History as revisions.** `created_at / confirmed_at / confirmed_by` on the row, full |
| 61 | snapshots in `concept_mapping_revisions` written by `revise()`, and a History drawer on |
| 62 | the page. |
| 63 | 4. **Evidence recorded separately** — a mapping's evidence is "which table's schema the LLM |
| 64 | read", not "which sentence". Not built: `concept_mappings` has no such column, and |
| 65 | exploration proposals leave no evidence. |
| 66 | 5. **No data migration.** Mock data only; the old `mapped_to` facts stay in the ledger |
| 67 | unread (as with #125). After release this convenience is gone. |
| 68 | 6. **Two things that landed unplanned.** `propose()` uses `ON CONFLICT … DO UPDATE … WHERE |
| 69 | status = 'proposed'`, so rerunning exploration does not erase a human rejection (when the |
| 70 | `WHERE` fails, `RETURNING` yields zero rows). Visibility is tiered: a Viewer can read the |
| 71 | list, `revise` needs Editor — seeing the answer without the definition means trusting an |
| 72 | algorithm you are not shown. |
| 73 | |
| 74 | ## Revisions |
| 75 | |
| 76 | - 2026-09-02: the status line said "planned" while the record arrived in the same commit as |
| 77 | its implementation. The status line is the implementing PR's responsibility; now a README |
| 78 | rule. |
| 79 | - 2026-09-02: we assumed a Review group would be the mapping's home; in use it became its |
| 80 | own page (#140, #148). |
| 81 | |
| 82 | ## Open questions |
| 83 | |
| 84 | - **A confirmed definition changes.** Answered by `revise` + `concept_mapping_revisions` + |
| 85 | the History drawer: "last quarter's definition" can be read back. Whether querying uses it |
| 86 | to replay historical reports is not built. |
| 87 | - **One concept, several sources.** `(kb_id, concept_id, source)` allows a different |
| 88 | definition per source, on purpose. Which one does querying use? Today all go into the |
| 89 | prompt (cap 30) and the model picks; rules are easier to add now that it is a table. |