World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
(#755)
WaylandYangd993006281d8
diff --git a/crates/utopia-core/src/models.rs b/crates/utopia-core/src/models.rsindex 624bfce3..cad33c00 100644--- a/crates/utopia-core/src/models.rs+++ b/crates/utopia-core/src/models.rs@@ -725,6 +725,10 @@ pub struct GraphEdge {/// 两个来源都拿不出时为 None——那是 add_evidence 记录原文说法之前的老数据pub predicate: Option<String>,pub label: Option<String>,+ /// 这条类型化边是从哪条开放陈述算出来的,那条陈述的原话(0044 决定 1,#755)。+ /// 画布把一条陈述只画一条边:有类型化行就画它,标签是属性的名字——原话不能因此+ /// 从画面上消失,它跟在这一格里。几条陈述算出同一行时是它们的原话,去重后拼起来+ pub said_as: Option<String>,/// true = 这条边的名字来自原文,不是本体认下的关系。界面要显示得看得出区别pub inferred: bool,/// true = 这条边是**推出来的**,不是任何人断言的(R1,住在 `derived_facts`)。@@ -786,6 +790,8 @@ pub struct NameView {#[derive(Debug, Clone, Serialize, sqlx::FromRow)]pub struct EntityFact {pub id: Uuid,+ /// 这条类型化事实是从哪条开放陈述算出来的,那条陈述的原话(#755)+ pub said_as: Option<String>,pub recorded_at: DateTime<Utc>,pub invalidated_at: Option<DateTime<Utc>>,pub supersedes: Option<Uuid>,diff --git a/crates/utopia-server/src/api/tools.rs b/crates/utopia-server/src/api/tools.rsindex 1108c692..476cb8ed 100644--- a/crates/utopia-server/src/api/tools.rs+++ b/crates/utopia-server/src/api/tools.rs@@ -1153,6 +1153,7 @@ mod tests {fn attribute_fact(value: serde_json::Value) -> EntityFact {EntityFact {+ said_as: None,recorded_at: chrono::Utc::now(),invalidated_at: None,supersedes: None,diff --git a/crates/utopia-server/src/api/tools_graph.rs b/crates/utopia-server/src/api/tools_graph.rsindex a7644666..95a62fef 100644--- a/crates/utopia-server/src/api/tools_graph.rs+++ b/crates/utopia-server/src/api/tools_graph.rs@@ -1222,6 +1222,7 @@ mod tests {fn fact(direction: &str, pred: &str, other: &str, other_type: Option<&str>) -> EntityFact {EntityFact {+ said_as: None,recorded_at: chrono::Utc::now(),invalidated_at: None,supersedes: None,diff --git a/crates/utopia-store/src/graph.rs b/crates/utopia-store/src/graph.rsindex 6db2cc05..0e912007 100644--- a/crates/utopia-store/src/graph.rs+++ b/crates/utopia-store/src/graph.rs@@ -1168,6 +1168,27 @@ pub async fn overview(Ok((nodes, edges, total_nodes, total_edges))}+/// 这条开放陈述已经被一条活着的类型化行代表(0044 决定 1:类型化图谱是开放图谱按+/// 绑定算出来的视图)。画布与实体面板据此一条陈述只画一条边——有类型化行就画它,+/// 标签是属性的名字;没有才画原话。**账本两条都留着**,这里只管画面。+/// `$f` 换成调用处的表别名+const REPRESENTED_BY_TYPED: &str = "EXISTS (SELECT 1 FROM typed_fact_sources src+ JOIN facts ty ON ty.id = src.fact_id+ WHERE src.statement_id = $f.id AND ty.invalidated_at IS NULL)";++fn represented_by_typed(alias: &str) -> String {+ REPRESENTED_BY_TYPED.replace("$f", alias)+}++/// 一条类型化行背后那些陈述的原话,去重拼起来(几条陈述可能算出同一行,见 0068)。+fn said_as(alias: &str) -> String {+ format!(+ "(SELECT string_agg(DISTINCT st.phrase, ' · ')+ FROM typed_fact_sources src JOIN facts st ON st.id = src.statement_id+ WHERE src.fact_id = {alias}.id)"+ )+}+async fn edges_among(pool: &PgPool,kb_id: Uuid,@@ -1195,6 +1216,7 @@ async fn edges_among("SELECT f.id, {subject} AS source, {object} AS target,COALESCE(r.key, fact_surface_predicate(f.id)) AS predicate,COALESCE(r.label, fact_surface_predicate(f.id)) AS label,+ {said_as} AS said_as,r.id IS NULL AS inferred, FALSE AS derived, NULL::text AS rule,ARRAY[]::uuid[] AS premises,f.valid_from, f.valid_to,@@ -1212,9 +1234,10 @@ async fn edges_among(WHERE f.kb_id = $1 AND {facts_held} AND f.object_id IS NOT NULLAND {subject} = ANY($2) AND {object} = ANY($2)AND {facts_hold}+ AND NOT {represented}UNION ALLSELECT d.id, d.subject_id AS source, d.object_id AS target,- r.key AS predicate, r.label AS label,+ r.key AS predicate, r.label AS label, NULL::text AS said_as,FALSE AS inferred, TRUE AS derived, ru.kind AS rule,ARRAY(SELECT fd.premise_fact_id FROM fact_derivations fdWHERE fd.derived_fact_id = d.id@@ -1233,6 +1256,7 @@ async fn edges_among((v.detail->>'subject_id')::uuid AS source,(v.detail->>'object_id')::uuid AS target,v.detail->>'predicate' AS predicate, v.detail->>'predicate' AS label,+ NULL::text AS said_as,FALSE AS inferred, TRUE AS derived, v.detail->>'rule' AS rule,v.path AS premises,(v.detail->>'valid_from')::timestamptz AS valid_from,@@ -1248,6 +1272,8 @@ async fn edges_among(AND {ghost_hold}",// 世界轴(0022):三段都从 world_axis 拼,读点上不再手写 NULL 的含义facts_hold = crate::world_axis::facts_hold_at("f", 3),+ said_as = said_as("f"),+ represented = represented_by_typed("f"),derived_hold = crate::world_axis::derived_hold_at("d", 3),ghost_hold = crate::world_axis::interval_holds_at("(v.detail->>'valid_from')::timestamptz",@@ -1441,7 +1467,7 @@ pub async fn entity_detail(.ok_or(AppError::NotFound)?;let mut facts: Vec<EntityFact> = sqlx::query_as(&format!(- "SELECT f.id, f.recorded_at, f.invalidated_at, f.supersedes,+ "SELECT f.id, {said_as} AS said_as, f.recorded_at, f.invalidated_at, f.supersedes,ARRAY(SELECT DISTINCT fe.document_id FROM fact_evidence feWHERE fe.fact_id = f.id AND fe.document_id IS NOT NULLORDER BY fe.document_id) AS document_ids,@@ -1487,10 +1513,13 @@ pub async fn entity_detail(ON o.id = CASE WHEN {subject} = $2 THEN {object} ELSE {subject} ENDLEFT JOIN entity_types ot ON ot.id = o.type_idWHERE f.kb_id = $1 AND {facts_held} AND {facts_hold}+ AND NOT {represented}AND ({subject} = $2 OR {object} = $2)AND {not_name}ORDER BY f.valid_from NULLS LAST, f.recorded_at",not_name = crate::names::not_a_name("f"),+ said_as = said_as("f"),+ represented = represented_by_typed("f"),facts_held = crate::record_axis::facts_held_at("f", 3),facts_hold = crate::world_axis::facts_hold_at("f", 4),holds_from = crate::world_axis::facts_holds_from("f"),diff --git a/docs/design/interface.md b/docs/design/interface.mdindex c47fe73a..1a6f09bc 100644--- a/docs/design/interface.md+++ b/docs/design/interface.md@@ -44,6 +44,11 @@ cards show the original sentence above the statements, the agent's proposal chipa rationale input [0015, 0025, 0026, 0027]. An open statement renders as an unnamed relationlabelled by its phrase [#731]. A page subtitle says the action the screen does, in one sentence.+**Layers on the canvas** [0044 decision 1, #755]. An open statement draws an edge labelled with the+document's phrase and marked as not-the-ontology's (`inferred`); once alignment computes a typed row+from it, that row draws the edge instead, labelled with the property, and the document's wording+rides along for the hover. One statement, one edge, whichever layer it currently lives in.+## Why- **One switch cannot serve five kinds of text** with different readers and sources; a quotation isdiff --git a/docs/design/ontology.md b/docs/design/ontology.mdindex 65042aaf..85171c0d 100644--- a/docs/design/ontology.md+++ b/docs/design/ontology.md@@ -49,6 +49,12 @@ classes of context neighbours, interleaved and never scored together; a class insubtree applied on its own, a cross-axis class sent to a person, each pair acknowledged once) runsfrom the ontology page; extraction no longer enqueues it [0001, 0016, #736].+**One statement draws one edge** [#755]. The typed graph is a view, so the canvas and the entity+panel show one edge per statement: the property's name when a live typed row was computed from it,+the document's phrase when none was. The document's wording is not lost with the folded edge, it+rides on the typed one (`said_as`, the phrases of every statement behind that row) and the interface+shows it. Both rows stay in the ledger; this is a rule about the picture, not about what is kept.+**A relation phrase binds to a property per signature** [0044 cut 2, #751]. A signature is aphrase as the documents wrote it, the class of its subject and the class of its object, or "value"when the object is a figure, a title or a status; the classes come from the kind-word bindings, anddiff --git a/web/src/api.ts b/web/src/api.tsindex bd3ff9bd..6c265721 100644--- a/web/src/api.ts+++ b/web/src/api.ts@@ -913,6 +913,9 @@ export interface GraphEdge {/** 本体没认下这条关系时是原文说法;两者都拿不出时为 null(0052 之前的老数据) */predicate: string | null;label: string | null;+ /** 这条边是从哪条开放陈述算出来的,那条陈述的原话(0044 决定 1):+ * 画布一条陈述只画一条边,有类型化行就画它,原话跟在这里不丢 */+ said_as: string | null;/** true = 这条边的名字来自原文,不是本体认下的关系 */inferred: boolean;/** true = 这条边是**推出来的**,不是任何人断言的(R1)。@@ -962,6 +965,9 @@ export interface EntityFact {/** 同 GraphEdge:本体外的关系回落到原文说法,两者都没有时为 null */predicate_key: string | null;predicate_label: string | null;+ /** 这条边是从哪条开放陈述算出来的,那条陈述的原话(0044 决定 1):+ * 画布一条陈述只画一条边,有类型化行就画它,原话跟在这里不丢 */+ said_as: string | null;/** true = 名字来自原文,不是本体认下的关系 */inferred: boolean;/** 关系的时态类别。没有谓词就无从谈起,为 null */diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex ac8d81a3..97f3de70 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -803,6 +803,7 @@ export const en = {「采购了」出来是 purchases——说"原文说的是 purchases"是假的。逐字原句就在旁边的证据引文里,没丢。 */proposedPredicate: (p: string) => `read from the text as “${p}”`,+ saidAs: (words: string) => `the documents say it “${words}”`,inferredPredicate:"not a relation in the ontology, this is the source's wording",unknownPredicate: "no relation stated",diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.tsindex 77548acc..bf06da9d 100644--- a/web/src/i18n/zh.ts+++ b/web/src/i18n/zh.ts@@ -731,6 +731,7 @@ export const zh: Strings = {openInDoc: "在文档里看这一段",proposedPredicate: (p: string) => `从原文读作「${p}」`,/* 本体没认下这条关系:显示的词来自原文,不是词表里的关系 */+ saidAs: (words: string) => `原文的说法:“${words}”`,inferredPredicate: "本体里没有这个关系,这是原文的说法",/* 连原文说法都没留下的老数据(0052 之前)。不编一个「有关联」出来 */unknownPredicate: "说不出是什么关系",diff --git a/web/src/pages/Graph.test.ts b/web/src/pages/Graph.test.tsindex 3f88d3fd..eba5c1e2 100644--- a/web/src/pages/Graph.test.ts+++ b/web/src/pages/Graph.test.ts@@ -23,6 +23,7 @@ import type { EntityFact } from "../api";const base: EntityFact = {id: "f",+ said_as: null,direction: "out",predicate_key: null,predicate_label: null,diff --git a/web/src/pages/Graph.tsx b/web/src/pages/Graph.tsxindex 231dec20..2c675e0f 100644--- a/web/src/pages/Graph.tsx+++ b/web/src/pages/Graph.tsx@@ -3301,7 +3301,14 @@ function FactRow({fact.predicate_label? fact.inferred? `${predicateSentence(fact.predicate_label)} · ${S.graph.inferredPredicate}`- : predicateSentence(fact.predicate_label)+ : // 本体认下的关系是从原文的说法算出来的(0044 决定 1):+ // 悬停说出那句原话,画布上少画的那条边不等于把它藏了+ [+ predicateSentence(fact.predicate_label),+ fact.said_as ? S.graph.saidAs(fact.said_as) : null,+ ]+ .filter(Boolean)+ .join(" · "): undefined}>