World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
An entity with no type is untyped, not a concept (#110)
WaylandYangc3393d386cea
diff --git a/.gitignore b/.gitignoreindex daa54cab..0b37f8f5 100644--- a/.gitignore+++ b/.gitignore@@ -5,7 +5,10 @@ node_modules/web/dist/*.log.DS_Store-/data+# 运行产物(上传原文 + Tantivy 索引)。**不写前导斜杠**:`/data` 只匹配仓库根,+# 而服务在哪个目录起就在哪儿建 data/——`web/data` 就是这么漏进来的(30 个文件,+# 含两份上传的测试文档)。跟 `_bench_*` 漏掉 `_holmes2.json` 是同一类错+data/# docs/ 是本地草稿区;只有决策记录与流水线参考入库。# 必须写成 /docs/* 而非 /docs——父目录被忽略时,子路径无法用 ! 重新纳入。/docs/*diff --git a/crates/utopia-core/src/models.rs b/crates/utopia-core/src/models.rsindex f1e13e02..1baaac5f 100644--- a/crates/utopia-core/src/models.rs+++ b/crates/utopia-core/src/models.rs@@ -435,7 +435,9 @@ pub struct RelationType {pub struct Entity {pub id: Uuid,pub kb_id: Uuid,- pub type_id: Uuid,+ /// `None` = 还没判出来。见 `docs/decisions/0009`——它不是一个类,+ /// 是「抽取器抽到了东西,但本体里没有对应的类」这个状态+ pub type_id: Option<Uuid>,pub canonical_name: String,pub aliases: Vec<String>,pub merged_into: Option<Uuid>,@@ -448,8 +450,10 @@ pub struct Entity {pub struct GraphNode {pub id: Uuid,pub name: String,- pub type_key: String,- pub type_label: String,+ /// 类型 key。**可能没有**(0009:没判出来就是 NULL),+ /// 前端据此显示"未分类"而不是编一个名字+ pub type_key: Option<String>,+ pub type_label: Option<String>,pub color: String,/// 类型形状:circle | squarepub shape: String,@@ -577,7 +581,8 @@ pub struct GraphChange {pub struct ReviewSide {pub id: Uuid,pub name: String,- pub type_label: String,+ /// 没判出类型时为 None(0009)。颜色另有缺省值——它是画布必须拿到的+ pub type_label: Option<String>,pub color: String,pub disambiguator: Option<String>,pub degree: i64,diff --git a/crates/utopia-extract/src/lib.rs b/crates/utopia-extract/src/lib.rsindex 4564b9cc..a7bca613 100644--- a/crates/utopia-extract/src/lib.rs+++ b/crates/utopia-extract/src/lib.rs@@ -198,8 +198,8 @@ pub fn build_messages(named after the text is worth more than a listed one that says something false.\n\9. The same holds for entity types: if none of the listed types fits, write the type \the text implies, in snake_case (e.g. \"model\", \"technology\"). Do not fall back \- to a broad listed type such as \"concept\" merely because nothing specific matched \- — that hides the gap instead of reporting it.\n\+ to a broad listed type such as \"thing\" or \"creative_work\" merely because \+ nothing specific matched — that hides the gap instead of reporting it.\n\10. specific_type is required on every entity and is never checked against the list. \Name the most specific kind the thing is, in the words you would use for it. Write \it even when \"type\" already fits, and make it narrower than \"type\" wherever the \diff --git a/crates/utopia-server/src/adjudication.rs b/crates/utopia-server/src/adjudication.rsindex 9da41b81..c60c728e 100644--- a/crates/utopia-server/src/adjudication.rs+++ b/crates/utopia-server/src/adjudication.rs@@ -21,7 +21,8 @@ fn pair_key(item: &ReviewItem) -> String {format!("{}|{}|{}",s.name.to_lowercase(),- s.type_label,+ // 没判出类型的一侧照样要能缓存(0009)+ s.type_label.as_deref().unwrap_or("untyped"),s.top_facts.join(";"))};@@ -80,12 +81,20 @@ pub async fn adjudicate_entities(state: &AppState, kb_id: Uuid) -> anyhow::Resul.map(|(item, _)| utopia_extract::AdjudicationPair {left: utopia_extract::AdjudicationSide {name: item.left.name.clone(),- type_label: item.left.type_label.clone(),+ type_label: item+ .left+ .type_label+ .clone()+ .unwrap_or_else(|| "untyped".into()),facts: item.left.top_facts.clone(),},right: utopia_extract::AdjudicationSide {name: item.right.name.clone(),- type_label: item.right.type_label.clone(),+ type_label: item+ .right+ .type_label+ .clone()+ .unwrap_or_else(|| "untyped".into()),facts: item.right.top_facts.clone(),},})diff --git a/crates/utopia-server/src/api/chat.rs b/crates/utopia-server/src/api/chat.rsindex 35f21c67..b608d505 100644--- a/crates/utopia-server/src/api/chat.rs+++ b/crates/utopia-server/src/api/chat.rs@@ -602,7 +602,12 @@ pub async fn chat(.unwrap_or_default();format!("{} | {}{} | {} | {} facts",- n.id, n.name, dis, n.type_label, n.degree+ n.id,+ n.name,+ dis,+ // 没判出类型的实体照样能被搜到、被引用(0009)+ n.type_label.as_deref().unwrap_or("untyped"),+ n.degree)}).collect::<Vec<_>>()diff --git a/crates/utopia-server/src/extraction.rs b/crates/utopia-server/src/extraction.rsindex 1965890a..e91b8b95 100644--- a/crates/utopia-server/src/extraction.rs+++ b/crates/utopia-server/src/extraction.rs@@ -123,10 +123,11 @@ pub async fn extract_document(state: &AppState, document_id: Uuid) -> anyhow::Reasync fn resolve(state: &AppState,kb_id: Uuid,- type_id: Uuid,+ // None = 模型给的类型不在本体里,或这个库根本还没有类(0009)+ type_id: Option<Uuid>,name: &str,ctx: Option<&[f32]>,- doc_cache: &mut HashMap<(Uuid, String), Uuid>,+ doc_cache: &mut HashMap<(Option<Uuid>, String), Uuid>,needs_adjudication: &mut bool,) -> anyhow::Result<Uuid> {let key = (@@ -258,9 +259,6 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {}false};- let concept_type = *type_ids- .get("concept")- .ok_or_else(|| anyhow::anyhow!("Ontology missing the 'concept' type"))?;let related_rel = rel_ids.get(FALLBACK_RELATION_KEY).copied();// 本轮要从头讲一遍这篇文档的故事,旧信号先清掉(重抽自动作数)let _ = utopia_store::extraction_drops::clear_for_document(&state.pool, document_id).await;@@ -268,7 +266,7 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {let doc_time = doc.doc_time.map(|t| t.format("%Y-%m-%d").to_string());let chunks = utopia_store::documents::chunks_for_extraction(&state.pool, document_id).await?;- let mut doc_cache: HashMap<(Uuid, String), Uuid> = HashMap::new();+ let mut doc_cache: HashMap<(Option<Uuid>, String), Uuid> = HashMap::new();// 本文档已经认下的实体,按首次出现排序,送进后续分块的提示词。//// **按 entity_id 去重,不按名字**:第 3 块写"上海研究院"若消解到了第 1 块的@@ -342,7 +340,7 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {// 实体消解:名称 → 实体 id(本分块的事实按原文名字连线)let mut entity_ids: HashMap<String, Uuid> = HashMap::new();// 名称 → 声明类型(属性 domain 校验用:salary 不能挂在 Organization 上)- let mut entity_type_of: HashMap<String, Uuid> = HashMap::new();+ let mut entity_type_of: HashMap<String, Option<Uuid>> = HashMap::new();for e in &extraction.entities {let name = e.name.trim();if name.is_empty() || name.chars().count() > 100 {@@ -353,9 +351,13 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {// concept 里面,唯一的出路是整库重抽let mut proposed: Option<&str> = None;let type_id = match type_ids.get(e.type_key.as_str()) {- Some(id) => *id,+ Some(id) => Some(*id),None => {- // 白名单外类型:降级 concept,并记入未匹配统计(本体扩展的信号)+ // 白名单外类型:**留空**,并记入未匹配统计(本体扩展的信号)。+ //+ // 从前这里降级到 concept 那行哨兵。现在「还没判出来」就是+ // `type_id IS NULL`(0009)——实体照常建、事实照常落、证据照常有,+ // 只是暂时没有类型。之后装一个包再跑类型消解,它会被重新分配let _ = utopia_store::ontology::record_miss(&state.pool,doc.kb_id,@@ -365,7 +367,7 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {).await;proposed = Some(e.type_key.as_str());- concept_type+ None}};let id = resolve(@@ -393,10 +395,17 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {{let _ = utopia_store::resolution::set_specific_type(&state.pool, id, st).await;}- // 只记模型自己声明过类型的:主宾兜底那条路一律按 concept 消解,- // 把一个猜出来的类型放进清单等于让后续分块照着猜的抄+ // 只记模型自己声明过类型的:主宾兜底那条路没有类型可依,+ // 把一个猜出来的类型放进清单等于让后续分块照着猜的抄。+ //+ // 本体装不下那个类时用模型自己的说法(proposed):这份清单是给后文+ // 认人用的,"同一个名字别写成两个实体"才是它的活。从前这里只能写死+ // concept,反倒把几个不同的词抹平成同一个标签if !doc_entities.iter().any(|(eid, _, _)| *eid == id) {- let tk = type_key_by_id.get(&type_id).copied().unwrap_or("concept");+ let tk = type_id+ .and_then(|t| type_key_by_id.get(&t).copied())+ .or(proposed)+ .unwrap_or("?");doc_entities.push((id, tk.to_string(), name.to_string()));}entity_ids.insert(name.to_string(), id);@@ -477,9 +486,11 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {if !attr.domains.iter()- .any(|d| type_matches_domain(subject_type, *d))+ .any(|d| subject_type.is_some_and(|t| type_matches_domain(t, *d))){- let subj_key = type_key_by_id.get(&subject_type).copied().unwrap_or("?");+ let subj_key = subject_type+ .and_then(|t| type_key_by_id.get(&t).copied())+ .unwrap_or("?");let dom_key = attr.domains.iter()@@ -682,14 +693,15 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {.await;continue;};- // 主宾未在 entities 中声明时,按 concept 兜底消解(模型偶尔漏报)+ // 主宾未在 entities 中声明时先建出来(模型偶尔漏报)。没有 entities 那条+ // 记录就没有类型可依,留空即可——0009 之前这里只能塞 conceptlet subject_id = match entity_ids.get(f.subject.trim()) {Some(id) => *id,None => {resolve(state,doc.kb_id,- concept_type,+ None,f.subject.trim(),ctx,&mut doc_cache,@@ -704,7 +716,7 @@ async fn run(state: &AppState, document_id: Uuid) -> anyhow::Result<()> {resolve(state,doc.kb_id,- concept_type,+ None,object_name,ctx,&mut doc_cache,diff --git a/crates/utopia-server/src/mappings.rs b/crates/utopia-server/src/mappings.rsindex 2c6556e8..571dc3ff 100644--- a/crates/utopia-server/src/mappings.rs+++ b/crates/utopia-server/src/mappings.rs@@ -124,9 +124,14 @@ pub async fn explore_mappings(state: &AppState, kb_id: Uuid) -> anyhow::Result<(let Some((type_id,)) = type_id else { continue };// 概念实体:走消解(同名归并;无向量上下文按 v1 兼容归并)- let resolved =- utopia_store::resolution::resolve_mention(&state.pool, kb_id, type_id, name, None)- .await?;+ let resolved = utopia_store::resolution::resolve_mention(+ &state.pool,+ kb_id,+ Some(type_id),+ name,+ None,+ )+ .await?;// 定义带 source + summary(Review 与 prompt 展示都靠 summary)let mut definition = p["definition"].clone();diff --git a/crates/utopia-server/src/type_resolution.rs b/crates/utopia-server/src/type_resolution.rsindex 5d1ddbde..3e0a25f5 100644--- a/crates/utopia-server/src/type_resolution.rs+++ b/crates/utopia-server/src/type_resolution.rs@@ -8,6 +8,11 @@//! 现在两个方向都认。纠正天然判为跨轴,所以一定进人工:推翻抽取的判断比//! 细化它风险大,不该自动发生。//!+//! 0009 之后还有第三种输入,而且是最常见的那种:**根本还没有类**。删掉兜底类+//! 之后,本体装不下的实体不再被塞进 `concept`,而是 `type_id IS NULL`。这一档+//! 身上没有"抽取的判断"要推翻,给它定类是补齐不是重新分类,所以**不判跨轴**、+//! 高置信度直接落库——否则删掉哨兵的代价就是每个实体都要人看一眼。+//!//! **为什么能事后做,而谓词不能**(0001 的那个不对称):类型是挂在节点上的//! 注解,可以等证据攒够了再贴;谓词就是事实本身,`(NVIDIA, ?, Mellanox)`//! 根本不是一条事实。所以谓词走"先记原词、后映射",类型走"先粗后精"。@@ -32,8 +37,6 @@ use crate::{llm_util, ontology_index, AppState};use utopia_core::{AppError, AppResult};use uuid::Uuid;-/// 倾倒场类的 key。挂在它下面的实体是"没判出来",不是"判成了这个"。-const DUMPING_GROUND: &str = "concept";/// 一轮看多少个实体。够一次人工过目,也够看出检索准不准。const BATCH: i64 = 60;/// 每个实体检索几个候选。给裁决看的,不是让它在一堆勉强相关里硬挑一个。@@ -46,12 +49,13 @@ const NEIGHBOURS: i64 = 10;pub struct TypeSuggestion {pub entity_id: Uuid,pub name: String,- pub coarse: String,+ /// 现在挂着的类,**可能没有**(0009)+ pub coarse: Option<String>,/// 现类的描述。裁决要判"现在这个类对不对",光看 key 不够- pub coarse_description: String,+ pub coarse_description: Option<String>,/// 粗类的 id。裁决要拿它跟目标类配成一对,去查"这一对人认可过没有"#[serde(skip)]- pub coarse_id: Uuid,+ pub coarse_id: Option<Uuid>,pub proposed_type: Option<String>,pub specific_type: Option<String>,pub fact_count: i64,@@ -101,13 +105,8 @@ pub async fn preview(state: &AppState, kb_id: Uuid) -> AppResult<Vec<TypeSuggestSome(utopia_store::ontology::TypeKind::Entity),).await;- let subjects = utopia_store::resolution::entities_for_type_resolution(- &state.pool,- kb_id,- DUMPING_GROUND,- BATCH,- )- .await?;+ let subjects =+ utopia_store::resolution::entities_for_type_resolution(&state.pool, kb_id, BATCH).await?;if subjects.is_empty() {return Ok(Vec::new());}@@ -158,11 +157,15 @@ pub async fn preview(state: &AppState, kb_id: Uuid) -> AppResult<Vec<TypeSuggest// **签名是导向,不是闸门**;系统性丢数据比偶尔判错贵得多。//// 该说不的是裁决那一步:它看得到描述、看得到粗类,能说出"这不是"。- let descendants: std::collections::HashSet<_> =- utopia_store::resolution::descendants_of(&state.pool, kb_id, s.coarse_id)+ // 还没有类的实体没有"粗类的后代"这个轴可用(0009),整张类表都是候选,+ // 排序就纯按检索顺序来+ let descendants: std::collections::HashSet<_> = match s.coarse_id {+ Some(c) => utopia_store::resolution::descendants_of(&state.pool, kb_id, c).await?.into_iter()- .collect();+ .collect(),+ None => std::collections::HashSet::new(),+ };// **两路交替取,不按距离合并。**//// 距离在两路之间不可比:短查询("医药集团")产生的距离系统性地小于@@ -184,7 +187,7 @@ pub async fn preview(state: &AppState, kb_id: Uuid) -> AppResult<Vec<TypeSuggestfor rank in 0..longest {for list in &lists {let Some(c) = list.get(rank) else { continue };- if c.id == s.coarse_id || !seen_ids.insert(c.id) {+ if Some(c.id) == s.coarse_id || !seen_ids.insert(c.id) {continue;}ranked.push(c.clone());@@ -194,14 +197,9 @@ pub async fn preview(state: &AppState, kb_id: Uuid) -> AppResult<Vec<TypeSuggestranked.sort_by_key(|c| !descendants.contains(&c.id));let candidates: Vec<_> = ranked.into_iter().take(CANDIDATES as usize).collect();// 第二路:语境相似的已定类实体,按类投票- let raw = utopia_store::resolution::nearest_typed_entities(- &state.pool,- kb_id,- s.id,- DUMPING_GROUND,- NEIGHBOURS,- )- .await?;+ let raw =+ utopia_store::resolution::nearest_typed_entities(&state.pool, kb_id, s.id, NEIGHBOURS)+ .await?;let mut votes: std::collections::BTreeMap<String, (usize, f64, Vec<String>, bool)> =std::collections::BTreeMap::new();for (name, _tid, key, distance, same_doc) in raw {@@ -217,7 +215,7 @@ pub async fn preview(state: &AppState, kb_id: Uuid) -> AppResult<Vec<TypeSuggest}let mut neighbours: Vec<NeighbourVote> = votes.into_iter()- .filter(|(key, _)| *key != s.coarse_key)+ .filter(|(key, _)| Some(key) != s.coarse_key.as_ref()).map(|(key, (votes, best_distance, examples, same_document_only))| NeighbourVote {key,@@ -332,7 +330,7 @@ pub struct ResolutionOutcome {#[derive(Debug, serde::Serialize)]pub struct DeclineNote {pub name: String,- pub coarse: String,+ pub coarse: Option<String>,pub specific_type: Option<String>,/// 模型给的理由;它压根没提到这个实体时为空pub reason: Option<String>,@@ -345,9 +343,10 @@ pub struct DeclineNote {pub struct ReviewItem {pub entity_id: Uuid,pub name: String,- pub coarse: String,- /// 配对的两端。认可这一条时认可的是**这一对类**,不是这一个实体- pub from_type_id: Uuid,+ pub coarse: Option<String>,+ /// 配对的两端。认可这一条时认可的是**这一对类**,不是这一个实体。+ /// 起点可能没有(0009)——那时没有"一对类"可认可,只能一个个改+ pub from_type_id: Option<Uuid>,pub to_type_id: Uuid,pub choice: String,pub confidence: f32,@@ -443,8 +442,16 @@ pub async fn resolve(state: &AppState, kb_id: Uuid) -> AppResult<ResolutionOutco// **纠正也走这里,而且天然如此**:抽取挑错细类之后(绍兴 → address),// 正确答案是它的兄弟而不是它的后代,所以一定判为跨轴、一定进人工。// 这正是想要的——推翻抽取的判断比细化它风险大,不该自动发生。- let crosses_axis = !item.descendants.contains(&target.id)- && !approved.contains(&(item.coarse_id, target.id));+ //+ // **还没有类的实体不算跨轴**(0009):它身上没有一个"抽取的判断"要被+ // 推翻,第一次给它定类是补齐而不是重新分类。这里若判成跨轴,等于+ // 删掉兜底类之后每一个实体都要人看一遍,整条自动化就废了+ let crosses_axis = match item.coarse_id {+ Some(from) => {+ !item.descendants.contains(&target.id) && !approved.contains(&(from, target.id))+ }+ None => false,+ };if confidence >= AUTO_THRESHOLD && !crosses_axis {picks.push((item.entity_id, target.id));} else {@@ -493,10 +500,13 @@ fn adjudication_prompt(items: &[TypeSuggestion]) -> String {for it in items {// 现类连描述一起给:要判"现在这个类对不对",光看 key 不够——// 导入本体的 key 常常自解释不了(`entry_point` 是什么?)- let current = if it.coarse_description.trim().is_empty() {- it.coarse.clone()- } else {- format!("{} ({})", it.coarse, it.coarse_description.trim())+ //+ // 没有类的实体直说没有(0009)。这一行从前一定填着 concept,模型读到的是+ // 「它已经是个概念」——一个错误的先验;现在读到的是「还没定」,正是实情+ let current = match (&it.coarse, it.coarse_description.as_deref().map(str::trim)) {+ (Some(k), Some(d)) if !d.is_empty() => format!("{k} ({d})"),+ (Some(k), _) => k.clone(),+ (None, _) => "not yet typed".into(),};let mut lines = vec![format!("### {}\ncurrently: {}\nthe extractor called it: {}\nseen as: {}",diff --git a/crates/utopia-store/src/graph.rs b/crates/utopia-store/src/graph.rsindex b4988e77..84b322f1 100644--- a/crates/utopia-store/src/graph.rs+++ b/crates/utopia-store/src/graph.rs@@ -26,95 +26,6 @@ const ADOPT_SUPERSEDED: &str = "superseded";/// 读成"并入"而不是"撤回",否则界面会宣称一件没发生的事。const ADOPT_MERGED: &str = "merged";-/// 内置本体模板:(key, label, color, shape, description)-///-/// **描述是承重的**:它逐字进抽取提示词,是模型区分 product 与 concept 的唯一依据。-/// 此前这一列在种子里是空的,于是提示词只有 `- product (Product)`——模型只能从-/// 标签猜,实测 `product` 吃下 37% 的实体,里面混着 GPU、accelerator 这类概念。-///-/// 写法:先说这个类**是什么**,再说**它不是什么**并指向该去的类。反例比正例管用——-/// 模型的错误集中在相邻类的边界上,不在类的中心。-// 低饱和粉彩色系(深色画布上柔和发光,不刺眼);组织/产品用方形区分"机构/制品"-const DEFAULT_ENTITY_TYPES: &[(&str, &str, &str, &str, &str)] = &[- (- "person",- "Person",- "#7fd0ff",- "circle",- "A named individual human being. Not a role, title or team — those are concepts \- or organizations.",- ),- (- "organization",- "Organization",- "#4cc38a",- "square",- "A company, institution, agency, team or other body of people that acts as one. \- Includes divisions and named groups. Not the products it makes.",- ),- (- "project",- "Project",- "#f2b66d",- "circle",- "A named initiative, programme or body of work with a beginning and an end. \- Not a shipped product, and not the organization running it.",- ),- // 问数语义层:可问的量与可切的维度(BI 语义层标准抽象),映射经 mapped_to 指向数据资产- (- "metric",- "Metric",- "#ffd580",- "square",- "A quantity that can be measured and aggregated — revenue, latency, headcount. \- The thing being counted, not a particular measured value.",- ),- (- "dimension",- "Dimension",- "#9adcc6",- "square",- "An axis a metric can be broken down by — region, channel, product line. \- The axis itself, not one of its values.",- ),- (- "product",- "Product",- "#c4a5ff",- "square",- "A specific named offering that can be bought, downloaded, played or subscribed to: \- a device, model, service, application or title. **A general capability, category or \- piece of technology is a concept, not a product** — \"GeForce RTX 5090\" is a product, \- \"GPU\" is a concept.",- ),- (- "event",- "Event",- "#ff9daf",- "circle",- "Something that happened or is scheduled to happen at a point in time — a launch, \- acquisition, conference, outage. Not the thing it happened to.",- ),- (- "concept",- "Concept",- "#8ea5bd",- "circle",- "An idea, capability, category, standard, technique or field — the general rather \- than the particular. Use it for things like \"inference\", \"GPU\", \"zero trust\". \- **Do not use it as a catch-all**: if the text names a specific product, organization \- or person, use that type; if it names a kind of thing this ontology has no type for, \- say so rather than filing it here (see the type rule).",- ),- (- "location",- "Location",- "#5fd4d0",- "circle",- "A place — country, region, city, campus, facility. Not the organization based there.",- ),-];-/// (key, label, temporal, functional, inverse_functional, description)////// functional = 同一时刻一个主语至多一个宾语(张三同时只 reports_to 一人);@@ -215,78 +126,19 @@ const DEFAULT_RELATION_TYPES: &[(&str, &str, &str, bool, bool, &str)] = &[),];-/// 内置本体的中文措辞:`key → (label, description)`。+/// 关系的中文措辞:`key → (label, description)`。label 是**动词短语**,+/// 读起来要能接上主宾:「张三 —任职于→ 星云科技」。///-/// **只覆盖 label 与 description**。颜色、形状、时态、函数性与语言无关,-/// 在上面那两张表里只有一份——复制一遍迟早会漂移。+/// **只覆盖 label 与 description**。时态与函数性跟语言无关,在上面那张表里+/// 只有一份——复制一遍迟早会漂移。////// 两条写法上的规矩,都不是文风问题:///-/// 1. **描述里提到其它类型时用 key,不用 label。** 中文库的 label 是「人物」,+/// 1. **描述里提到类型时用 key,不用 label。** 中文库的 label 是「人物」,/// 但模型必须输出 `person`。描述逐字进提示词,写「那些属于人物」等于教模型/// 输出一个不存在的类型。/// 2. **负面例子是干活的那半。** 模型的错误集中在相邻类的边界上,不在类的中心;-/// "什么不算" 比 "什么算" 更能改变结果(`product` 加上 GPU 那句反例后,-/// 真实语料上误标从 37.2% 降到 8.6%)。所以这不是翻译,是用中文重写一遍。-const ENTITY_TEXT_ZH: &[(&str, &str, &str)] = &[- (- "person",- "人物",- "有名有姓的具体的人。**不是**职务、头衔或团队——那些属于 concept 或 organization。",- ),- (- "organization",- "组织",- "作为一个整体行动的人的集合:公司、机构、政府部门、团队。包括事业部与有名字的小组。\- **不包括它做出来的产品**。",- ),- (- "project",- "项目",- "有起点也有终点的、有名字的计划、工程或一批工作。**不是**已经发布的产品,\- 也不是承担它的那个 organization。",- ),- (- "metric",- "指标",- "可度量、可聚合的量——营收、时延、人数。指**被数的那个东西本身**,\- 不是某一次量出来的具体数值。",- ),- (- "dimension",- "维度",- "指标可以被拆开看的那个轴——地区、渠道、产品线。指**轴本身**,不是轴上的某个取值。",- ),- (- "product",- "产品",- "可以购买、下载、游玩或订阅的**具体**产物:一台设备、一个模型、一项服务、\- 一个应用或一部作品。**泛指的能力、品类或技术是 concept,不是 product**——\- 「GeForce RTX 5090」是 product,「GPU」是 concept。",- ),- (- "event",- "事件",- "在某个时间点发生或将要发生的事——发布、收购、大会、故障。\- **不是**这件事发生在谁身上的那个「谁」。",- ),- (- "concept",- "概念",- "一个想法、能力、品类、标准、技术或领域——泛指而非特指。\- 用于「推理」「GPU」「零信任」这类。**不要拿它当兜底**:\- 原文若点名了具体的产品、组织或人,就用那个类型;\- 若点的是本体里没有对应类型的东西,直说没有,别往这里塞(见类型规则)。",- ),- (- "location",- "地点",- "一个地方——国家、地区、城市、园区、场所。**不是**总部设在那里的那个 organization。",- ),-];--/// 关系的中文措辞。label 是**动词短语**,读起来要能接上主宾:-/// 「张三 —任职于→ 星云科技」。+/// "什么不算" 比 "什么算" 更能改变结果。所以这不是翻译,是用中文重写一遍。const RELATION_TEXT_ZH: &[(&str, &str, &str)] = &[("works_at", "任职于", "一个人受雇于某个组织,或隶属于它。"),("leads", "领导", "一个人领导一个组织、项目或团队。"),@@ -336,28 +188,22 @@ fn localized(fallback}-/// 建库时铺内置本体。**已存在的行只补空描述,不覆盖人写过的**——种子里的描述是-/// 缺省值不是权威,用户按自己的语料调过之后不该被下一次调用抹掉。+/// 建库时铺内置本体——**只有关系,没有实体类**(见 `docs/decisions/0009`)。+/// 已存在的行只补空描述,+/// 不覆盖人写过的:种子里的描述是缺省值不是权威,用户按自己的语料调过之后+/// 不该被下一次调用抹掉。+///+///+/// 从前这里有九个(person、organization、location…)。通病是**零个带类型签名**,+/// 方向只能靠散文写;而装了 schema.org 之后它们又会被同名的真类顶替,+/// 等于从头到尾只是个占位。`location` 是反例中的反例——schema.org 里它叫 `Place`,+/// key 对不上于是不被认领,`City` 挂到另建的 `place` 底下,+/// 一个我们自己起的名字把整条地理子树割断了。+///+/// 兜底类 `concept` 一并退场:「还没判出来」现在由 `entities.type_id IS NULL` 表达。+/// 哨兵有名字,有名字就会撞——`skos:Concept` 派生出的 key 正是 `concept`,+/// 而哨兵没有 IRI,导入的「占位者没有 IRI 就认领它」会让它直接接管。pub async fn ensure_default_ontology(pool: &PgPool, kb_id: Uuid, lang: &str) -> AppResult<()> {- for (key, en_label, color, shape, en_description) in DEFAULT_ENTITY_TYPES {- let (label, description) = localized(ENTITY_TEXT_ZH, key, lang, (en_label, en_description));- sqlx::query(- "INSERT INTO entity_types (id, kb_id, key, label, color, shape, builtin, description)- VALUES ($1, $2, $3, $4, $5, $6, TRUE, $7)- ON CONFLICT (kb_id, key) DO UPDATE- SET description = EXCLUDED.description- WHERE entity_types.description = ''",- )- .bind(Uuid::now_v7())- .bind(kb_id)- .bind(key)- .bind(label)- .bind(color)- .bind(shape)- .bind(description)- .execute(pool)- .await?;- }for (key, en_label, temporal, functional, inverse_functional, en_description) inDEFAULT_RELATION_TYPES{@@ -707,11 +553,22 @@ pub async fn add_evidence(Ok(())}+/// 所有图查询共用的取节点语句。+///+/// **LEFT JOIN,不是 JOIN**(0009)。没判出类型的实体照样是图上的节点:它有名字、+/// 有事实、有证据,缺的只是一个标签。内连接会让它整个消失——事实还在库里,+/// 图上却查无此人,那是最难发现的一种数据丢失。+///+/// key 与 label 留 NULL,**颜色和形状给缺省值**:前者是身份,没有就该说没有;+/// 后者是画布必须拿到的东西,编不出来就没法渲染。灰色圆点正是「还没定」的样子const NODE_SQL: &str = "SELECT e.id, e.canonical_name AS name, t.key AS type_key,- t.label AS type_label, t.color, t.shape, e.disambiguator,+ t.label AS type_label,+ coalesce(t.color, '#94a3b8') AS color,+ coalesce(t.shape, 'circle') AS shape,+ e.disambiguator,(SELECT count(*) FROM facts fWHERE (f.subject_id = e.id OR f.object_id = e.id) AND f.invalidated_at IS NULL) AS degree- FROM entities e JOIN entity_types t ON t.id = e.type_id";+ FROM entities e LEFT JOIN entity_types t ON t.id = e.type_id";/// 全图概览:按度数取 top N 实体及其间的边。/// `at`:服务端 as-of——只返回 T 时刻有效的边(起点不晚于 T 或未知,终点晚于 T 或开放)。diff --git a/crates/utopia-store/src/resolution.rs b/crates/utopia-store/src/resolution.rsindex a3295535..04ac82f4 100644--- a/crates/utopia-store/src/resolution.rs+++ b/crates/utopia-store/src/resolution.rs@@ -101,13 +101,9 @@ pub fn recall_keys(name: &str) -> Vec<String> {}// ----------------------------------------------------------------------------// 类型漂移:同名实体被抽成了不同类型("Orion platform team" ↔ organization/project/concept)+// 类型漂移:同名实体被抽成了不同类型("Orion platform team" ↔ organization/project)// ----------------------------------------------------------------------------/// 抽取兜底类型:白名单外类型与漏报的主宾都降级到 concept(见 extraction),-/// 因此 concept ↔ 具体类型 的同名大概率是同一实体的类型漂移,按召回候选参与画像分层。-pub const FALLBACK_TYPE_KEY: &str = "concept";-/// 易混具体类型:抽取常在这几类间摇摆(一个团队算组织还是项目?平台算项目还是产品?)。/// 同名跨这组类型 → 照建实体(宁分勿合),但入队审核对交 LLM/人工裁决。/// DESIGN.md §3.2 的 disjoint 公理目前只是设计面(0005 仅落了 subClassOf 数据面),@@ -128,7 +124,7 @@ enum TypeDrift {Disjoint,}-fn classify_type_drift(a: &str, b: &str) -> TypeDrift {+fn classify_type_drift(a: Option<&str>, b: Option<&str>) -> TypeDrift {// **同一个类型当然可能是同一个东西。**//// 这一档原本不存在,因为这个函数生来只服务"类型漂移"——同名被抽成两种@@ -142,9 +138,13 @@ fn classify_type_drift(a: &str, b: &str) -> TypeDrift {if a == b {return TypeDrift::Recall;}- if a == FALLBACK_TYPE_KEY || b == FALLBACK_TYPE_KEY {+ // **一侧还没判出来** → 当召回候选,走画像相似度分层。+ // 从前比的是 `== FALLBACK_TYPE_KEY`,那个 key 已经没有了:+ // 「还没判出来」现在由 `None` 表达(0009)。两边都是 None+ // 已经被上面 `a == b` 那行接住+ let (Some(a), Some(b)) = (a, b) else {return TypeDrift::Recall;- }+ };if CONFUSABLE_TYPE_KEYS.contains(&a) && CONFUSABLE_TYPE_KEYS.contains(&b) {return TypeDrift::Review;}@@ -197,7 +197,8 @@ pub struct ReviewRequest {pub async fn resolve_mention(pool: &PgPool,kb_id: Uuid,- type_id: Uuid,+ // None = 抽取器给的类型不在本体里,或库里根本没有类(0009)+ type_id: Option<Uuid>,raw_name: &str,context: Option<&[f32]>,) -> AppResult<Resolution> {@@ -351,7 +352,8 @@ const CONTAIN_SCAN_LIMIT: i64 = 16;async fn containment_reviews(pool: &PgPool,kb_id: Uuid,- type_id: Uuid,+ // None = 抽取器给的类型不在本体里,或库里根本没有类(0009)+ type_id: Option<Uuid>,name: &str,new_id: Uuid,ctx: Option<&[f32]>,@@ -360,18 +362,24 @@ async fn containment_reviews(if lower.chars().count() < MIN_CONTAIN_CHARS as usize {return Ok(Vec::new());}- let (mention_key,): (String,) = sqlx::query_as("SELECT key FROM entity_types WHERE id = $1")- .bind(type_id)- .fetch_one(pool)- .await?;+ // 实体可能还没判出类型(0009),那时没有 key 可查+ let mention_key: Option<String> = match type_id {+ Some(t) => sqlx::query_as::<_, (String,)>("SELECT key FROM entity_types WHERE id = $1")+ .bind(t)+ .fetch_optional(pool)+ .await?+ .map(|(k,)| k),+ None => None,+ };// **不按类型过滤**:简称经常掉进 concept 兜底,而全称是具体类型//(实测 上海研究院→concept vs 星云科技上海研究院→organization,// 启明 X7 加速卡→concept vs 启明 X7 推理加速卡→product),// 按类型相等去查,这两对一个都捞不到。相容性交给下面的 classify_type_drift。// 多取一些行,因为硬互斥的会在 Rust 侧被筛掉- let rows: Vec<(Uuid, String, String, Option<Vector>)> = sqlx::query_as(+ // 第三列可空:未分类实体也要参与包含关系扫描(0009)+ let rows: Vec<(Uuid, String, Option<String>, Option<Vector>)> = sqlx::query_as("SELECT e.id, e.canonical_name, t.key, e.profile_embedding- FROM entities e JOIN entity_types t ON t.id = e.type_id+ FROM entities e LEFT JOIN entity_types t ON t.id = e.type_idWHERE e.kb_id = $1 AND e.merged_into IS NULLAND e.id <> $2AND lower(e.canonical_name) <> $3@@ -410,7 +418,7 @@ async fn containment_reviews(// 哪些类型对可能指同一个东西,既有规则已经想清楚了,别另发明一套:// person vs organization 永不合并,concept 兜底与谁都可能是一个.filter(|(_, _, type_key, _)| {- classify_type_drift(&mention_key, type_key) != TypeDrift::Disjoint+ classify_type_drift(mention_key.as_deref(), type_key.as_deref()) != TypeDrift::Disjoint}).take(MAX_CONTAIN_REVIEWS).map(|(id, other_name, _, emb)| {@@ -432,22 +440,28 @@ async fn containment_reviews(struct CrossCandidate {id: Uuid,canonical_name: String,- type_key: String,+ // None = 这个候选还没判出类型(0009)+ type_key: Option<String>,profile_embedding: Option<Vector>,profile_n: i32,}/// `reason` 存 code,措辞归界面(docs/decisions/0004)——这一列不该一半 code/// 一半英文句子,那样中文界面上就是一半能翻一半不能。-fn drift_reason(mention_key: &str, other_key: &str, sim: Option<f32>) -> String {+fn drift_reason(mention_key: Option<&str>, other_key: Option<&str>, sim: Option<f32>) -> String {+ // 未分类的一侧写成 `(untyped)`。这一列存 code 供界面翻译,+ // 留空会让 `a vs b` 变成 `a vs `,读起来像被截断而不像"没有"+ let a = mention_key.unwrap_or("(untyped)");+ let b = other_key.unwrap_or("(untyped)");match sim {- Some(s) => format!("type_drift|{mention_key} vs {other_key} {s:.2}"),- None => format!("type_drift|{mention_key} vs {other_key}"),+ Some(s) => format!("type_drift|{a} vs {b} {s:.2}"),+ None => format!("type_drift|{a} vs {b}"),}}fn confusable_reviews(- mention_key: &str,+ // None = 这一侧还没判出类型(0009)+ mention_key: Option<&str>,cands: &[&CrossCandidate],ctx: Option<&[f32]>,) -> Vec<ReviewRequest> {@@ -462,7 +476,7 @@ fn confusable_reviews(ReviewRequest {other_id: c.id,score: sim.unwrap_or(0.0),- reason: drift_reason(mention_key, &c.type_key, sim),+ reason: drift_reason(mention_key, c.type_key.as_deref(), sim),}}).collect()@@ -475,19 +489,27 @@ fn confusable_reviews(async fn resolve_type_drift(pool: &PgPool,kb_id: Uuid,- type_id: Uuid,+ // None = 抽取器给的类型不在本体里,或库里根本没有类(0009)+ type_id: Option<Uuid>,name: &str,keys: &[String],context: Option<&[f32]>,) -> AppResult<Resolution> {- let (mention_key,): (String,) = sqlx::query_as("SELECT key FROM entity_types WHERE id = $1")- .bind(type_id)- .fetch_one(pool)- .await?;+ // 这一侧也可能还没判出类型(0009),那时没有 key 可查+ let mention_key: Option<String> = match type_id {+ Some(t) => sqlx::query_as::<_, (String,)>("SELECT key FROM entity_types WHERE id = $1")+ .bind(t)+ .fetch_optional(pool)+ .await?+ .map(|(k,)| k),+ None => None,+ };let cross: Vec<CrossCandidate> = sqlx::query_as("SELECT e.id, e.canonical_name, t.key AS type_key, e.profile_embedding, e.profile_n- FROM entities e JOIN entity_types t ON t.id = e.type_id- WHERE e.kb_id = $1 AND e.type_id <> $2 AND e.merged_into IS NULL+ FROM entities e LEFT JOIN entity_types t ON t.id = e.type_id+ -- IS DISTINCT FROM 而不是 <>:后者遇 NULL 返回 NULL,被 WHERE 当假,+ -- 未分类实体会被整个漏掉(0009)+ WHERE e.kb_id = $1 AND e.type_id IS DISTINCT FROM $2 AND e.merged_into IS NULLAND (lower(e.canonical_name) = ANY($3)OR EXISTS (SELECT 1 FROM unnest(e.aliases) a WHERE lower(a) = ANY($3)))",)@@ -500,7 +522,7 @@ async fn resolve_type_drift(let mut recall_cands: Vec<&CrossCandidate> = Vec::new();let mut review_cands: Vec<&CrossCandidate> = Vec::new();for c in &cross {- match classify_type_drift(&mention_key, &c.type_key) {+ match classify_type_drift(mention_key.as_deref(), c.type_key.as_deref()) {TypeDrift::Recall => recall_cands.push(c),TypeDrift::Review => review_cands.push(c),TypeDrift::Disjoint => {}@@ -520,9 +542,9 @@ async fn resolve_type_drift(if let Some((best, sim)) = best {if sim >= SIM_ATTACH {update_profile(pool, best.id, best.profile_n, ctx).await?;- if best.type_key == FALLBACK_TYPE_KEY && mention_key != FALLBACK_TYPE_KEY {- // concept 只是"没认出来",具体类型是更强的判断 → 升格。- // 不是合并(没有第二个实体),不入 entity_merges;本体页可手工改回。+ // 候选还没判出类型而这次抽取判出来了 → 升格。+ // 不是合并(没有第二个实体),不入 entity_merges;本体页可手工改回+ if best.type_key.is_none() && type_id.is_some() {sqlx::query("UPDATE entities SET type_id = $2, updated_at = now() WHERE id = $1",)@@ -534,7 +556,8 @@ async fn resolve_type_drift(refresh_disambiguators(pool, kb_id, &best.canonical_name).await?;}// mention 已定居到召回实体;同名易混类型实体的疑点仍在 → 照常入队- let mut reviews = confusable_reviews(&mention_key, &review_cands, Some(ctx));+ let mut reviews =+ confusable_reviews(mention_key.as_deref(), &review_cands, Some(ctx));reviews.truncate(MAX_DRIFT_REVIEWS);return Ok(Resolution {entity_id: best.id,@@ -550,7 +573,7 @@ async fn resolve_type_drift(// 跨类型同名并存:消歧后缀按名字分组(不分类型),需要刷新refresh_disambiguators(pool, kb_id, name).await?;}- let mut reviews = confusable_reviews(&mention_key, &review_cands, context);+ let mut reviews = confusable_reviews(mention_key.as_deref(), &review_cands, context);for c in &recall_cands {let sim = context.and_then(|ctx| {c.profile_embedding@@ -564,7 +587,7 @@ async fn resolve_type_drift(_ => reviews.push(ReviewRequest {other_id: c.id,score: sim.unwrap_or(0.0),- reason: drift_reason(&mention_key, &c.type_key, sim),+ reason: drift_reason(mention_key.as_deref(), c.type_key.as_deref(), sim),}),}}@@ -581,7 +604,8 @@ async fn resolve_type_drift(async fn create_entity(pool: &PgPool,kb_id: Uuid,- type_id: Uuid,+ // None = 抽取器给的类型不在本体里,或库里根本没有类(0009)+ type_id: Option<Uuid>,name: &str,context: Option<&[f32]>,) -> AppResult<Uuid> {@@ -680,18 +704,18 @@ pub async fn refresh_disambiguators(pool: &PgPool, kb_id: Uuid, name: &str) -> A.bind(id).fetch_optional(pool).await?;- let disambiguator = match label {- Some((l,)) => l,- None => {- let (type_label,): (String,) = sqlx::query_as(- "SELECT t.label FROM entities e JOIN entity_types t ON t.id = e.type_id+ // 关联事实找不着就退到类型标签;**类型也可能没有**(0009),+ // 那就没有可写的后缀——留 NULL,界面按同名并列显示,别编一个出来+ let disambiguator: Option<String> = match label {+ Some((l,)) => Some(l),+ None => sqlx::query_as::<_, (String,)>(+ "SELECT t.label FROM entities e JOIN entity_types t ON t.id = e.type_idWHERE e.id = $1",- )- .bind(id)- .fetch_one(pool)- .await?;- type_label- }+ )+ .bind(id)+ .fetch_optional(pool)+ .await?+ .map(|(l,)| l),};sqlx::query("UPDATE entities SET disambiguator = $2 WHERE id = $1").bind(id)@@ -749,17 +773,20 @@ async fn review_side(pool: &PgPool, kb_id: Uuid, entity_id: Uuid) -> AppResult<Rstruct SideRow {id: Uuid,name: String,- type_label: String,+ type_label: Option<String>,color: String,disambiguator: Option<String>,degree: i64,}let row: SideRow = sqlx::query_as(- "SELECT e.id, e.canonical_name AS name, t.label AS type_label, t.color, e.disambiguator,+ "SELECT e.id, e.canonical_name AS name, t.label AS type_label,+ coalesce(t.color, '#94a3b8') AS color, e.disambiguator,(SELECT count(*) FROM facts fWHERE (f.subject_id = e.id OR f.object_id = e.id)AND f.invalidated_at IS NULL) AS degree- FROM entities e JOIN entity_types t ON t.id = e.type_id+ -- LEFT JOIN:没判出类型的实体照样要能进审核(0009)。+ -- 内连接会让它整条审核项取不出来,而漂移审核恰恰最常发生在它们身上+ FROM entities e LEFT JOIN entity_types t ON t.id = e.type_idWHERE e.kb_id = $1 AND e.id = $2",).bind(kb_id)@@ -1004,7 +1031,8 @@ pub async fn merge_direction(pool: &PgPool, a: Uuid, b: Uuid) -> AppResult<(Uuid#[derive(Debug, sqlx::FromRow)]struct EntityFull {- type_id: Uuid,+ // None = 还没判出来(0009)+ type_id: Option<Uuid>,canonical_name: String,aliases: Vec<String>,profile_embedding: Option<Vector>,@@ -1147,21 +1175,12 @@ pub async fn merge_entities((None, None) => (None, 0),};- // 类型调和:concept 是抽取兜底而非类型判断,被并侧带具体类型时目标升格;- // 两个具体类型相并(易混对被裁"same")保留 target(存活方)的类型。- let concept_type: Option<Uuid> =- sqlx::query_as::<_, (Uuid,)>("SELECT id FROM entity_types WHERE kb_id = $1 AND key = $2")- .bind(kb_id)- .bind(FALLBACK_TYPE_KEY)- .fetch_optional(&mut *tx)- .await?- .map(|(id,)| id);- let new_type_id =- if concept_type == Some(target.type_id) && concept_type != Some(source.type_id) {- source.type_id- } else {- target.type_id- };+ // 类型调和:**没有类型的一侧让位**。存活方还没判出来而被并方判出来了,+ // 就把那个类型带过来;否则保留存活方的。+ //+ // 从前这里要先查库找出 concept 那行的 id 再跟两侧比对。「还没判出来」+ // 现在是 `None`(0009),一个 `or` 就说完了,那次查询也省了+ let new_type_id = target.type_id.or(source.type_id);sqlx::query("UPDATE entities SET aliases = $2, profile_embedding = $3, profile_n = $4,@@ -1511,11 +1530,15 @@ pub async fn adopt_proposed_types(if forms.is_empty() {return Ok((batch_id, 0));}- // 已经在目标类上的不算改动,也不进账本——撤销时不该把它们推回去- let targets: Vec<(Uuid, Uuid, String)> = sqlx::query_as(+ // 已经在目标类上的不算改动,也不进账本——撤销时不该把它们推回去。+ //+ // **`IS DISTINCT FROM` 而不是 `<>`**:0009 之后 type_id 可能是 NULL,而+ // `NULL <> uuid` 求值为 NULL 不是 true,那一行会被悄悄滤掉——偏偏带着+ // proposed_type 的几乎全是还没判出类型的实体,整个认领功能会一声不响地空转+ let targets: Vec<(Uuid, Option<Uuid>, String)> = sqlx::query_as("SELECT id, type_id, canonical_name FROM entitiesWHERE kb_id = $1 AND merged_into IS NULL- AND proposed_type = ANY($2) AND type_id <> $3",+ AND proposed_type = ANY($2) AND type_id IS DISTINCT FROM $3",).bind(kb_id).bind(forms)@@ -1562,7 +1585,9 @@ pub async fn adopt_proposed_types(/// 类型本身不删——与谓词那边同一条理由:有实体指向过它,而"它存在过"是历史。/// `proposed_type` 也一并恢复,否则撤销之后那些实体就再也认领不回来了。pub async fn unadopt_types(pool: &PgPool, kb_id: Uuid, batch_id: Uuid) -> AppResult<u32> {- let rows: Vec<(Uuid, Uuid, String)> = sqlx::query_as(+ // from_type_id 可能是 NULL:0009 之后最常见的一次改类正是"从没有类到有类",+ // 撤销就是把它推回没有类。解成 Uuid 会在这里当场崩+ let rows: Vec<(Uuid, Option<Uuid>, String)> = sqlx::query_as("SELECT r.entity_id, r.from_type_id, t.keyFROM entity_retypes r JOIN entity_types t ON t.id = r.to_type_idWHERE r.batch_id = $1 AND r.kb_id = $2 AND r.reverted_at IS NULL",@@ -1699,38 +1724,46 @@ mod tests {#[test]fn type_drift_classes() {- // 兜底型任意一侧 → 召回候选+ // 还没判出类型的那一侧 → 召回候选。0009 之前这一档比的是 `concept`+ // 这个 key,现在比的是"有没有类"本身+ assert_eq!(+ classify_type_drift(None, Some("organization")),+ TypeDrift::Recall+ );assert_eq!(- classify_type_drift("concept", "organization"),+ classify_type_drift(Some("project"), None),TypeDrift::Recall);- assert_eq!(classify_type_drift("project", "concept"), TypeDrift::Recall);- assert_eq!(classify_type_drift("concept", "person"), TypeDrift::Recall);+ // 两边都还没判出来:也归召回,由画像相似度说话+ assert_eq!(classify_type_drift(None, None), TypeDrift::Recall);// 易混具体类型两两 → 审核对assert_eq!(- classify_type_drift("organization", "project"),+ classify_type_drift(Some("organization"), Some("project")),+ TypeDrift::Review+ );+ assert_eq!(+ classify_type_drift(Some("project"), Some("product")),TypeDrift::Review);- assert_eq!(classify_type_drift("project", "product"), TypeDrift::Review);assert_eq!(- classify_type_drift("product", "organization"),+ classify_type_drift(Some("product"), Some("organization")),TypeDrift::Review);// 硬互斥与未知自定义类型 → 完全分开assert_eq!(- classify_type_drift("person", "organization"),+ classify_type_drift(Some("person"), Some("organization")),TypeDrift::Disjoint);assert_eq!(- classify_type_drift("person", "project"),+ classify_type_drift(Some("person"), Some("project")),TypeDrift::Disjoint);assert_eq!(- classify_type_drift("event", "location"),+ classify_type_drift(Some("event"), Some("location")),TypeDrift::Disjoint);assert_eq!(- classify_type_drift("team", "organization"),+ classify_type_drift(Some("team"), Some("organization")),TypeDrift::Disjoint);}@@ -1750,13 +1783,14 @@ pub struct TypeCandidateSubject {pub id: Uuid,pub canonical_name: String,pub aliases: Vec<String>,- /// 现在挂着的类。名字里的"粗"是历史——抽取现在也可能直接给一个细类,- /// 而且可能给错(实测 `绍兴 → address`),所以这里也可能是要被**纠正**的那个- pub coarse_key: String,- pub coarse_id: Uuid,+ /// 现在挂着的类,**可能没有**(0009:没判出来就是 NULL)。名字里的"粗"+ /// 是历史——抽取现在也可能直接给一个细类,而且可能给错(实测+ /// `绍兴 → address`),所以这里也可能是要被**纠正**的那个+ pub coarse_key: Option<String>,+ pub coarse_id: Option<Uuid>,/// 现类的描述。裁决要判"现在这个类对不对",光看 key 不够——/// 导入本体的 key 常常自解释不了(`entry_point` 是什么?)- pub coarse_description: String,+ pub coarse_description: Option<String>,/// 抽取时模型自己报的类型名,**词表里没有**才会留在这儿pub proposed_type: Option<String>,/// 模型对它自己的说法,每个实体都有。@@ -1778,18 +1812,17 @@ pub struct TypeCandidateSubject {pub fact_count: i64,}-/// 值得送去精化类型的实体:挂在倾倒场类下的,或者模型报过一个词表外类型的。+/// 值得送去精化类型的实体:**还没有类的**,或者模型报过一个词表外类型的。////// 类型化得已经很具体的实体不动——重判一次只有下降风险,没有上升空间。pub async fn entities_for_type_resolution(pool: &PgPool,kb_id: Uuid,- dumping_ground: &str,limit: i64,) -> AppResult<Vec<TypeCandidateSubject>> {Ok(sqlx::query_as("SELECT e.id, e.canonical_name, e.aliases, t.key AS coarse_key, t.id AS coarse_id,- coalesce(t.description, '') AS coarse_description,+ t.description AS coarse_description,e.proposed_type, e.specific_type,-- 对方写**名字**,不写它的类型 key。-- 写 key 是自毁:查询里出现 organization / product / event 这些词,@@ -1820,19 +1853,18 @@ pub async fn entities_for_type_resolution(WHERE f3.kb_id = $1 AND f3.invalidated_at IS NULLAND (f3.subject_id = e.id OR f3.object_id = e.id)) AS fact_countFROM entities e- JOIN entity_types t ON t.id = e.type_id+ LEFT JOIN entity_types t ON t.id = e.type_idWHERE e.kb_id = $1 AND e.merged_into IS NULL- -- 值得看的三种:挂在倾倒场下的、模型报过词表外类型的、- -- **以及粗类本身还有子类的**。第三种是主力:抽取只认基类之后,- -- organization 下面挂着 167 个更具体的类,那才是导进来的本体+ -- 值得看的三种:**还没有类的**、模型报过词表外类型的、+ -- **以及现类本身还有子类的**。第三种是主力:抽取只认基类之后,+ -- organization 下面挂着一大批更具体的类,那才是导进来的本体-- 唯一的用武之地。只看前两种就把它整个漏掉了- AND (t.key = $2 OR e.proposed_type IS NOT NULL OR e.specific_type IS NOT NULL+ AND (e.type_id IS NULL OR e.proposed_type IS NOT NULL OR e.specific_type IS NOT NULLOR EXISTS (SELECT 1 FROM entity_type_parents p WHERE p.parent_id = t.id))ORDER BY fact_count DESC, e.created_at- LIMIT $3",+ LIMIT $2",).bind(kb_id)- .bind(dumping_ground).bind(limit).fetch_all(pool).await?)@@ -1891,7 +1923,6 @@ pub async fn nearest_typed_entities(pool: &PgPool,kb_id: Uuid,entity_id: Uuid,- dumping_ground: &str,limit: i64,) -> AppResult<Vec<(String, Uuid, String, f64, bool)>> {Ok(sqlx::query_as(@@ -1910,19 +1941,18 @@ pub async fn nearest_typed_entities(WHERE f2.kb_id = $1 AND (f2.subject_id = e.id OR f2.object_id = e.id)AND ev2.document_id IN (SELECT document_id FROM my_docs))AS same_document+ -- 内连接就是那道门:没判出类型的实体(type_id IS NULL)不是答案,+ -- 拿它当邻居的证据只会把「没判出来」传染开FROM entities eJOIN entity_types t ON t.id = e.type_idWHERE e.kb_id = $1 AND e.merged_into IS NULL AND e.id <> $2AND e.profile_embedding IS NOT NULLAND (SELECT v FROM me) IS NOT NULL- -- 倾倒场类不是答案,拿它当邻居的证据只会把没判出来的传染开- AND t.key <> $3ORDER BY e.profile_embedding <=> (SELECT v FROM me)- LIMIT $4",+ LIMIT $3",).bind(kb_id).bind(entity_id)- .bind(dumping_ground).bind(limit).fetch_all(pool).await?)@@ -1951,10 +1981,15 @@ pub async fn retype_entities(// 是改之前那个。直接 RETURNING type_id 拿到的就是刚写进去的那一个,// 撤销时等于把实体"放回"它现在的位置——账本看着满满当当,实际什么都撤不了。// 条件也一并放进 CTE:这一行还在、没被合并、且确实要变- let row: Option<(Uuid, String)> = sqlx::query_as(+ //+ // **`IS DISTINCT FROM` 而不是 `<>`**:0009 之后起点常常是 NULL,而+ // `NULL <> uuid` 是 NULL 不是 true——CTE 会空掉,UPDATE 一行不动,+ // 于是"给没有类的实体定类"这个最主要的场景整个变成空操作+ let row: Option<(Option<Uuid>, String)> = sqlx::query_as("WITH before AS (SELECT id, type_id, canonical_name FROM entities- WHERE id = $1 AND kb_id = $3 AND merged_into IS NULL AND type_id <> $2+ WHERE id = $1 AND kb_id = $3 AND merged_into IS NULL+ AND type_id IS DISTINCT FROM $2)UPDATE entities e SET type_id = $2, updated_at = now()FROM before@@ -2044,25 +2079,21 @@ mod same_type_tests {/// 结果是 `Sherlock Holmes` 与 `Holmes` 一对都进不了审阅队列。#[test]fn the_same_type_is_a_recall_candidate() {- for k in [- "person",- "location",- "organization",- "product",- "event",- "concept",- ] {+ for k in ["person", "location", "organization", "product", "event"] {assert_eq!(- classify_type_drift(k, k),+ classify_type_drift(Some(k), Some(k)),TypeDrift::Recall,"{k} 对 {k} 必须可召回");}// 自定义类型同样——这里判的是"两边是不是同一种东西",不是"它在不在白名单里"- assert_eq!(classify_type_drift("drug", "drug"), TypeDrift::Recall);+ assert_eq!(+ classify_type_drift(Some("drug"), Some("drug")),+ TypeDrift::Recall+ );// 跨类型的老结论一条都不变assert_eq!(- classify_type_drift("person", "organization"),+ classify_type_drift(Some("person"), Some("organization")),TypeDrift::Disjoint);}diff --git a/docs/decisions/0009-no-type-is-a-type.md b/docs/decisions/0009-no-type-is-a-type.mdnew file mode 100644index 00000000..9850030c--- /dev/null+++ b/docs/decisions/0009-no-type-is-a-type.md@@ -0,0 +1,161 @@+# 0009 · 「还没判出来」不该是一个类++- **状态**:已实施+- **成文**:2026-08-30(约定见 [README](README.md))+- **相关**:[0008](0008-ontology-packs-as-cold-start.md) 让真词表成为可选起点,本文把内置的那套拆掉;+ [0001](0001-ontology-import-and-governance.md) 的 IRI/key 分工是本文撞名论证的前提++> 本篇没有 benchmark 数字。它是一次归类的更正——`concept` 一直被当成本体的一部分,+> 而它其实是控制流的一部分。更正的依据是代码事实与一个撞名推演,都能重跑。++## 起点:内置九个类,一个都不该留++建库播种九个实体类(`graph.rs` 的 `DEFAULT_ENTITY_TYPES`):++```+person organization project metric dimension product event concept location+```++0008 论证过它们的通病——**零个带类型签名**,方向只能靠散文写。装了 schema.org 之后+它们更是多余:`Person` / `Organization` / `Product` / `Event` / `Project` 会按 key 撞名+被认领,等于内置那份从头到尾只是个占位。++**`location` 是反例中的反例**:schema.org 里它叫 `Place`,key 对不上,于是不被认领,+`City` / `AdministrativeArea` 挂到另建的 `place` 底下,跟 `location` 成了两棵树。+一个我们自己起的名字,把整条地理子树割断了。++`metric` / `dimension` 是语义层概念,schema.org 里确实没有——但代码里除测试外零引用,+它们只是**播种的默认值**,不是机制。++## `concept` 是控制流,不是词表++八个是词表内容,可以换、可以不同意、可以被 schema.org 顶替。`concept` 不是:++```rust+// extraction.rs+let concept_type = *type_ids.get("concept")+ .ok_or_else(|| anyhow!("Ontology missing the 'concept' type"))?;+```++它编码的是**「抽取器抽到了东西,但本体里没有对应的类」**。这个状态在任何本体下都存在,+跟装了 schema.org 还是 FIBO 无关。没有它,抽出来的实体只能被丢掉——而 0001 的 P1+整节就是在修「静默丢弃」。++它承担三件事:白名单外类型的落点(同时 `record_miss` 作为本体扩展信号)、+类型消解的取材范围(`entities_for_type_resolution(kb, DUMPING_GROUND, …)`)、+实体合并时的类型调和(兜底侧让位给具体侧)。++## 决定:不是给它改名,是让它不存在++初稿拟保留哨兵行、改 key 为 `_unclassified`。**否掉**,但这个方案值得记下来,+因为否掉它的理由才是本文的结论。++改名方案能成立,是因为 `key_from_iri` 永远产不出前导下划线——第一个字符若非字母数字,+`out.is_empty()` 为真,那个 `_` 不会被推入。实测:++```+skos:Concept -> "concept" ← 会撞+http://x#_Concept -> "concept" ← 前导下划线被剥掉+http://x#__unclass -> "unclassified"+```++所以 `_unclassified` 是导入够不到的命名空间。**这是算法保证,不是约定。**++而且不改名会出真事故:哨兵行**没有 IRI**,而导入逻辑是「占位者没有 IRI 就认领它」——+`skos:Concept` 会**接管哨兵**。于是所有"还没判出来"的实体一夜之间变成正经的+`skos:Concept`。不是撞名被跳过,是语义被静默改写。SKOS 不是冷门词表。++**但改名解决的只是撞名,解决不了泄漏。** 哨兵行必须从每一个消费者那里被过滤掉:+本体页、抽取提示词、候选列表、图谱图例、导出、统计。漏掉任何一处,它就作为一个正经的类+出现在那里,而且是静默出现。++这正是本仓库反复警告的那类缺陷。`ontology_index.rs` 开篇:++> **自愈,不挂钩子。**……漏挂一个钩子会悄悄烂掉,而对比原文不会。++`_unclassified` 是**用命名约定替代类型保证**:它管得住导入撞名,管不住某个 SELECT+忘了写 `WHERE key NOT LIKE '\_%'`。++**所以 `entities.type_id` 改为可空。** 「没有类型」就是没有类型,不用一行假类冒充。++初稿在这里写的是「NULL 忘不掉——SQL 与类型系统会当场让人知道」。**实现下来只对了一半,+记在这儿因为错的那一半更要紧。**++Rust 这边全中:每把一个字段改成 `Option`,编译器就把它的每一个消费点列出来,+一处不漏(`graph.rs` 的取节点语句、审核项两侧、裁决提示词、聊天里的实体清单)。+漏掉一个哨兵不会有任何提示,漏掉一个 `Option` 连编译都过不去。++**SQL 这边不会。** `NULL <> uuid` 求值为 NULL 而不是 true,于是这样的条件++```sql+AND type_id <> $2 -- 认领 / 改类都靠它挑出"要变的那些行"+```++**一行都选不中**,而且不报错。踩到两处,都在最主要的那条路上:`adopt_proposed_types`+(本体长出新类之后认领等着它的实体)与 `retype_entities`(类型消解裁决落库)。+两处的输入几乎全是 `type_id IS NULL` 的实体——功能会静默空转,测试也照样绿。+正解是 `IS DISTINCT FROM`。同一次实测(一个 `proposed_type='vehicle'` 的未分类实体):+`<>` 选中 0 行,`IS DISTINCT FROM` 选中 1 行。++所以这条决定的真实代价不是「90 处引用要改」,而是**26 处 SQL 里的每一个比较都要重看一遍**:+类型系统数得清 Rust 那 64 处,数不到 SQL 里去。++## 代价,逐条++**90 处引用,26 处在 SQL 字符串里。** 逐个过完了,实际改动 14 个文件、+`+316 / -369`——**删的比加的多**,因为内置那两张表(九个类与它们的中文措辞)+连同播种循环一起没了。++**两个唯一索引带 `type_id` 前缀:**++```sql+CREATE UNIQUE INDEX … ON entities (kb_id, type_id, lower(canonical_name))+ WHERE merged_into IS NULL;+```++Postgres 里 **NULL 不等于 NULL**,所以未分类的同名实体不会被它拦住——两个都没类型的+「张三」可以并存。++**这是要的行为,不是缺陷**:该索引本来的意图就是「同类同名允许重复」(0001 P0 论证过+两个张伟必须能分开存放,宁分勿合)。未分类时我们对它们是不是同一个东西**知道得更少**,+更没有理由合并。写在这里是因为半年后有人看到「未分类的同名实体可以重复」会以为是 bug。++**`CONFUSABLE_TYPE_KEYS` 不受影响。** 它按 key 查(`["organization","project","product"]`),+而这些 key 装了 schema.org 之后仍然存在——只是来源从内置播种变成了词表导入。+没装包的库里它们不存在,于是那一档永不命中,所有跨类型同名判 `Disjoint`(完全分开)。+**那是变严不是变松**,不会造成错误合并。++它的正解仍然是注释里写的那条——等 `disjointWith` 落库后改从本体读,即 0008 的 R0 第三阶段。+本文不动它。++## 空白库++删光之后,不选任何包的库是**真的空**:抽出来的实体 `type_id` 为 NULL,事实照常落库,+证据链照常。之后装一个包再跑一次类型消解,实体会被重新分配——+`entities_for_type_resolution` 本来就是取「落在兜底上的」,改成取 `type_id IS NULL` 即可。++**所以"先建库后建模"是受支持的路径,不是将就。**++配套:schema.org 在建库对话框里默认勾选,可反选。这在 45 秒的时候不成立,+在 0.42 秒的时候成立(导入改批量插入之后的实测)。++## 落地时定下的两件事++**图谱怎么画它。** 取节点的语句从 `JOIN entity_types` 改成 `LEFT JOIN`——内连接会让+未分类实体**整个从图上消失**,事实还在库里却查无此人,是最难发现的一种数据丢失。+`key` 与 `label` 留 NULL,**颜色和形状给缺省值**(灰色圆点):前者是身份,没有就该说没有;+后者是画布必须拿到的东西,编不出来就没法渲染。同一处理也用在审核项两侧。++**给它定类不算「跨轴」。** 类型消解把「选中的类不在现类子树里」判为重新分类而非精化,+一律进人工。未分类实体身上**没有一个抽取判断要被推翻**,第一次定类是补齐;+若也判跨轴,删掉哨兵的代价就是每个实体都要人看一眼,整条自动化直接废掉。+配套地 `entity_retypes.from_type_id` 改为可空——最常见的一次改类正是「从没有类到有类」,+而那张表是撤销的唯一依据;非空的话第一次定类就写不进账,那批改动不可撤。++## 开放问题++- **未分类实体的消解**:画像里没有类型这一维,`classify_type_drift` 少一个判据。+ 两个都没类型的同名实体,今天按 `Recall` 走画像相似度——够不够,没测过。+- **`metric` / `dimension` 的去处**:语义层要用,而没有任何公开词表提供它们。+ 是让用户自己建,还是我们出一个「Utopia 语义层」包?后者会把内置本体从代码搬到包里,+ 性质完全不同——那是可选、带 IRI、可被替换的。diff --git a/migrations/0047_no_type_is_a_type.sql b/migrations/0047_no_type_is_a_type.sqlnew file mode 100644index 00000000..012cf983--- /dev/null+++ b/migrations/0047_no_type_is_a_type.sql@@ -0,0 +1,43 @@+-- 「还没判出来」不再是一个类,见 docs/decisions/0009。+--+-- 此前它是一行叫 concept 的哨兵。哨兵有名字,有名字就会撞——SKOS 的+-- skos:Concept 派生出的 key 正是 concept,而哨兵没有 IRI,导入逻辑+-- 「占位者没有 IRI 就认领它」会让它接管哨兵:所有未分类的实体一夜之间+-- 变成正经的 skos:Concept。不是撞名被跳过,是语义被静默改写。+--+-- NULL 没有名字,撞不着;也忘不掉——漏过滤一个哨兵不会有任何提示,+-- 漏处理一个 NULL 会当场报出来。++ALTER TABLE entities ALTER COLUMN type_id DROP NOT NULL;++-- 挂在内置类上的实体一律回到未分类。+--+-- **不做"有实体就保留那个类"的挽救**:仓库至今没有 release,不存在要照顾的+-- 生产部署,而留一半内置类会让迁完的状态不确定——测试时分不清某个 organization+-- 是内置残留还是 schema.org 导进来的。宁可状态干净。+--+-- 顺序要紧:type_id 是 ON DELETE RESTRICT,不先解引用就删不掉类型行。+UPDATE entities SET type_id = NULL+WHERE type_id IN (SELECT id FROM entity_types WHERE builtin);++-- 关联表同理:属性的 domain 指向内置类时,那条关联也一并去掉。+-- 属性本身留着——它可能还挂在别的类上,而且描述与 IRI 都是有价值的+DELETE FROM relation_type_domains WHERE entity_type_id IN (SELECT id FROM entity_types WHERE builtin);+DELETE FROM relation_type_ranges WHERE entity_type_id IN (SELECT id FROM entity_types WHERE builtin);+DELETE FROM entity_type_parents+WHERE parent_id IN (SELECT id FROM entity_types WHERE builtin)+ OR child_id IN (SELECT id FROM entity_types WHERE builtin);++DELETE FROM entity_types WHERE builtin;++-- 唯一索引里 type_id 现在可能是 NULL,而 Postgres 里 NULL <> NULL——+-- 两个都没类型的同名实体不会被它拦住,可以并存。+--+-- **这是要的行为**:该索引的意图是「同类同名允许重复」(见 0001 P0 的两个张伟)。+-- 未分类时我们对它们是不是同一个东西知道得更少,更没有理由合并。+-- 写在这里是因为半年后看到「未分类的同名实体可以重复」会像个 bug。++-- 改类账本的起点也可能为空:类型消解现在最常见的动作正是「从没有类到有类」,+-- 而 entity_retypes 是它的撤销依据。这一列非空的话,第一次赋类就写不进账,+-- 于是那批改动不可撤——比不记账更糟+ALTER TABLE entity_retypes ALTER COLUMN from_type_id DROP NOT NULL;diff --git a/web/data/files/dbf6e5cc9155834907dece9b23e3bbc80244fcb22ce8162ef6a17f1f99f2ec94 b/web/data/files/dbf6e5cc9155834907dece9b23e3bbc80244fcb22ce8162ef6a17f1f99f2ec94deleted file mode 100644index f6a0993f..00000000--- a/web/data/files/dbf6e5cc9155834907dece9b23e3bbc80244fcb22ce8162ef6a17f1f99f2ec94+++ /dev/null@@ -1,20 +0,0 @@-# 凤凰项目管理制度--## 项目背景--凤凰项目是公司 2024 年启动的核心数字化转型项目,目标是在两年内完成全部业务系统的云原生改造。--## 负责人安排--凤凰项目自 2023 年 1 月起由张三担任项目负责人。2024 年 7 月起,项目负责人调整为李四,张三转任技术顾问。--## 预算与周期--项目总预算为 1200 万元,分三期执行:-- 第一期(2024 年上半年):基础设施迁移,预算 400 万-- 第二期(2024 年下半年):核心业务系统改造,预算 500 万-- 第三期(2025 年):数据平台建设,预算 300 万--## 汇报机制--项目负责人每月向技术委员会汇报进展,每季度向董事会提交书面报告。重大风险事项须在 48 小时内上报。diff --git a/web/data/files/ff94ce5e2550340460a922bdaea59ba05f82b716540b5104ed89771bbb1689df b/web/data/files/ff94ce5e2550340460a922bdaea59ba05f82b716540b5104ed89771bbb1689dfdeleted file mode 100644index 61437f79..00000000--- a/web/data/files/ff94ce5e2550340460a922bdaea59ba05f82b716540b5104ed89771bbb1689df+++ /dev/null@@ -1,3 +0,0 @@-# Phoenix Handbook--凤凰项目由张三负责。 Budget is 12 million CNY.diff --git a/web/data/index/.managed.json b/web/data/index/.managed.jsondeleted file mode 100644index 2b8079a5..00000000--- a/web/data/index/.managed.json+++ /dev/null@@ -1 +0,0 @@-["c7717e57324544a1a198b5ffa16ef125.term","762d0901b09f48c781c83b41dd9e9a21.idx","c7717e57324544a1a198b5ffa16ef125.idx","8cac7b9961c2420590015c1f94a74e9b.fieldnorm","c7717e57324544a1a198b5ffa16ef125.store","00684c79ed564b48b38b3e50d60e83f1.fieldnorm","8cac7b9961c2420590015c1f94a74e9b.idx","762d0901b09f48c781c83b41dd9e9a21.term","8cac7b9961c2420590015c1f94a74e9b.store","00684c79ed564b48b38b3e50d60e83f1.pos","762d0901b09f48c781c83b41dd9e9a21.pos","00684c79ed564b48b38b3e50d60e83f1.idx","meta.json","8cac7b9961c2420590015c1f94a74e9b.pos","c7717e57324544a1a198b5ffa16ef125.fieldnorm","c7717e57324544a1a198b5ffa16ef125.fast","8cac7b9961c2420590015c1f94a74e9b.term","762d0901b09f48c781c83b41dd9e9a21.store","c7717e57324544a1a198b5ffa16ef125.pos","00684c79ed564b48b38b3e50d60e83f1.fast","8cac7b9961c2420590015c1f94a74e9b.fast","762d0901b09f48c781c83b41dd9e9a21.fieldnorm","00684c79ed564b48b38b3e50d60e83f1.store","00684c79ed564b48b38b3e50d60e83f1.term","762d0901b09f48c781c83b41dd9e9a21.fast"]diff --git a/web/data/index/.tantivy-meta.lock b/web/data/index/.tantivy-meta.lockdeleted file mode 100644index e69de29b..00000000diff --git a/web/data/index/.tantivy-writer.lock b/web/data/index/.tantivy-writer.lockdeleted file mode 100644index e69de29b..00000000diff --git a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.fast b/web/data/index/00684c79ed564b48b38b3e50d60e83f1.fastdeleted file mode 100644index e93b75f9..00000000Binary files a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.fast and /dev/null differdiff --git a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.fieldnorm b/web/data/index/00684c79ed564b48b38b3e50d60e83f1.fieldnormdeleted file mode 100644index ae8c5f41..00000000Binary files a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.fieldnorm and /dev/null differdiff --git a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.idx b/web/data/index/00684c79ed564b48b38b3e50d60e83f1.idxdeleted file mode 100644index 9678170d..00000000Binary files a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.idx and /dev/null differdiff --git a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.pos b/web/data/index/00684c79ed564b48b38b3e50d60e83f1.posdeleted file mode 100644index fab6d450..00000000Binary files a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.pos and /dev/null differdiff --git a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.store b/web/data/index/00684c79ed564b48b38b3e50d60e83f1.storedeleted file mode 100644index cb995d6a..00000000Binary files a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.store and /dev/null differdiff --git a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.term b/web/data/index/00684c79ed564b48b38b3e50d60e83f1.termdeleted file mode 100644index f610e6b5..00000000Binary files a/web/data/index/00684c79ed564b48b38b3e50d60e83f1.term and /dev/null differdiff --git a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.fast b/web/data/index/762d0901b09f48c781c83b41dd9e9a21.fastdeleted file mode 100644index e93b75f9..00000000Binary files a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.fast and /dev/null differdiff --git a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.fieldnorm b/web/data/index/762d0901b09f48c781c83b41dd9e9a21.fieldnormdeleted file mode 100644index ae8c5f41..00000000Binary files a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.fieldnorm and /dev/null differdiff --git a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.idx b/web/data/index/762d0901b09f48c781c83b41dd9e9a21.idxdeleted file mode 100644index 9678170d..00000000Binary files a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.idx and /dev/null differdiff --git a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.pos b/web/data/index/762d0901b09f48c781c83b41dd9e9a21.posdeleted file mode 100644index fab6d450..00000000Binary files a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.pos and /dev/null differdiff --git a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.store b/web/data/index/762d0901b09f48c781c83b41dd9e9a21.storedeleted file mode 100644index 6196e7de..00000000Binary files a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.store and /dev/null differdiff --git a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.term b/web/data/index/762d0901b09f48c781c83b41dd9e9a21.termdeleted file mode 100644index 9f59ac01..00000000Binary files a/web/data/index/762d0901b09f48c781c83b41dd9e9a21.term and /dev/null differdiff --git a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.fast b/web/data/index/8cac7b9961c2420590015c1f94a74e9b.fastdeleted file mode 100644index e93b75f9..00000000Binary files a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.fast and /dev/null differdiff --git a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.fieldnorm b/web/data/index/8cac7b9961c2420590015c1f94a74e9b.fieldnormdeleted file mode 100644index ae8c5f41..00000000Binary files a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.fieldnorm and /dev/null differdiff --git a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.idx b/web/data/index/8cac7b9961c2420590015c1f94a74e9b.idxdeleted file mode 100644index 9678170d..00000000Binary files a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.idx and /dev/null differdiff --git a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.pos b/web/data/index/8cac7b9961c2420590015c1f94a74e9b.posdeleted file mode 100644index fab6d450..00000000Binary files a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.pos and /dev/null differdiff --git a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.store b/web/data/index/8cac7b9961c2420590015c1f94a74e9b.storedeleted file mode 100644index fc0264ad..00000000Binary files a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.store and /dev/null differdiff --git a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.term b/web/data/index/8cac7b9961c2420590015c1f94a74e9b.termdeleted file mode 100644index d6e016dc..00000000Binary files a/web/data/index/8cac7b9961c2420590015c1f94a74e9b.term and /dev/null differdiff --git a/web/data/index/c7717e57324544a1a198b5ffa16ef125.fast b/web/data/index/c7717e57324544a1a198b5ffa16ef125.fastdeleted file mode 100644index e93b75f9..00000000Binary files a/web/data/index/c7717e57324544a1a198b5ffa16ef125.fast and /dev/null differdiff --git a/web/data/index/c7717e57324544a1a198b5ffa16ef125.fieldnorm b/web/data/index/c7717e57324544a1a198b5ffa16ef125.fieldnormdeleted file mode 100644index 0b942bf9..00000000Binary files a/web/data/index/c7717e57324544a1a198b5ffa16ef125.fieldnorm and /dev/null differdiff --git a/web/data/index/c7717e57324544a1a198b5ffa16ef125.idx b/web/data/index/c7717e57324544a1a198b5ffa16ef125.idxdeleted file mode 100644index d564ab52..00000000Binary files a/web/data/index/c7717e57324544a1a198b5ffa16ef125.idx and /dev/null differdiff --git a/web/data/index/c7717e57324544a1a198b5ffa16ef125.pos b/web/data/index/c7717e57324544a1a198b5ffa16ef125.posdeleted file mode 100644index 5727e04f..00000000Binary files a/web/data/index/c7717e57324544a1a198b5ffa16ef125.pos and /dev/null differdiff --git a/web/data/index/c7717e57324544a1a198b5ffa16ef125.store b/web/data/index/c7717e57324544a1a198b5ffa16ef125.storedeleted file mode 100644index a75f28ce..00000000Binary files a/web/data/index/c7717e57324544a1a198b5ffa16ef125.store and /dev/null differdiff --git a/web/data/index/c7717e57324544a1a198b5ffa16ef125.term b/web/data/index/c7717e57324544a1a198b5ffa16ef125.termdeleted file mode 100644index 4334f058..00000000Binary files a/web/data/index/c7717e57324544a1a198b5ffa16ef125.term and /dev/null differdiff --git a/web/data/index/meta.json b/web/data/index/meta.jsondeleted file mode 100644index cc1179c4..00000000--- a/web/data/index/meta.json+++ /dev/null@@ -1,83 +0,0 @@-{- "index_settings": {- "docstore_compression": "lz4",- "docstore_blocksize": 16384- },- "segments": [- {- "segment_id": "8cac7b99-61c2-4205-9001-5c1f94a74e9b",- "max_doc": 1,- "deletes": null- },- {- "segment_id": "762d0901-b09f-48c7-81c8-3b41dd9e9a21",- "max_doc": 1,- "deletes": null- },- {- "segment_id": "00684c79-ed56-4b48-b38b-3e50d60e83f1",- "max_doc": 1,- "deletes": null- },- {- "segment_id": "c7717e57-3245-44a1-a198-b5ffa16ef125",- "max_doc": 1,- "deletes": null- }- ],- "schema": [- {- "name": "chunk_id",- "type": "text",- "options": {- "indexing": {- "record": "basic",- "fieldnorms": true,- "tokenizer": "raw"- },- "stored": true,- "fast": false- }- },- {- "name": "kb_id",- "type": "text",- "options": {- "indexing": {- "record": "basic",- "fieldnorms": true,- "tokenizer": "raw"- },- "stored": false,- "fast": false- }- },- {- "name": "document_id",- "type": "text",- "options": {- "indexing": {- "record": "basic",- "fieldnorms": true,- "tokenizer": "raw"- },- "stored": false,- "fast": false- }- },- {- "name": "text",- "type": "text",- "options": {- "indexing": {- "record": "position",- "fieldnorms": true,- "tokenizer": "jieba"- },- "stored": false,- "fast": false- }- }- ],- "opstamp": 16-}diff --git a/web/src/api.ts b/web/src/api.tsindex fd2f22d7..37b4db5f 100644--- a/web/src/api.ts+++ b/web/src/api.ts@@ -213,8 +213,9 @@ export interface DataSourceView {export interface GraphNode {id: string;name: string;- type_key: string;- type_label: string;+ // 没判出类型时为 null(0009)+ type_key: string | null;+ type_label: string | null;color: string;shape: "circle" | "square";degree: number;@@ -248,7 +249,8 @@ export interface ChunkFact {export interface ReviewSide {id: string;name: string;- type_label: string;+ // 没判出类型时为 null(0009)+ type_label: string | null;color: string;disambiguator: string | null;degree: number;diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.tsindex 6456b06d..cd4199c6 100644--- a/web/src/i18n/en.ts+++ b/web/src/i18n/en.ts@@ -504,6 +504,8 @@ export const en = {cancel: "Cancel",},graph: {+ // 还没判出类型的实体(0009)。不是一个类,是"这一格还空着"+ untyped: "Untyped",zoomIn: "Zoom in",zoomOut: "Zoom out",fitView: "Fit view",diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.tsindex 96ac79a7..f6bf4e9b 100644--- a/web/src/i18n/zh.ts+++ b/web/src/i18n/zh.ts@@ -472,6 +472,7 @@ export const zh: Strings = {cancel: "取消",},graph: {+ untyped: "未分类",zoomIn: "放大",zoomOut: "缩小",fitView: "适应视图",diff --git a/web/src/pages/Graph.tsx b/web/src/pages/Graph.tsxindex 05afc514..4630f2d1 100644--- a/web/src/pages/Graph.tsx+++ b/web/src/pages/Graph.tsx@@ -322,8 +322,15 @@ export function Graph() {const types = useMemo(() => {const map = new Map<string, { label: string; color: string; shape: string }>();for (const n of data.data?.nodes ?? []) {- if (!map.has(n.type_key))- map.set(n.type_key, { label: n.type_label, color: n.color, shape: n.shape });+ // 没判出类型的归到空 key 一档(0009)。真实 key 由 IRI 派生,不可能为空,+ // 所以它撞不着任何一个类;标签走 i18n,别把 null 画到图例上+ const key = n.type_key ?? "";+ if (!map.has(key))+ map.set(key, {+ label: n.type_label ?? S.graph.untyped,+ color: n.color,+ shape: n.shape,+ });}return [...map.entries()];}, [data.data]);@@ -400,8 +407,8 @@ export function Graph() {borderColor: mix(NODE_BORDER_BASE, n.color, 0.3),ringColor: TRANSPARENT,typeColor: n.color,- typeLabel: n.type_label,- typeKey: n.type_key,+ typeLabel: n.type_label ?? S.graph.untyped,+ typeKey: n.type_key ?? "",type: n.shape === "square" ? "square" : "shell",size: 5 + Math.min(8, Math.sqrt(Number(n.degree)) * 1.6),});@@ -1287,7 +1294,8 @@ function EntityPanel({{e.disambiguator && e.disambiguator !== e.type_label? `${e.disambiguator} · `: ""}- {e.type_label} · {detail.data?.facts.length ?? 0} {S.graph.facts}+ {e.type_label ?? S.graph.untyped} · {detail.data?.facts.length ?? 0}{" "}+ {S.graph.facts}</div></>)}@@ -1384,7 +1392,7 @@ function EntityPanel({onClick={() => onNavigate(p.id)}className="text-[11px] px-1.5 py-0.5 rounded bg-white/[0.06] text-neutral-300 hover:bg-white/10">- {p.type_label}+ {p.type_label ?? S.graph.untyped}{p.disambiguator && p.disambiguator !== p.type_label? ` · ${p.disambiguator}`: ""}diff --git a/web/src/pages/Review.tsx b/web/src/pages/Review.tsxindex 449361fe..f592acf2 100644--- a/web/src/pages/Review.tsx+++ b/web/src/pages/Review.tsx@@ -51,7 +51,7 @@ function SideCard({ side }: { side: ReviewSide }) {)}</div><div className="text-xs text-neutral-500 mb-2">- {side.type_label} · {S.review.factsCount(side.degree)}+ {side.type_label ?? S.graph.untyped} · {S.review.factsCount(side.degree)}</div>{side.top_facts.length > 0 ? (<ul className="space-y-1">diff --git a/web/src/pages/Settings.tsx b/web/src/pages/Settings.tsxindex 58dab2fe..fae22804 100644--- a/web/src/pages/Settings.tsx+++ b/web/src/pages/Settings.tsx@@ -357,7 +357,10 @@ function NewKbModal({const [name, setName] = useState("");const [desc, setDesc] = useState("");const [restricted, setRestricted] = useState(true);- const [packs, setPacks] = useState<string[]>([]);+ // schema.org 默认勾选,可反选(0009)。删掉内置类之后不选任何包的库是真的空,+ // 而空库仍然能用——但绝大多数人要的是一个已经能认出人、组织、产品的起点。+ // 一秒装完(0008 的批量插入),所以默认装得起+ const [packs, setPacks] = useState<string[]>(["schema-org"]);const available = useQuery({queryKey: ["ontologyPacks"],