@aalis/plugin-user-relation 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.js +4 -4
- package/dist/actions.js.map +1 -1
- package/dist/extractor.d.ts +7 -0
- package/dist/extractor.d.ts.map +1 -1
- package/dist/extractor.js +23 -1
- package/dist/extractor.js.map +1 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +11 -12
- package/dist/service.js.map +1 -1
- package/package.json +3 -3
package/dist/service.js
CHANGED
|
@@ -1977,7 +1977,7 @@ export class RelationService {
|
|
|
1977
1977
|
// 2) PersonEventEdge 去重:按现行 addPersonEventEdge 吸收规则重排(修旧账)
|
|
1978
1978
|
// 3) 报告:返回结构化结果,调用方按需展示
|
|
1979
1979
|
//
|
|
1980
|
-
//
|
|
1980
|
+
// 注:不做「自动 part-of」步骤(实体名是事件标题子串时自动建边)。
|
|
1981
1981
|
// 原因:consolidate 在初始 snapshot 上运行,无法感知本轮 event 合并后的 rewire 结果,
|
|
1982
1982
|
// 导致别名事件的 about 边 rewire 到 canonical 后与 consolidate 新建的 part-of 并存,
|
|
1983
1983
|
// 形成同一 (event,entity) 对同时存在两种边类型的脏数据。
|
|
@@ -2057,9 +2057,9 @@ export class RelationService {
|
|
|
2057
2057
|
let shouldMerge = true;
|
|
2058
2058
|
// hierarchy 守门:若 a/b 之间已存在**有证据**的 part-of/contains 边
|
|
2059
2059
|
// → 视为已知层级,禁止 alias 合并。
|
|
2060
|
-
//
|
|
2061
|
-
//
|
|
2062
|
-
//
|
|
2060
|
+
// 注意:必须卡 evidence≥1——LLM 抽取阶段会产出大量 evidence=0 的幻觉层级边,
|
|
2061
|
+
// 无视 evidence 数会让这道安全网被污染(如 APEX ↔ 《Apex英雄》被锁住无法合并)。
|
|
2062
|
+
// 只信任 evidence≥1 的层级边:幻觉边不阻塞合并,真实层级仍守门。
|
|
2063
2063
|
const knownHierarchyEdge = snapshot.edges.some(e => e.kind === 'entity-entity' &&
|
|
2064
2064
|
(e.relationType === 'part-of' || e.relationType === 'contains') &&
|
|
2065
2065
|
(e.evidence?.length ?? 0) >= 1 &&
|
|
@@ -2150,7 +2150,7 @@ export class RelationService {
|
|
|
2150
2150
|
});
|
|
2151
2151
|
aliasEdgesCreated++;
|
|
2152
2152
|
}
|
|
2153
|
-
// 无条件触发真合并:即便 alias
|
|
2153
|
+
// 无条件触发真合并:即便 alias 边已存在("路由+壳子"式的
|
|
2154
2154
|
// 半合并状态),也要把 alias 节点真正合并掉,确保收敛。mergeAlias 幂等:
|
|
2155
2155
|
// alias 节点已不存在 → 直接 no-op;还在 → 正常合并。
|
|
2156
2156
|
const mergeResult = await this.mergeAlias({ aliasId: a.id, canonicalId: b.id, kind: 'entity' });
|
|
@@ -2169,7 +2169,7 @@ export class RelationService {
|
|
|
2169
2169
|
// (a) name 子串包含(短名 ⊂ 长名,且短名长度 ≥ 2)
|
|
2170
2170
|
// (b) 一方的某个 alias 与另一方的 name 归一相等
|
|
2171
2171
|
//
|
|
2172
|
-
// ──
|
|
2172
|
+
// ── 决策范式:批量决策 → 并查集分簇 → 一次合并 ──
|
|
2173
2173
|
// 1) 召回所有 pair 候选
|
|
2174
2174
|
// 2) 对每个候选跑 verifyAliasPair(只记结果,不立即合并)
|
|
2175
2175
|
// 3) 把所有 LLM 判 yes 的候选丢进并查集 (union-find),
|
|
@@ -2178,7 +2178,7 @@ export class RelationService {
|
|
|
2178
2178
|
// (mergeScore = 0.5·weightSum + 0.3·edgeCount + 0.2·evidenceCount,
|
|
2179
2179
|
// 不含 recency;与 compositeScore 解耦,专为"挑代表"语义),
|
|
2180
2180
|
// 把其它成员逐个 mergeAlias 到 canonical
|
|
2181
|
-
//
|
|
2181
|
+
// 动机:"判一对合一对"时 snapshot 不刷新会出现悬空合并 / 漏传递闭包。
|
|
2182
2182
|
// 本范式让决策与应用分离,所有 LLM 判定基于同一份 snapshot,行为可预测。
|
|
2183
2183
|
// 未启用 LLM 时跳过本段(保持原算法的零误合并保证)。
|
|
2184
2184
|
if (opts.autoLink && llmModel && opts.llm) {
|
|
@@ -2592,7 +2592,7 @@ export class RelationService {
|
|
|
2592
2592
|
eventEdgesNormalized++;
|
|
2593
2593
|
}
|
|
2594
2594
|
// ─── (3b) PersonEntityEdge 旧账整理:同一 (person,entity) 多条不同 role 行 → 留最强 role
|
|
2595
|
-
//
|
|
2595
|
+
// 存量里可能有未做 (from,to) 级别去重的边;此处按当前 addPersonEntityEdge 规则修旧账。
|
|
2596
2596
|
const peEntityPairs = new Map();
|
|
2597
2597
|
for (const e of snapshot.edges) {
|
|
2598
2598
|
if (e.kind !== 'person-entity')
|
|
@@ -3145,16 +3145,15 @@ export class RelationService {
|
|
|
3145
3145
|
}
|
|
3146
3146
|
let fusedScore = null;
|
|
3147
3147
|
if (cosineScore !== null) {
|
|
3148
|
-
//
|
|
3149
|
-
// 原 0.3·cos + 0.7·struct 让"标题/语义高度相似但孤立(无共邻边)"的事件对永远
|
|
3148
|
+
// 若用 0.3·cos + 0.7·struct,"标题/语义高度相似但孤立(无共邻边)"的事件对会永远
|
|
3150
3149
|
// fused≈0 → 默认阈值 0.7 永远不达 → 永远不进 LLM(如「缸中之脑技术的讨论」与
|
|
3151
3150
|
// 「缸中之脑的讨论」)。文本语义本身就是 event 相似度更稳定的信号,结构相似只在
|
|
3152
3151
|
// 已经连接到共同实体/人物的场景下才能加成;这里以文本为主、结构为辅。
|
|
3153
3152
|
fusedScore = 0.7 * cosineScore + 0.3 * structuralScore;
|
|
3154
3153
|
}
|
|
3155
3154
|
// 候选判定:fused 或 jaccard 或 struct 任一达阈即可(OR 兜底)。
|
|
3156
|
-
//
|
|
3157
|
-
//
|
|
3155
|
+
// embedding 可用时若完全忽略 jaccard,高 cos 高 jaccard 但 struct=0 的孤立
|
|
3156
|
+
// 事件对会被丢弃;把 jaccard/struct 兜底显式纳入候选判定,让 LLM 仍有机会评审。
|
|
3158
3157
|
const hasEmbed = cosineScore !== null;
|
|
3159
3158
|
const isCandidate = (hasEmbed && fusedScore >= fusedThreshold) ||
|
|
3160
3159
|
jaccardScore >= jaccardThreshold ||
|