业务本体与标准实体:跨源键值对齐、对账共变算子、健康证据链与实体助手

- 新增标准业务实体(CanonicalEntity)模型、确定性跨源编码翻译、后台候选实体扫描与文档驱动实体智能助手
- 新增指标本体图谱(factor / reconciles_with / upstream_driver)、DAG 防环校验以及 ontology_neighbors / source_health 内置工具
- 新增跨源对账(analysis_reconcile)与滞后共变(analysis_cochange)分析算子,打通 [[h:H1]] 数据源健康证据链、报告导出与本体消融评测
- 数据目录新增「标准业务实体」视图与候选审阅工作台,口径页集成指标本体拓扑面板与端到端浏览器检查
This commit is contained in:
ThearchyHelios
2026-11-12 12:57:53 +08:00
parent 2f90f0eb3a
commit 8d9a712eae
106 changed files with 16654 additions and 295 deletions
+29 -3
View File
@@ -89,7 +89,32 @@ def node_limits(config: dict[str, Any], snapshot: dict[str, Any], hard_cap: int)
)
def call_key(name: str, args: dict[str, Any]) -> str:
def call_key(name: str, args: dict[str, Any], *, canonical: bool = False) -> str:
if canonical:
args = dict(args)
if name.startswith("db_schema__") and "table" in args:
from app.tools.datasource import _schema_tables
args["table"] = sorted(set(_schema_tables(args["table"])))
if name.startswith("db_query__") and isinstance(args.get("sql"), str):
import sqlglot
sql = args["sql"]
try:
tokens = sqlglot.tokenize(sql)
# Preserve every token verbatim, including literals, quoted identifiers and comments.
# Only collapse whitespace gaps: comments/non-whitespace gaps disqualify normalization.
end, pieces = 0, []
for token in tokens:
if sql[end:token.start].strip():
break
pieces.append(sql[token.start:token.end + 1])
end = token.end + 1
else:
if not sql[end:].strip():
args["sql"] = " ".join(pieces)
except sqlglot.errors.TokenError:
pass
return json.dumps({"tool": name, "args": args}, ensure_ascii=False, sort_keys=True, default=str)
@@ -124,12 +149,13 @@ class Guard:
last_input: int = 0
compressed: bool = False
facts: dict[str, Any] = field(default_factory=dict)
canonical_calls: bool = False
# ------------------------------------------------------------ 重复调用
def repeat(self, name: str, args: dict[str, Any]) -> str | None:
"""同一个工具、同样的参数已经成功跑过:返回要喂回去的那句话,不再执行。"""
hit = self.seen.get(call_key(name, args))
hit = self.seen.get(call_key(name, args, canonical=self.canonical_calls))
if hit is None:
return None
step, content = hit
@@ -138,7 +164,7 @@ class Guard:
def record(self, step: int, name: str, args: dict[str, Any], ok: bool, content: str) -> None:
if ok:
self.seen.setdefault(call_key(name, args), (step, content))
self.seen.setdefault(call_key(name, args, canonical=self.canonical_calls), (step, content))
def step_done(self, progressed: bool) -> None:
self.stalled = 0 if progressed else self.stalled + 1