World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
A Chinese name does not stop the queue, and a stated figure is written down (#523)
WaylandYang017896b6ab10
diff --git a/crates/utopia-extract/src/lib.rs b/crates/utopia-extract/src/lib.rsindex de1fc859..f0af3d12 100644--- a/crates/utopia-extract/src/lib.rs+++ b/crates/utopia-extract/src/lib.rs@@ -281,6 +281,27 @@ pub fn build_messages(8. If no listed relation fits, do not force the nearest one — write the predicate the \text itself uses, in snake_case (e.g. \"available_on\", \"runs_on\"). A relation \named after the text is worth more than a listed one that says something false.\n\+ 8a. The same holds for a literal the text states outright — an amount, a share count, \+ a percentage, a capacity, a date, a job title, a ticker. Write it as a fact with \+ \"value\" and no \"object\": {{\"subject\":\"NVIDIA\",\"subject_ref\":\"e1\",\+ \"predicate\":\"purchase_price\",\"value\":\"$11.9 billion\",\"confidence\":0.9,\+ \"quote\":\"...\"}}. Name the predicate after the text when no listed attribute \+ fits — \"purchase_price\", \"job_title\", \"generation_capacity\", \"record_date\". \+ Attach it to the entity the text attaches it to, and keep the literal as written, \+ units and all. **A stated figure left out is the loss that costs most**: the reader \+ came for those numbers, and no later step can recover one that was never written \+ down.\n\+ 8b. A **listed** relation also takes \"value\" when what the text gives is a \+ string rather than another entity — a job title, a designation, a ticker, a \+ model number. Never invent an entity for a string. And when the text introduces \+ someone by their role — \"X, founder and CEO of Y\", \"Z, co-CEO of W\" — write \+ both facts: the tie to the organization, and the role itself as a value on the \+ person. The tie alone says they are connected; the role is what the sentence \+ was actually telling you.\n\+ 8c. A list of named parties is a list of facts — one per name. \"partners \+ including A, B, C and D\" is four facts, not one; \"advisors A and B\" is two. \+ Do not collapse an enumeration into a summary or into its first member. \+ The same applies to the entities: each named party is its own entity.\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 \"thing\" or \"creative_work\" merely because \diff --git a/crates/utopia-ingest/src/html.rs b/crates/utopia-ingest/src/html.rsindex 9a004965..2a9895f0 100644--- a/crates/utopia-ingest/src/html.rs+++ b/crates/utopia-ingest/src/html.rs@@ -1,4 +1,73 @@//! Canonical HTML conversion shared by file, URL and feed ingestion.+#[cfg(test)]+mod table_tests {+ use super::{markdown_from_html, promote_first_row_headers};++ #[test]+ fn a_table_without_headers_still_keeps_its_rows() {+ let html = "<table><tr><td>Revenue</td><td>Q2 FY27</td><td>Q1 FY27</td></tr>\+ <tr><td>total</td><td>$96,221</td><td>$81,615</td></tr></table>";+ let md = markdown_from_html(html).expect("converts");+ // 行列关系还在:同一行的三格在同一行文本里+ let row = md+ .lines()+ .find(|l| l.contains("96,221"))+ .expect("the numbers survive");+ assert!(row.contains("81,615"), "同一行的两个数应当在一行里: {md}");+ assert!(row.contains("total"), "行标签应当与它的数在一行: {md}");+ }++ #[test]+ fn empty_spacer_columns_do_not_survive() {+ let html = "<table><tr><td>Revenue</td><td></td><td>$96,221</td><td></td></tr>\+ <tr><td>Margin</td><td></td><td>75.0</td><td></td></tr></table>";+ let md = markdown_from_html(html).expect("converts");+ let row = md+ .lines()+ .find(|l| l.contains("96,221"))+ .expect("row survives");+ assert!(!row.contains("| |"), "空列应当被砍掉: {row}");+ assert!(row.contains("Revenue"), "有内容的列一个不能少: {row}");+ }++ #[test]+ fn a_blank_header_row_gives_way_to_the_real_one() {+ let md = super::prune_empty_table_columns(+ "| | |\n| --- | --- |\n| a. Tench Coxe | |\n| shares For | 15,411 |",+ );+ let first = md.lines().next().expect("a line");+ assert!(first.contains("Tench Coxe"), "表头该是真正的抬头: {md}");+ assert!(md.contains("15,411"), "行不能丢: {md}");+ }++ #[test]+ fn a_column_with_any_content_is_kept() {+ let md = super::prune_empty_table_columns("| a | | c |\n| --- | --- | --- |\n| | b | |");+ assert!(md.contains("| a | | c |") || md.contains("a"), "{md}");+ assert!(md.contains("b"), "有内容的列不能砍: {md}");+ }++ #[test]+ fn a_table_that_already_has_headers_is_untouched() {+ let html = "<table><thead><tr><th>a</th></tr></thead><tr><td>1</td></tr></table>";+ assert_eq!(promote_first_row_headers(html), html);+ }++ #[test]+ fn a_nested_table_does_not_promote_the_outer_row() {+ // 内层先被处理;外层因此看得见 <th>,跳过——不猜哪一行属于谁+ let html = "<table><tr><td><table><tr><td>inner</td></tr></table></td></tr></table>";+ let out = promote_first_row_headers(html);+ assert_eq!(out.to_ascii_lowercase().matches("<th").count(), 1, "{out}");+ }++ #[test]+ fn text_outside_tables_is_left_alone() {+ let html = "<p>plain</p>";+ assert_eq!(promote_first_row_headers(html), html);+ }+}+#[cfg(test)]mod evidence_tests {use super::*;@@ -235,7 +304,191 @@ pub fn looks_like_challenge_shell(markdown: &str) -> bool {&& !has_substantive_prose(markdown)}+/// 没有 `<th>` 的表格,把第一行的 `<td>` 提成 `<th>`。+///+/// **理由是一整类文档在解析这一步就把行列关系丢了。** htmd 的表格处理器要求+/// 表里有显式表头(`<th>` 或 `<thead>`),否则整张退回逐格摊平——一格一行。+/// 而 SEC 的 XBRL 报表一个都没有:实测 NVIDIA 那份财报 11 张表、那份投票结果+/// 8-K 21 张表,`<th>` 计数都是 0。摊平之后模型看到的是一列孤立标签跟一列+/// 孤立数字,只能按顺序猜哪个数配哪一列,于是抽出 `NVIDIA net_worth Net income`+/// 这种边,十位董事的四类票数也全部退化成分不出类别的裸数字。+///+/// 第一行提成表头是这类表格的实际语义("Q2 FY27 | Q1 FY27 | Q2 FY26"),+/// 而且**判据很窄**:整张表一个 `<th>`/`<thead>` 都没有时才动。已经有表头的+/// 表格一个字不改。+///+/// 嵌套表格按**从内到外**处理(`</table>` 出现的顺序天然如此):内层改过之后+/// 外层就带着 `<th>` 了,于是外层跳过——宁可少改一张,不去猜哪一行属于谁。+fn promote_first_row_headers(html: &str) -> String {+ let lower = html.to_ascii_lowercase();+ let mut out = html.to_string();+ // (开标签结束位置, 表格结束位置),按闭合顺序 = 从内到外+ let mut opens: Vec<usize> = Vec::new();+ let mut spans: Vec<(usize, usize)> = Vec::new();+ let mut i = 0usize;+ while i < lower.len() {+ let next_open = lower[i..].find("<table").map(|x| i + x);+ let next_close = lower[i..].find("</table").map(|x| i + x);+ match (next_open, next_close) {+ (Some(o), Some(c)) if o < c => {+ opens.push(o);+ i = o + 6;+ }+ (_, Some(c)) => {+ if let Some(o) = opens.pop() {+ spans.push((o, c));+ }+ i = c + 7;+ }+ (Some(o), None) => {+ opens.push(o);+ i = o + 6;+ }+ (None, None) => break,+ }+ }+ // 位置会随改写移动,所以从后往前改+ spans.sort_by_key(|(o, _)| std::cmp::Reverse(*o));+ for (open, close) in spans {+ let seg = &out[open..close.min(out.len())];+ let seg_lower = seg.to_ascii_lowercase();+ if seg_lower.contains("<th") || seg_lower.contains("<thead") {+ continue;+ }+ let Some(tr) = seg_lower.find("<tr") else {+ continue;+ };+ let Some(tr_end) = seg_lower[tr..].find("</tr").map(|x| tr + x) else {+ continue;+ };+ let row = &seg[tr..tr_end];+ if !row.to_ascii_lowercase().contains("<td") {+ continue;+ }+ let rewritten = replace_td_with_th(row);+ out.replace_range(open + tr..open + tr_end, &rewritten);+ }+ out+}++/// 只换标签名,属性原样留着。+fn replace_td_with_th(row: &str) -> String {+ let mut out = String::with_capacity(row.len());+ let lower = row.to_ascii_lowercase();+ let mut i = 0usize;+ while i < row.len() {+ if lower[i..].starts_with("<td") {+ out.push_str("<th");+ i += 3;+ } else if lower[i..].starts_with("</td") {+ out.push_str("</th");+ i += 4;+ } else {+ let ch = row[i..].chars().next().expect("char boundary");+ out.push(ch);+ i += ch.len_utf8();+ }+ }+ out+}++/// 表格里整列都空的,砍掉;对齐用的空格也不留。+///+/// **不砍的代价是三倍。** 排版用的空单元格(XBRL 的缩进列、货币符号列)在+/// HTML 里不占地方,转成 markdown 管道表之后每一行都要为它们写一个 `|` 和+/// 一片对齐空格。实测那份财报:24 块 2.6 万字符 → 78 块 9.2 万字符,多出来的+/// 全是 `| | | |`。分块数进了抽取的成本,一列空格不值这个钱。+///+/// 判据是「这一列在**每一行**都空」,所以有内容的列一个不动;分隔行不参与判断+/// (它本来就只有横线),但跟着一起砍列。+fn prune_empty_table_columns(markdown: &str) -> String {+ let is_row = |l: &str| {+ let t = l.trim();+ t.starts_with('|') && t.ends_with('|') && t.len() > 1+ };+ let cells = |l: &str| -> Vec<String> {+ let t = l.trim();+ t[1..t.len() - 1]+ .split('|')+ .map(|c| c.trim().to_string())+ .collect()+ };+ let is_sep = |c: &[String]| {+ !c.is_empty()+ && c.iter()+ .all(|x| !x.is_empty() && x.chars().all(|ch| ch == '-' || ch == ':'))+ };++ let lines: Vec<&str> = markdown.split('\n').collect();+ let mut out: Vec<String> = Vec::with_capacity(lines.len());+ let mut i = 0usize;+ while i < lines.len() {+ if !is_row(lines[i]) {+ out.push(lines[i].to_string());+ i += 1;+ continue;+ }+ let start = i;+ while i < lines.len() && is_row(lines[i]) {+ i += 1;+ }+ let rows: Vec<Vec<String>> = lines[start..i].iter().map(|l| cells(l)).collect();+ let width = rows.iter().map(Vec::len).max().unwrap_or(0);+ let keep: Vec<bool> = (0..width)+ .map(|c| {+ rows.iter()+ .any(|r| !is_sep(r) && r.get(c).is_some_and(|x| !x.is_empty()))+ })+ .collect();+ // 一列都不剩就原样留着,不去猜+ if !keep.iter().any(|k| *k) {+ out.extend(lines[start..i].iter().map(|l| l.to_string()));+ continue;+ }+ let render = |r: &Vec<String>| {+ let sep = is_sep(r);+ let kept: Vec<String> = (0..width)+ .filter(|c| keep[*c])+ .map(|c| {+ let v = r.get(c).cloned().unwrap_or_default();+ if sep && v.is_empty() {+ "---".to_string()+ } else {+ v+ }+ })+ .collect();+ format!("| {} |", kept.join(" | "))+ };+ // **表头整行是空的就让位。** 提上来的第一行有时只是排版用的占位行+ // (SEC 那份投票结果 8-K 的每张表都这样),留着它,模型看到的是+ // 一张列名全空的表——没有信息,还占着「表头」这个位置。下一行顶上,+ // 表的第一行才是它真正的抬头("a. Tench Coxe")。+ let head_blank = rows.first().is_some_and(|r| {+ (0..width)+ .filter(|c| keep[*c])+ .all(|c| r.get(c).is_none_or(String::is_empty))+ });+ let body_start = if head_blank && rows.len() > 2 { 2 } else { 0 };+ if body_start == 2 {+ out.push(render(&rows[2]));+ if let Some(sep) = rows.get(1) {+ out.push(render(sep));+ }+ for r in &rows[3..] {+ out.push(render(r));+ }+ } else {+ for r in &rows {+ out.push(render(r));+ }+ }+ }+ out.join("\n")+}+fn markdown_from_html(html: &str) -> Result<String, HtmlError> {+ let html = &promote_first_row_headers(html);let markdown = htmd::HtmlToMarkdown::builder().skip_tags(vec!["script", "style", "iframe", "object", "embed", "img", "svg", "math",@@ -252,7 +505,7 @@ fn markdown_from_html(html: &str) -> Result<String, HtmlError> {{return Err(HtmlError::Interstitial);}- normalize_markdown(&markdown)+ normalize_markdown(&prune_empty_table_columns(&markdown))}/// Normalize direct Markdown with the same link policy as HTML conversion.diff --git a/crates/utopia-server/src/adjudication.rs b/crates/utopia-server/src/adjudication.rsindex 14644a18..9980c491 100644--- a/crates/utopia-server/src/adjudication.rs+++ b/crates/utopia-server/src/adjudication.rs@@ -8,6 +8,7 @@ use crate::llm_util;use crate::state::AppState;use sha2::{Digest, Sha256};use std::collections::HashMap;+use std::sync::{Arc, LazyLock, Mutex};use utopia_core::models::ReviewItem;use utopia_core::AppError;use utopia_store::governance as gov;@@ -114,7 +115,31 @@ async fn record_look(Ok(())}+/// 同一个库的裁决一次只跑一个(与 `ontology_index::PER_KB` 同一套理由)。+///+/// 入队去重只挡得住「还排着队的」;一批文档陆续抽完时,后一个入队时前一个+/// 已经是 `running`,于是七个任务同时跑同一个库。它们各自 `pending_adjudications`+/// 拿到**同一批**待裁项:模型调用翻七倍,而两个任务对同一对下判断时,第二个+/// 撞 `agent_decisions_open_idx` 唯一索引直接失败(2026-09-08 实测:七个任务里+/// 两个这样挂掉)。+///+/// **等而不是跳过**:后到的等前一个跑完再进,进来时重新查一遍待裁项,+/// 通常只剩前一个读完之后才新增的那几对。+static PER_KB: LazyLock<Mutex<HashMap<Uuid, Arc<tokio::sync::Mutex<()>>>>> =+ LazyLock::new(Default::default);++fn lock_for(kb_id: Uuid) -> Arc<tokio::sync::Mutex<()>> {+ PER_KB+ .lock()+ .expect("per-kb adjudication lock table poisoned")+ .entry(kb_id)+ .or_default()+ .clone()+}+pub async fn adjudicate_entities(state: &AppState, kb_id: Uuid) -> anyhow::Result<()> {+ let lock = lock_for(kb_id);+ let _serial = lock.lock().await;let kb = utopia_store::kbs::get(&state.pool, kb_id).await?;let settings = utopia_store::settings::get(&state.pool, kb.workspace_id).await?;let client = settings.as_ref().and_then(llm_util::chat_client);diff --git a/crates/utopia-server/src/api/settings_routes.rs b/crates/utopia-server/src/api/settings_routes.rsindex 917d18f6..8afafcec 100644--- a/crates/utopia-server/src/api/settings_routes.rs+++ b/crates/utopia-server/src/api/settings_routes.rs@@ -70,6 +70,25 @@ pub async fn put(req.embed_dim,).await?;+ // **配好嵌入模型的这一刻,就是本体索引能开工的最早时刻。**+ //+ // 注册时自动建的默认库会装上本体包,而那一刻还没有模型:`embed_ontology`+ // 空转即报 done,此后没有任何东西会再排一次——库里躺着一份没有向量的本体,+ // 直到有人去编辑本体或跑一次类型消解。于是默认库的第一批文档必然走+ // 「全量铺本体」那条又贵又差的路。+ //+ // 在这里补一次,索引在用户还在想上传什么的时候就建起来了。抽取那边也各自+ // 兜底(见 extraction.rs),这里只是把它提前,不是唯一的保障。+ if nonempty(&req.embed_model).is_some() {+ for kb in utopia_store::kbs::list(&state.pool, workspace_id).await? {+ let _ = utopia_store::jobs::enqueue_unless_queued(+ &state.pool,+ "embed_ontology",+ serde_json::json!({ "kb_id": kb.id }),+ )+ .await;+ }+ }Ok(Json(json!({ "ok": true })))}diff --git a/crates/utopia-server/src/extraction.rs b/crates/utopia-server/src/extraction.rsindex 17ad1726..26e624df 100644--- a/crates/utopia-server/src/extraction.rs+++ b/crates/utopia-server/src/extraction.rs@@ -662,6 +662,24 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:classes = etypes.len(),"本体超出提示词预算,改为按分块检索候选");+ // **这一篇要靠检索,那就先把检索用的向量补齐——不要跟补齐任务赛跑。**+ //+ // 建库装包、随手上传,是产品里最自然的一条路,而它踩的正是这个坑:+ // `embed_ontology` 与 `extract_document` 同时排队,向量没就绪时按块检索+ // 取不到候选,退回全量本体——实测每块 109k tokens(正文只占 0.2%),+ // 且**多给的那些类会吃掉实体**(build_lists 上面那段注释量过:25 → 18)。+ // 更糟的是连锁:109k × 并发把端点打到限流,退避五次仍失败就整块跳过,+ // 一轮 13 块抽出来的同时 24 块被丢掉;抽取又占着端点,向量补得更慢。+ //+ // `refresh` 是幂等的、按库串行的(ontology_index::PER_KB),所以:+ // 第一篇文档把向量补出来,同时到的其余文档在锁上等一下,进来时已经没事可做。+ // 没配嵌入模型时它直接返回 0,退回全量那条路原样保留——那种部署本来就没有检索。+ //+ // 代价是新库的第一篇要多等几分钟。**换来的是它不会被一份烂抽取永久写坏**:+ // 事实一旦落库,没有人会回头发现「这篇当初是在本体看不见的时候抽的」。+ if let Err(e) = crate::ontology_index::refresh(state, doc.kb_id).await {+ tracing::warn!(%document_id, error = %e, "本体向量补齐失败,这一篇按全量本体抽");+ }}// 内置类恒在:检索漏掉的分块仍要有地方落脚,否则模型无类可选let seed_classes: HashSet<Uuid> = etypes.iter().filter(|t| t.builtin).map(|t| t.id).collect();@@ -1243,9 +1261,16 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:// 文本值的属性(schema.org 里 323 个)在这一档仍会变成实体——// 那里没有可靠判据,猜错会吃掉真实体,不猜let literal = match (&f.value, f.object.as_deref().map(str::trim)) {- (Some(v), None | Some("")) if !known_predicate(f.predicate.as_str()) => {- Some(v.clone())- }+ // **给了值、没给宾语——不管这个谓词本体认不认识。**+ //+ // 从前这里卡着 `!known_predicate`:`job_title` 在 schema.org 里是关系+ //(它的 range 是 `Text|DefinedTerm`,含一个类就走关系通道),于是模型+ // 写 `job_title` + "founder and CEO" 时既进不了属性档、又在关系档因为+ // 缺宾语被丢掉——`object_missing` 实测 69 次,四篇文档里每个人的职务+ // 就是这么没的。谓词认不认识与「这条事实带的是值还是实体」无关:+ // 值在手上就收下,原词进 proposed_predicate,等本体采纳时再换谓词,+ // 形状已经是对的(0010)+ (Some(v), None | Some("")) => Some(v.clone()),(_, Some(o))if !o.is_empty()&& !known_predicate(f.predicate.as_str())@@ -1258,17 +1283,55 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:};if let Some(value) = literal {let subject_name = f.subject.trim();- let Some(&subject_id) = entity_ids.get(subject_name) else {- drop_signal(- state,- doc.kb_id,- document_id,- utopia_store::extraction_drops::reason::SUBJECT_NOT_DECLARED,- &f.predicate,- Some(subject_name),- )- .await;- continue;+ // **主语按关系那条路解,不要求它在本次回复里重新声明过。**+ //+ // 从前这里只查 `entity_ids`,模型用「已知实体」句柄带进来的、+ // 或者只写了名字没重列的主语一律落空——实测一轮 51 块里+ // `subject_not_declared` 丢掉 113 条,丢的是 NVIDIA 的营收、+ // 净利、每股收益,是十位董事的赞成票与反对票,全是有名有姓的+ // 主语。属性那一档要求主语有类型(domain 要校验),这一档没有+ // domain 可校验,也就没有理由比关系那条路更严+ let subject_id = match f.subject_ref.as_deref().map(str::trim) {+ Some(handle) => match referenced_entity(&ref_entities, handle) {+ Some(bound) => bound.id,+ None => {+ drop_signal(+ state,+ doc.kb_id,+ document_id,+ utopia_store::extraction_drops::reason::MALFORMED_ITEM,+ &f.predicate,+ Some(handle),+ )+ .await;+ continue;+ }+ },+ None => {+ match no_ref_name_binding(&entity_ids, &handled_by_name, subject_name) {+ NoRefNameBinding::Legacy(id) => id,+ NoRefNameBinding::AmbiguousHandled | NoRefNameBinding::Missing => {+ touched_names.insert(+ utopia_store::resolution::normalize_name(subject_name)+ .to_lowercase(),+ );+ resolve_bare(+ &state.pool,+ doc.kb_id,+ entity_type_of.get(subject_name).copied().flatten(),+ subject_name,+ ctx,+ Some(&chunk.text),+ &mut doc_cache,+ &handled_by_name,+ &mut ambiguous_bare_cache,+ &mut needs_adjudication,+ &mut human_reviews_found,+ )+ .await?+ }+ }+ }};let _ = utopia_store::ontology::record_miss(&state.pool,@@ -1764,7 +1827,9 @@ async fn run(state: &AppState, document_id: Uuid, proposer: Proposer) -> anyhow:.await?;}} else if needs_adjudication {- utopia_store::jobs::enqueue(+ // 同库已排着的不重复——与下面的 resolve_types 一样。一批文档同时抽完+ // 会各排一个,而它们读到的是同一批待裁项+ utopia_store::jobs::enqueue_unless_queued(&state.pool,"adjudicate_entities",serde_json::json!({ "kb_id": doc.kb_id }),@@ -1937,6 +2002,13 @@ fn build_lists(const PER_CHUNK_CLASSES: i64 = 40;const PER_CHUNK_RELATIONS: i64 = 30;const PER_CHUNK_ATTRIBUTES: i64 = 30;+/// 「这批类身上声明的关系/属性」这道地板给多少名额。+///+/// 比按相似度那 30 个宽得多,因为它的池子已经被 domain 收窄过一轮——+/// schema.org 里 person + organization + corporation 三个类身上一共只有 86 个关系。+/// 上限只是防病态情况(一块认出上百个类),不是筛选手段。+const PER_CHUNK_DOMAIN_RELATIONS: i64 = 120;+const PER_CHUNK_DOMAIN_ATTRIBUTES: i64 = 40;/// 按这一块的向量检索候选,排出这一块专用的三段清单。///@@ -2030,6 +2102,42 @@ async fn chunk_lists(.collect();classes.extend(sig_classes);+ // **类进来了,就把本体声明在它们身上的关系也铺出去。**+ //+ // 上面那道祖先地板治的是「类捞不到」,这道治的是「关系捞不到」——同一个+ // 病的两侧。实测一块讲「Jensen Huang, founder and CEO of NVIDIA」的正文:+ // `employee` 排第 10 进了窗口,模型就用了它;而 `founder` 排 267、+ // `job_title` 排 618、`has_occupation` 排 811,一个都没进——**四篇文档里+ // 每个人的职务因此全部没落进图,而且不留任何丢弃信号:模型没被问到,+ // 也就什么都没说,drops 与 misses 两张表都看不见它**(2026-09-08 实测)。+ //+ // 收窄的判据是本体自己声明的 domain,不是又一次相似度猜测:这一块认出了+ // person 与 organization,那么「本体说人和组织能有什么」就该摆在模型面前。+ // 同一块里 `founder` 升到 29、`job_title` 升到 55(池子 86)。+ //+ // **放在 `sig_classes` 之后,是为了不让它反过来撑大类清单。** 放在前面时+ // 这批关系的 range 会顺着签名规则把一大票类拉进来,同一块的提示词从 11.7k+ // 涨到 21.4k——为了一个谓词付两倍的钱。它们的 domain 侧本来就在清单里+ // (地板正是这么选出来的),range 侧退化成 `*` 可以接受:这道地板要办的事+ // 是「让模型看见这个说法存在」,不是把签名补全。+ let domain_ids: Vec<Uuid> = classes.iter().copied().collect();+ for (limit, kind) in [+ (PER_CHUNK_DOMAIN_RELATIONS, "relation"),+ (PER_CHUNK_DOMAIN_ATTRIBUTES, "attribute"),+ ] {+ rels.extend(+ utopia_store::ontology::nearest_relation_type_ids_in_domains(+ &state.pool,+ kb_id,+ embedding,+ limit,+ Some(kind),+ &domain_ids,+ )+ .await?,+ );+ }+// 一个候选都没检索到 = 索引还没建好,退回全量而不是给一份空清单if classes.len() <= seed_classes.len() && rels.is_empty() {return Ok(None);diff --git a/crates/utopia-store/src/governance.rs b/crates/utopia-store/src/governance.rsindex 2850b919..c8e60e37 100644--- a/crates/utopia-store/src/governance.rs+++ b/crates/utopia-store/src/governance.rs@@ -347,7 +347,11 @@ pub fn name_shape(a: &str, b: &str) -> NameShape {if before_ok && after_ok {return Some(i);}- from = i + 1;+ // **前进一个字符,不是一个字节。** `i + 1` 落在多字节字符中间时,+ // 下一轮的 `long[from..]` 直接 panic——中文名字一撞上就炸,而这条+ // 路在裁决里跑,panic 掉的是整个任务:任务行永远停在 running,+ // 没有报错、没有重试,队列静默少一格(2026-09-08 实测)+ from = i + long[i..].chars().next().map_or(1, char::len_utf8);}None};@@ -1295,6 +1299,19 @@ mod tests {Version);assert_eq!(name_shape("DeepMind Health", "DeepMind"), Extension);+ // **中文名字不能把它炸掉。** 下面每一对都要走进「整词判定失败、+ // 换个位置再找」那条路,而那条路从前按字节前进,落在多字节字符+ // 中间就 panic——测试断言的是「有个答案」,不是答案是什么+ for (a, b) in [+ ("繪圖處理器", "繪圖"),+ ("英伟达繪圖繪圖", "繪圖"),+ ("北京中关村科技园", "中关村"),+ ("東京都渋谷区", "渋谷"),+ ("Nvidia 繪圖處理器", "繪圖"),+ ] {+ let _ = name_shape(a, b);+ let _ = name_shape(b, a);+ }assert_eq!(name_shape("Gemini Robotics-ER", "Gemini Robotics"),Extensiondiff --git a/crates/utopia-store/src/jobs.rs b/crates/utopia-store/src/jobs.rsindex 3cdae6be..6954bf23 100644--- a/crates/utopia-store/src/jobs.rs+++ b/crates/utopia-store/src/jobs.rs@@ -275,7 +275,22 @@ wherelet handler = handler.clone();let running = running.clone();tokio::spawn(async move {- let result = handler(job.clone()).await;+ // **处理器 panic 也要收尸。** 直接 `handler(job).await` 的话,+ // panic 会把这个 spawn 出来的 future 一起掀掉:`mark_failed`+ // 不会跑(任务行永远停在 running,无错误无重试),`running`+ // 也不会减(每 panic 一次就永久少一个并发名额,攒够 cap 之后+ // 整个队列不再认领任何任务)。套一层 spawn,panic 变成+ // JoinError 拿回来,两件事就都还在。+ let inner = {+ let (handler, job) = (handler.clone(), job.clone());+ tokio::spawn(async move { handler(job).await })+ };+ let result = match inner.await {+ Ok(r) => r,+ Err(join) => {+ Err(anyhow::anyhow!("任务处理器 panic(详情见 stderr):{join}"))+ }+ };let outcome = match result {Ok(()) => mark_done(&pool, job.id).await,Err(e) => {diff --git a/crates/utopia-store/src/ontology.rs b/crates/utopia-store/src/ontology.rsindex 1b9350b9..8c425d7d 100644--- a/crates/utopia-store/src/ontology.rs+++ b/crates/utopia-store/src/ontology.rs@@ -1292,6 +1292,46 @@ pub async fn nearest_entity_type_ids(}/// 同上,关系与属性。`only_kind` 分道:关系清单与属性清单在提示词里是两段。+/// 同上,但**只在 domain 落在这批类上的那些关系里**检索。+///+/// 存在的理由:全库检索对关系几乎没有区分度(1500 字的分块向量 vs 几个词的+/// 关系标签,距离全挤在一条窄带里)。实测一块讲「Jensen Huang, founder and CEO+/// of NVIDIA」的正文,`founder` 排 267、`job_title` 排 618(共 1026)——两个都进不了+/// 前 30 的窗口,于是模型没有地方写职务,索性不写。**不是抽错,是没被问到。**+///+/// 把池子先按 domain 收窄到「这一块认出来的那些类身上声明的关系」,同一块里+/// `founder` 升到 29、`job_title` 升到 55(共 86)。收窄靠的是本体自己声明的+/// 结构,不是又一个相似度模型。+pub async fn nearest_relation_type_ids_in_domains(+ pool: &PgPool,+ kb_id: Uuid,+ embedding: &[f32],+ limit: i64,+ only_kind: Option<&str>,+ domains: &[Uuid],+) -> AppResult<Vec<Uuid>> {+ if domains.is_empty() {+ return Ok(Vec::new());+ }+ let rows: Vec<(Uuid,)> = sqlx::query_as(+ "SELECT r.id FROM relation_types r+ WHERE r.kb_id = $1 AND r.embedding IS NOT NULL+ AND ($4::text IS NULL OR r.kind = $4)+ AND EXISTS (SELECT 1 FROM relation_type_domains d+ WHERE d.relation_type_id = r.id AND d.entity_type_id = ANY($5))+ ORDER BY r.embedding <=> $2+ LIMIT $3",+ )+ .bind(kb_id)+ .bind(Vector::from(embedding.to_vec()))+ .bind(limit)+ .bind(only_kind)+ .bind(domains)+ .fetch_all(pool)+ .await?;+ Ok(rows.into_iter().map(|(id,)| id).collect())+}+pub async fn nearest_relation_type_ids(pool: &PgPool,kb_id: Uuid,diff --git a/scripts/bench/README.md b/scripts/bench/README.mdindex 4e172456..4d342726 100644--- a/scripts/bench/README.md+++ b/scripts/bench/README.md@@ -42,6 +42,54 @@ node scripts/bench/run.mjs --corpus pharma --ontology /tmp/schemaorg.ttl --label- `subset-corpus.mjs` —— 从一份语料里挑几个条目做成新语料。**整条目取**,因为 `supersedes` 只在同一条目的相邻快照之间发生,随机抽块会把时态那根轴废掉。- `subset.mjs` —— 把 schema.org 的 TTL 切成前 N 个类,给退化曲线用。+- `recall.mjs` / `fetch-sec-filings.mjs` / `truth/nvda-public-docs.json` —— 召回的台子:+ 文档里该有的东西进图了没有(见下面「召回的测量台」)。++## 召回的测量台(2026-09-09)++`recall.mjs` 量的是另一件事:**这篇文档里该有的东西,进图了没有。**+`run.mjs` 问「实体归到哪个类」,`temporal.mjs` 问「两根轴答得对不对」,+这一个问「金额、容量、期限、票数、职务丢了多少」。++判据是**人读原文列出来的一张表**(`truth/nvda-public-docs.json`,52 条),+不是 `extraction_drops` / `ontology_misses` 那两张信号表——**它们只看得见+「抽出来了没落地」,看不见「根本没抽」**,而后者是大头:一份 8-K 的收购价、+留任池、交割时点全都不在图里的时候,那两张表是空的。++语料是四份真实 SEC 文件(`fetch-sec-filings.mjs` 抓,不入库存),各压一类形态:+收购公告(一句话三个数)、多方新闻稿(七方、四位高管带职务)、财报新闻稿+(行列关系全在表格里)、投票结果(二十一张无表头的表,十位董事各四类票数)。++```+node scripts/bench/fetch-sec-filings.mjs # 一次就够+node scripts/bench/recall.mjs --kb <id> # 一轮:清空 → 重抽 → 打分+node scripts/bench/recall.mjs --kb <id> --score # 只打分+node scripts/bench/recall.mjs --kb <id> --reprocess # 改了解析器:连分块一起重来+```++`--kb` 要一个**装了本体包、向量已补齐**的库:装一次 schema.org 要嵌 2500 条向量、+二十分钟,而这个台子量的不是本体。库里除了本体没有跨轮状态——事实、实体、信号+每轮都清空,自动扩本体上一轮长出来的关系也删掉(留着就进下一轮的提示词)。++**52 个条目、九成命中率,一个标准差 ≈ 2.7 条。** 单轮差一两条不是证据;+同一份代码重跑一遍再说。结构性的改善要看别的:`object_missing` 的计数、+某一类(比如「四位高管的职务」)是不是整类进来了。++2026-09-09 那一轮(dev @ cb2bab7 + 九处修改,DeepSeek-V3.2 + bge-m3):++| 轮次 | 改了什么 | 分数 |+| --- | --- | --- |+| 基线 | — | 33/52 |+| r1 | 字面值通道放行 | 29/52 ← 回归 |+| r2 | +表格保住行列 +关系地板 +主语兜底 | 44/52 |+| r3 | +角色规则 +空列裁剪 | 43/52 |+| r4 | +空表头让位 | 44/52 |+| r5 | +名单是名单 | **49/52** |+| r6 | 代码一字不改,重跑 | **49/52** |++r5 与 r6 漏的不是同一批(交集为空),剩下的是抽样噪声。+r1 那次回归最值钱:放开字面值之后,主语解析比关系通道严,一轮丢掉 113 条——+这个 bug 只有在放开字面值之后才暴露得出来。## 治理的测量台(0025)diff --git a/scripts/bench/fetch-sec-filings.mjs b/scripts/bench/fetch-sec-filings.mjsnew file mode 100644index 00000000..e306e2ae--- /dev/null+++ b/scripts/bench/fetch-sec-filings.mjs@@ -0,0 +1,59 @@+#!/usr/bin/env node+// 抓四份真实的 SEC 公开文件,作为「召回」测量台的语料。+//+// 为什么是 SEC 文件而不是维基百科:这个台子量的是**企业文档里的量化事实丢不丢**——+// 金额、容量、期限、票数、职务。维基条目讲的是叙事,一段话里常常一个数都没有;+// 而一份 8-K 的全部价值就是那几个数(收购价、交割时点、每位董事的四类票数)。+// 四份各压一类形态:+//+// 09-02 收购公告 —— 一句话里三个数(对价、留任池、交割时点)+// 08-17 多方新闻稿 —— 七个参与方、四位高管带职务、六个量级不同的数+// q2fy27 财报新闻稿 —— 财务报表,行列关系全在表格里+// 06-24 投票结果 —— 二十一张无表头的表,十位董事各四类票数+//+// **不把文件存进仓库。** 它们是各公司提交给 SEC 的文件,公开可取但版权不属于我们;+// 维基语料那边是 CC BY-SA 才随语料文件一起存的。这里存脚本,跑一次就有。+//+// 用法:node scripts/bench/fetch-sec-filings.mjs+// → scripts/bench/corpora/nvda-public-docs/*.html++import fs from "node:fs";+import path from "node:path";+import { execFileSync } from "node:child_process";+import { fileURLToPath } from "node:url";++const HERE = path.dirname(fileURLToPath(import.meta.url));+const OUT = path.join(HERE, "corpora", "nvda-public-docs");++// SEC 要求带能联系上的 User-Agent,否则 403。改成你自己的。+const UA = process.env.SEC_USER_AGENT || "Utopia-bench ([email protected])";+const BASE = "https://www.sec.gov/Archives/edgar/data/1045810";++const DOCS = [+ ["nvda-8k-2026-09-02.html", "000104581026000078/nvda-20260902.htm"],+ ["nvda-8k-2026-08-17-exhibit.html", "000104581026000069/sbeoainvidia-portsrelease.htm"],+ ["nvda-q2fy27-earnings-release.html", "000104581026000073/q2fy27pr.htm"],+ ["nvda-8k-2026-06-24.html", "000104581026000056/nvda-20260624.htm"],+];++// **走 curl,不走 fetch**:与 fetch-ai-timeline.mjs 同一个理由——+// 这台机器上 HTTP(S)_PROXY 指向本地代理,Node 20 的 undici 不读它。+function get(url) {+ return execFileSync("curl", ["-sSL", "--max-time", "90", "-H", `User-Agent: ${UA}`, url], {+ encoding: "buffer",+ maxBuffer: 64 * 1024 * 1024,+ });+}++fs.mkdirSync(OUT, { recursive: true });+for (const [name, suffix] of DOCS) {+ const dest = path.join(OUT, name);+ if (fs.existsSync(dest) && fs.statSync(dest).size > 0) {+ console.log("skip", name);+ continue;+ }+ const body = get(`${BASE}/${suffix}`);+ fs.writeFileSync(dest, body);+ console.log("ok ", name, body.length);+}+console.log(`\n语料在 ${OUT}\n真值在 scripts/bench/truth/nvda-public-docs.json\n跑一轮:node scripts/bench/recall.mjs`);diff --git a/scripts/bench/recall.mjs b/scripts/bench/recall.mjsnew file mode 100644index 00000000..c7c32817--- /dev/null+++ b/scripts/bench/recall.mjs@@ -0,0 +1,231 @@+#!/usr/bin/env node+// 召回的测量台:**这篇文档里该有的东西,进图了没有。**+//+// 与 run.mjs 的分工:那个量「类型消解把实体归到哪个类」,这个量「文档里的信息丢没丢」。+// 判据是人读原文列出来的一张表(truth/nvda-public-docs.json,52 条),不是模型自己的说法,+// 也不是 drops/misses 那两张信号表——**它们只看得见「抽出来了没落地」,看不见「根本没抽」**,+// 而后者才是大头:一份 8-K 的收购价、留任池、交割时点全都不在图里的时候,那两张表是空的。+//+// 打分只问「在不在」,不问「落没落上本体」:谓词取 coalesce(关系 key, proposed_predicate),+// 空谓词的事实照样算命中。本体接不接得住是另一个问题(run.mjs 那条线)。+//+// 一轮 = 清空事实与实体 → 本体退回装包那一刻 → 重抽 → 打分。**每轮条件相同,数字才可比**;+// 自动扩本体与类型消解在轮内关掉,否则上一轮长出来的关系会进下一轮的提示词。+//+// 用法:+// node scripts/bench/recall.mjs --kb <id> # 已有库(本体向量已就绪)+// node scripts/bench/recall.mjs --kb <id> --score # 只打分,不重抽+// node scripts/bench/recall.mjs --kb <id> --reprocess # 改了解析器:连分块一起重来+//+// 环境变量:BENCH_BASE / BENCH_EMAIL / BENCH_PASSWORD / BENCH_PSQL(同 run.mjs)。+//+// **为什么要 `--kb` 而不是每轮建新库**:装一次 schema.org 要嵌 2500 条向量、二十分钟,+// 而这个台子量的不是本体。库里除了本体没有别的跨轮状态——事实、实体、信号每轮都清空。++import fs from "node:fs";+import path from "node:path";+import { execFileSync } from "node:child_process";+import { fileURLToPath } from "node:url";++const HERE = path.dirname(fileURLToPath(import.meta.url));+const BASE = process.env.BENCH_BASE || "http://localhost:18080";+const EMAIL = process.env.BENCH_EMAIL || "[email protected]";+const PASSWORD = process.env.BENCH_PASSWORD || "benchbench123";+const CORPUS = path.join(HERE, "corpora", "nvda-public-docs");+const TRUTH = path.join(HERE, "truth", "nvda-public-docs.json");++const args = Object.fromEntries(+ process.argv.slice(2).reduce((acc, cur, i, arr) => {+ if (cur.startsWith("--")) acc.push([cur.slice(2), arr[i + 1]?.startsWith("--") ? true : arr[i + 1] ?? true]);+ return acc;+ }, []),+);+const KB = args.kb;+if (!KB) {+ console.error("要一个 --kb <id>:建一个装了本体包的库,等它的本体向量补齐,再把 id 给这里。");+ process.exit(1);+}++function psql(sql) {+ const cmd =+ process.env.BENCH_PSQL ||+ "docker exec -e PGPASSWORD=utopia landscapebi-db-1 psql -U utopia -d utopia -tAc";+ const parts = cmd.split(" ");+ return execFileSync(parts[0], [...parts.slice(1), sql], { encoding: "utf8", maxBuffer: 64 << 20 }).trim();+}+const num = (sql) => Number(psql(sql) || 0);+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));+const stamp = () => new Date().toISOString().slice(11, 19);++let cookie = "";+async function api(method, url, body, isForm) {+ const init = { method, headers: {} };+ if (cookie) init.headers.cookie = cookie;+ if (isForm) init.body = body;+ else if (body !== undefined) {+ init.headers["content-type"] = "application/json";+ init.body = JSON.stringify(body);+ }+ const r = await fetch(BASE + url, init);+ for (const c of r.headers.getSetCookie?.() ?? []) cookie = c.split(";")[0];+ const t = await r.text();+ if (!r.ok) throw new Error(`${method} ${url} -> ${r.status} ${t.slice(0, 200)}`);+ return t ? JSON.parse(t) : null;+}++const truth = JSON.parse(fs.readFileSync(TRUTH, "utf8"));+const DOCS = [...new Set(truth.map((t) => t.doc))];++function score() {+ // 一篇文档的全部现行事实,摊平成可搜的一行+ // 用单元分隔符拼成一列再取回:BENCH_PSQL 是一条固定的命令串(`-tAc` 结尾),+ // 加不了 `-F`,而默认的 `|` 会被名字里的竖线撞上+ const rows = psql(`+ SELECT concat_ws(chr(31),+ d.filename,+ coalesce(s.canonical_name,''),+ coalesce(rt.key, coalesce(fe.proposed_predicate,'')),+ coalesce(o.canonical_name, f.object_value #>> '{}', f.object_value::text, ''),+ coalesce(to_char(f.valid_from,'YYYY-MM-DD'),''))+ FROM facts f+ JOIN fact_evidence fe ON fe.fact_id = f.id+ JOIN documents d ON d.id = fe.document_id+ JOIN entities s ON s.id = f.subject_id+ LEFT JOIN relation_types rt ON rt.id = f.predicate_id+ LEFT JOIN entities o ON o.id = f.object_id+ WHERE f.kb_id = '${KB}' AND f.invalidated_at IS NULL`)+ .split("\n")+ .filter(Boolean)+ .map((l) => {+ const [file, subj, pred, obj, from] = l.split("");+ return { file, subj, pred, obj, from };+ });++ const byDoc = new Map();+ for (const r of rows) {+ const key = r.file.replace(/\.(html|md|pdf)$/i, "");+ if (!byDoc.has(key)) byDoc.set(key, []);+ byDoc.get(key).push(r);+ }++ const norm = (s) => (s || "").toLowerCase().replace(/[’‘]/g, "'");+ // 值只比字符,不比排版:"8 IT-GW" 与 "8-IT GW" 是同一个数;不抹平就会把命中判成漏抽+ const squash = (s) => norm(s).replace(/[\s\-–—]/g, "");++ let pass = 0;+ const misses = [];+ const perDoc = new Map();+ const perKind = new Map();++ for (const t of truth) {+ const facts = byDoc.get(t.doc) || [];+ let ok = false;+ if (t.kind === "value") {+ ok = facts.some((f) => {+ const raw = `${f.subj} | ${f.pred} | ${f.obj} | ${f.from}`;+ return t.value_any.some((v) => norm(raw).includes(norm(v)) || squash(raw).includes(squash(v)));+ });+ } else if (t.kind === "edge") {+ ok = facts.some((f) => {+ const s = norm(f.subj), o = norm(f.obj);+ return (+ (t.subject.some((x) => s.includes(norm(x))) && t.object.some((x) => o.includes(norm(x)))) ||+ (t.subject.some((x) => o.includes(norm(x))) && t.object.some((x) => s.includes(norm(x))))+ );+ });+ } else if (t.kind === "predicate") {+ ok = facts.some((f) => t.predicate_any.some((p) => norm(f.pred).includes(norm(p))));+ }+ for (const [map, key] of [[perDoc, t.doc], [perKind, t.kind]]) {+ const cur = map.get(key) || { pass: 0, total: 0 };+ cur.total++;+ if (ok) cur.pass++;+ map.set(key, cur);+ }+ if (ok) pass++;+ else misses.push(t);+ }++ console.log(`\n总分 ${pass}/${truth.length} (${((100 * pass) / truth.length).toFixed(1)}%)\n`);+ for (const [doc, d] of [...perDoc].sort()) {+ console.log(` ${String(d.pass).padStart(2)}/${String(d.total).padEnd(2)} ${doc}`);+ }+ const label = { value: "字面值(金额/日期/职务/票数)", edge: "关系边", predicate: "谓词区分度" };+ console.log("\n按类别:");+ for (const [k, v] of perKind) {+ console.log(` ${String(v.pass).padStart(2)}/${String(v.total).padEnd(2)} ${label[k] || k}`);+ }+ console.log("\n没进图的:");+ for (const m of misses) console.log(` [${m.doc}] ${m.id} — ${m.what}`);+ // **52 个条目、九成命中率,一个标准差 ≈ 2.7 条。** 单轮差一两条不是证据,+ // 同一份代码重跑一遍再说;结构性的改善看 drops 计数与某一类是否整类进来了+ console.log("\n(52 条真值,1σ ≈ 2.7 条:单轮小幅波动不作数)");+}++if (args.score) {+ score();+ process.exit(0);+}++await api("POST", "/api/v1/auth/login", { email: EMAIL, password: PASSWORD });++// 已经在库里的就不重传;第一次跑要先 fetch-sec-filings.mjs+const existing = ((await api("GET", `/api/v1/kbs/${KB}/documents?limit=200`)).docs ?? []).map((d) => d.filename);+const want = DOCS.map((d) => `${d}.html`);+const missing = want.filter((f) => !existing.includes(f));+for (const f of missing) {+ const p = path.join(CORPUS, f);+ if (!fs.existsSync(p)) throw new Error(`语料缺 ${f},先跑 node scripts/bench/fetch-sec-filings.mjs`);+ const fd = new FormData();+ fd.append("files", new Blob([fs.readFileSync(p)]), f);+ await api("POST", `/api/v1/kbs/${KB}/documents`, fd, true);+ console.log(`${stamp()} 上传 ${f}`);+}+if (missing.length) {+ // 新传的要先解析入库,才谈得上重抽+ while (num(`SELECT count(*) FROM documents WHERE kb_id='${KB}' AND status <> 'ready'`) > 0) await sleep(5000);+}++const names = want.map((f) => `'${f}'`).join(",");+const packTs = psql(+ `SELECT coalesce(min(created_at)::text,'') FROM relation_types WHERE kb_id='${KB}'`,+);+console.log(`=== ${stamp()} 清空(本体退回 ${packTs})===`);+psql(`DELETE FROM jobs WHERE kind IN ('adjudicate_entities','bootstrap_ontology','resolve_types','govern')`);+psql(`DELETE FROM facts WHERE kb_id='${KB}'`);+psql(`DELETE FROM entities WHERE kb_id='${KB}'`);+psql(`DELETE FROM extraction_drops WHERE kb_id='${KB}'`);+psql(`DELETE FROM ontology_misses WHERE kb_id='${KB}'`);+// 自动扩本体上一轮长出来的关系:留着就进下一轮的提示词,两轮条件不同+psql(`DELETE FROM relation_types WHERE kb_id='${KB}' AND created_at > '${packTs}'::timestamptz + interval '1 second'`);+psql(`UPDATE knowledge_bases SET auto_extend_ontology=FALSE, auto_type_resolution=FALSE WHERE id='${KB}'`);+psql(`UPDATE chunks SET extracted_at=NULL WHERE document_id IN (SELECT id FROM documents WHERE kb_id='${KB}' AND filename IN (${names}))`);+console.log(`本体 ${num(`SELECT count(*) FROM relation_types WHERE kb_id='${KB}'`)} 个关系 / ${num(`SELECT count(*) FROM entity_types WHERE kb_id='${KB}'`)} 个类`);++const docs = (await api("GET", `/api/v1/kbs/${KB}/documents?limit=200`)).docs.filter((d) => want.includes(d.filename));+const endpoint = args.reprocess ? "reprocess" : "extract";+for (const d of docs) {+ await api("POST", `/api/v1/documents/${d.id}/${endpoint}`, {});+ console.log(`${stamp()} 排队 ${endpoint} ${d.filename}`);+}++// **看进展,不看总时长**:慢不算超时,卡住才算(与 run.mjs 同一条规矩)+const live = `SELECT count(*) FROM chunks c JOIN documents d ON d.id=c.document_id+ WHERE d.kb_id='${KB}' AND d.filename IN (${names}) AND c.superseded_at IS NULL`;+let last = -1, stall = 0;+for (;;) {+ const done = num(`${live.replace("count(*)", "count(c.extracted_at)")}`);+ const total = num(live);+ const left = num(+ `SELECT count(*) FROM jobs WHERE kind IN ('extract_document','process_document') AND status IN ('queued','running')`,+ );+ console.log(`${stamp()} ${done}/${total} 块,还有 ${left} 个任务`);+ if (left === 0 && done > 0) break;+ if (done === last) {+ if (++stall > 30) { console.log("十五分钟没有进展,停"); break; }+ } else stall = 0;+ last = done;+ await sleep(30000);+}++score();diff --git a/scripts/bench/truth/nvda-public-docs.json b/scripts/bench/truth/nvda-public-docs.jsonnew file mode 100644index 00000000..23311eab--- /dev/null+++ b/scripts/bench/truth/nvda-public-docs.json@@ -0,0 +1,109 @@+[+ { "doc": "nvda-8k-2026-09-02", "id": "acq-edge", "what": "NVIDIA 收购 Hugging Face(有一条把两者连起来的边)",+ "kind": "edge", "subject": ["nvidia"], "object": ["hugging face"] },+ { "doc": "nvda-8k-2026-09-02", "id": "acq-price", "what": "对价约 $11.9 billion",+ "kind": "value", "value_any": ["11.9"] },+ { "doc": "nvda-8k-2026-09-02", "id": "acq-retention", "what": "留任股权计划最高约 $1.0 billion",+ "kind": "value", "value_any": ["1.0 billion", "$1.0", "1 billion"] },+ { "doc": "nvda-8k-2026-09-02", "id": "acq-close", "what": "预计 2027 年上半年交割",+ "kind": "value", "value_any": ["first half of 2027", "2027"] },+ { "doc": "nvda-8k-2026-09-02", "id": "acq-fy-end", "what": "财年结束于 2026-01-25",+ "kind": "value", "value_any": ["january 25, 2026", "2026-01-25"] },+ { "doc": "nvda-8k-2026-09-02", "id": "cfo-name", "what": "Colette M. Kress 与 NVIDIA 有关系",+ "kind": "edge", "subject": ["nvidia", "kress"], "object": ["kress", "nvidia"] },+ { "doc": "nvda-8k-2026-09-02", "id": "cfo-title", "what": "Kress 的职务 EVP / CFO",+ "kind": "value", "value_any": ["chief financial officer", "cfo"] },+ { "doc": "nvda-8k-2026-09-02", "id": "hq", "what": "总部地址 Santa Clara",+ "kind": "value", "value_any": ["santa clara"] },+ { "doc": "nvda-8k-2026-09-02", "id": "ticker", "what": "股票代码 NVDA",+ "kind": "value", "value_any": ["nvda"] },+ { "doc": "nvda-8k-2026-09-02", "id": "exchange", "what": "在 Nasdaq 上市",+ "kind": "value", "value_any": ["nasdaq"] },+ { "doc": "nvda-8k-2026-09-02", "id": "hf-open", "what": "承诺保持 Hugging Face 平台开放",+ "kind": "edge", "subject": ["hugging face"], "object": ["silicon vendor", "model", "developer", "open"] },++ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-parties", "what": "NVIDIA 与 SB Energy 之间有边",+ "kind": "edge", "subject": ["nvidia"], "object": ["sb energy"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-invest", "what": "NVIDIA 投资 SB Energy $1.5 billion",+ "kind": "value", "value_any": ["1.5 billion", "$1.5"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-huang", "what": "Jensen Huang 与 NVIDIA 有边",+ "kind": "edge", "subject": ["nvidia", "huang"], "object": ["huang", "nvidia"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-huang-title", "what": "Jensen Huang 的职务 founder and CEO",+ "kind": "value", "value_any": ["founder and ceo", "chief executive"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-hossfeld-title", "what": "Rich Hossfeld 的职务 co-CEO",+ "kind": "value", "value_any": ["co-ceo", "co ceo", "chief executive"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-altman-title", "what": "Sam Altman 的职务 CEO",+ "kind": "value", "value_any": ["ceo", "chief executive"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-son-title", "what": "Masayoshi Son 的职务 Chairman and CEO",+ "kind": "value", "value_any": ["chairman"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-gw", "what": "至少 10 GW 新增发电",+ "kind": "value", "value_any": ["10 gw", "10gw"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-itgw", "what": "8 IT-GW 的 AI factory 容量",+ "kind": "value", "value_any": ["8 it-gw", "8 itgw", "8 it gw"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-grid", "what": "至少 $4.2 billion 电网投入",+ "kind": "value", "value_any": ["4.2 billion", "$4.2"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-fund", "what": "$40 million 社区基金",+ "kind": "value", "value_any": ["40 million", "$40"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-2028", "what": "分阶段自 2028 年起上线",+ "kind": "value", "value_any": ["2028"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-pike", "what": "园区在 Pike County",+ "kind": "edge", "subject": ["ports-pike", "campus"], "object": ["pike county", "ohio"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-ports", "what": "改造已退役的 Portsmouth Gaseous Diffusion Plant",+ "kind": "value", "value_any": ["portsmouth"] },+ { "doc": "nvda-8k-2026-08-17-exhibit", "id": "oh-aep", "what": "与 AEP Ohio 合作",+ "kind": "value", "value_any": ["aep ohio", "aep"] },++ { "doc": "nvda-q2fy27-earnings-release", "id": "er-rev", "what": "季度营收 $96.2B / 96,221",+ "kind": "value", "value_any": ["96,221", "96.2", "96221"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-dc", "what": "数据中心营收 $89.0B",+ "kind": "value", "value_any": ["89.0", "89,0"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-gm", "what": "毛利率 75.0%",+ "kind": "value", "value_any": ["75.0"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-eps", "what": "GAAP 摊薄每股收益 $2.46",+ "kind": "value", "value_any": ["2.46"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-eps-nongaap", "what": "non-GAAP 每股收益 $2.22",+ "kind": "value", "value_any": ["2.22"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-quarter-end", "what": "季度截止 2026-07-26",+ "kind": "value", "value_any": ["july 26, 2026", "2026-07-26"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-return", "what": "返还股东约 $26.0 billion",+ "kind": "value", "value_any": ["26.0 billion", "$26.0"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-buyback", "what": "回购授权余额约 $99.0 billion",+ "kind": "value", "value_any": ["99.0"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-div", "what": "股息 $0.25 每股",+ "kind": "value", "value_any": ["0.25"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-div-pay", "what": "股息支付日 2026-10-01",+ "kind": "value", "value_any": ["october 1, 2026", "2026-10-01"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-div-record", "what": "股息登记日 2026-09-10",+ "kind": "value", "value_any": ["september 10, 2026", "2026-09-10"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-guide", "what": "Q3 指引营收 $108.0 billion",+ "kind": "value", "value_any": ["108.0"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-tax", "what": "FY27 税率 16%–18%",+ "kind": "value", "value_any": ["16.0", "18.0"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-huang", "what": "Jensen Huang 与 NVIDIA 有边",+ "kind": "edge", "subject": ["nvidia", "huang"], "object": ["huang", "nvidia"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-huang-title", "what": "Jensen Huang 的职务 founder and CEO",+ "kind": "value", "value_any": ["founder and ceo", "chief executive"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-coreweave", "what": "Vera Rubin 合作方 CoreWeave",+ "kind": "edge", "subject": ["vera rubin"], "object": ["coreweave"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-nebius", "what": "Vera Rubin 合作方 Nebius",+ "kind": "edge", "subject": ["vera rubin"], "object": ["nebius"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-oci", "what": "Vera Rubin 合作方 Oracle Cloud Infrastructure",+ "kind": "edge", "subject": ["vera rubin"], "object": ["oracle"] },+ { "doc": "nvda-q2fy27-earnings-release", "id": "er-spectrum", "what": "Spectrum-6 交换机",+ "kind": "value", "value_any": ["spectrum"] },++ { "doc": "nvda-8k-2026-06-24", "id": "vt-meeting", "what": "2026-06-24 年度股东大会",+ "kind": "value", "value_any": ["june 24, 2026", "2026-06-24"] },+ { "doc": "nvda-8k-2026-06-24", "id": "vt-coxe", "what": "Tench Coxe 当选董事(与 NVIDIA 有边)",+ "kind": "edge", "subject": ["nvidia", "coxe"], "object": ["coxe", "nvidia"] },+ { "doc": "nvda-8k-2026-06-24", "id": "vt-huang", "what": "Jen-Hsun Huang 当选董事",+ "kind": "edge", "subject": ["nvidia", "huang"], "object": ["huang", "nvidia"] },+ { "doc": "nvda-8k-2026-06-24", "id": "vt-for-coxe", "what": "Tench Coxe 赞成票 15,411,252,412",+ "kind": "value", "value_any": ["15,411,252,412", "15411252412"] },+ { "doc": "nvda-8k-2026-06-24", "id": "vt-for-huang", "what": "Jen-Hsun Huang 赞成票 16,650,193,763",+ "kind": "value", "value_any": ["16,650,193,763", "16650193763"] },+ { "doc": "nvda-8k-2026-06-24", "id": "vt-for-label", "what": "票数分得出「赞成」这一类(谓词或值里有 for/against/abstain)",+ "kind": "predicate", "predicate_any": ["shares_for", "votes_for", "for_votes", "against", "abstain", "broker"] },+ { "doc": "nvda-8k-2026-06-24", "id": "vt-ten", "what": "选出十名董事",+ "kind": "value", "value_any": ["ten", "10 director"] }+]