ZY Action PlatformP4 LightGotham

P4 LightGotham — 多源情报融合与智能决策平台

对标 Palantir Gotham(Graph / Map / Timeline / Dossier / Object Explorer)。以实体和关系为中心,核心产出是从海量异构碎片数据中发现隐藏关联、揭示异常模式、形成可行动的情报产品。服务端口 18083

自研磁盘图存储 图算法 实体解析四层 时空多视图联动 报告 + ABAC V5 图谱域(导入/分区/时序)

GraphStore 自研磁盘图存储

products/gotham/graph/(store/memstore/persist/index):自研实现,不引入外部图库(Neo4j 留作 GraphStore 可替换后端)。

  • 数据结构nodes map[string]*GraphNode + outAdj/inAdj 邻接表(节点ID → 边类型 → 目标节点ID → 边),支持入边查询与无向边双写。
  • 持久化:全量快照 JSON(temp/gotham_graph.json变更写盘(标记 dirty,超阈值如 200 次或 5s 异步重写);进程退出 Close() 强制 flush;启动加载重建邻接表与索引。
  • 事务与幂等:sync.RWMutex 包裹批量写;UpsertEdge 幂等键 = sha256(source|type|target|direction),重复提交不产生重复边。
  • MergeNode:实体合并(absorbed 的边全部重定向到 surviving,合并关系记入 merged_entity_ids);幂等,冲突返回 GOTHAM_MERGE_CONFLICT
  • 索引:type 索引 + 高频属性等值索引(仅本体声明可索引属性,如 name/phone/id_number)。
  • 与 Foundry 本体对齐:图节点 Type = object_type.api_name、边 Type = link_type.api_name,节点 ID graph:{type}:{rid}

性能目标(PRD §6.1):10 万节点/百万边加载 <3s;1-3 度展开 <2s;最短路径 <5s(6 度内)。

图算法(全部在 GraphStore 之上,Go 原生)

算法实现要点复杂度
1-3 度展开 ExpandBFS 按层遍历,节点去重 + 边收集;max_nodes 硬校验(默认 500 上限 5000),超限返回 GOTHAM_EXPAND_LIMIT_EXCEEDED 而非静默截断O(V+E)
最短路径无权 BFS + 父指针回溯(all_shortest 返回全部等长路径,max_paths 硬校验);有权 Dijkstra + heap(权重取边属性 weight)O(V+E) / O(E·logV)
中心性度中心性(出/入/无向三口径);介数中心性 Brandes + 随机度采样近似O(V) / O(V·E) 采样可降
社群union-find 连通分量(路径压缩+按秩合并);Louvain 简化版(一轮局部移动 + 网络折叠)O(V·α) / 近线性

API:/analysis/graph/expand|path|centrality|community;响应含 visualization_hints(力导向布局、节点大小/颜色字段)。

融合接入(ingestion)

products/gotham/fusion/(sources + importer):复用底座 connector/datasource 作数据接入层。

  • 数据源管理ingestion_sources(type: db/file/api;连接配置 AES-256-GCM 加密存储)+ 批次 + 映射规则。
  • 导入流水线:抽取 → 清洗(trim/空值/日期/手机号/全角半角)→ 映射(表→实体类型、字段→属性、关联→关系)→ 图写入(BatchUpsert 幂等);异步 goroutine + SSE 进度。
  • 事件:批次完成 Publish ingestion.batch.completed 经 eventbus 触发解析。

实体解析四层流水线(三阈值带 + union-find + AI 灰区)

products/gotham/resolution/(layers/scoring/cluster/thresholds/jobs):业界 block→score→cluster 三阶段落地为:

新记录流入 → L1 Blocking 分块(类型/属性/拼音/N-gram/sorted-neighborhood,产候选对避免 O(n²))
  → L2 确定性层 Deterministic:唯一标识符精确相等 → score=1.0 auto_merge
  → L3 规则层 Rule:归一化 + 组合字段精确/近似匹配(姓名+出生日期+地址 / 企业名+法人…)
  → L4 模糊层 Fuzzy:SimMetrics 组合评分(Levenshtein / Jaro-Winkler / Soundex)
  → L5 AI 层(可选):仅 0.35≤score<0.85 灰区路由 LLM(selecting 策略,批量 10-15 对)
  → cluster(union-find 连通分量聚成 canonical entity,先聚簇再合并防假簇)
  → 三阈值带分流:
      score ≥ 0.90      → auto_merged(自动合并)
      0.70 ≤ score < 0.90 → pending_review(人工审核)
      score < 0.70      → rejected
  → 合并执行:graph.MergeNode(surviving, absorbed[])
  • 作业模型:job(全量/增量)→ run(每批默认 5000 条)→ resolution_records;状态机 pending/running/blocked/completed/failed/cancelled(人工处理完最后一条 pending_review 自动回 completed)。
  • 人工审核回路:并排对比/差异高亮/批量确认/拒绝/拆分;审核反馈回流(V2 在线学习权重)。
  • 限制:单 job ≤100 万条(演示 ≤10 万),超时 30 分钟。

地理空间(geo)

  • 几何统一 GeoJSON(点/线/面),后端一律返回 FeatureCollection,前端 Leaflet 原生消费(MapView.vue)。
  • 双存储路径降级:PG + PostGIS(ST_Within/ST_Distance,GiST 索引);SQLite 无 PostGIS 用 lat/lng 数值 + bbox 数值比较降级(geo_engine 接口隔离)。
  • API:/map/features CRUD + bbox 框选 / radius 半径 / aggregate/regions 网格聚合簇。

时间轴(timeline + Time-Wheel)

  • timeline_events 每行一个时间点事件(实体 + 时间维度 + 时间戳 + 标签 + 属性);实体类型的时间维度导入时自动注册。
  • API:时间范围查询、按粒度聚合(年/季/月/周/日/时)、单实体事件序列、多实体对比。
  • Time-Wheel 时间轮盘:按"小时 × 多天"环形包裹视图用于周期性检测(pattern-of-life);level-of-detail 缩放自动降采样,异常高峰红色高亮。

多视图联动(EventBus + SelectionExpr)

  • SelectionExpr:联动载荷 = 筛选表达式(filters[] 维度/算子/值 + mode: intersect|union|overwrite),各视图按自身数据键映射(地图键=geo_bbox、时间轴键=time_range、图键=entity_id/entity_type)。
  • 后端 cross_filter 统一参数:全部分析 API 支持;服务端 SelectionExprValidator 校验算子白名单(in/not_in/between/within/eq/neq/gte/lte)与值类型。
  • EventBusproducts/gotham/eventbus/):进程内 Publish/Subscribe 解耦 fusion/resolution/pattern;主题字典含 node.created / edge.created / entity.merged / graph.changed / alert.created 等,全部写 event_log
  • 三态视觉:selected / dimmed / neutral;前端 linkageBus + 去抖 300ms + 请求去重。
视图 API:/views/sessions CRUD + filter 应用/清除 + linked 联动查询 + /views/links 关联定义。

模式识别(pattern)

  • 规则类型:graph_pattern(基于 GraphStore BFS/模式遍历)、property_condition(属性条件)、statistical(时间窗口聚合 + Z-Score/IQR)、temporal(时序模式)、composite(AND/OR/NOT 组合)。
  • 检测调度:scheduler(cron)+ 事件触发(node.created/edge.created 实时检测)+ 手动。
  • 告警:去重(同 rule+entities 24h 一条)、聚合(共享核心实体归组)、打分(severity × confidence × freshness);状态机 new → acknowledged → investigating → resolved / false_positive。
  • 预置规则库:分散转入集中转出、资金快进快出、黑名单对手交易、同电话/地址多公司(围标)等。

情报报告(HTML / PDF / docx)

  • 报告模型reports.content 结构化 JSON 块(heading/paragraph/table/embedded_object),非纯 HTML → 支持多格式导出、搜索。
  • 嵌入对象(活文档)report_embedded_objects 存 query_params + data_snapshot + rendered_image(base64 PNG);导出时服务端用 query_params 重渲染,避免静态过期。
  • 导出引擎:PDF 主方案 = 后端 html/template 渲染 → 前端 window.print()(矢量保真、零服务端依赖);兜底 gofpdf(须先 AddFont 注册中文字体否则乱码);docx 用标准库 archive/zip + 固定 OpenXML 模板手写(不引 AGPL 的 unioffice)。
  • 模板:预置案件调查报告 / 情报分析简报 / 态势总览报告。

ABAC(两层模型 + deny 一票否决 + trace)

products/gotham/abac/:自研(<2000 行,不引 OPA/Casbin)RBAC 基础门 + ABAC 收窄两层模型

RBAC gate:permission = rbac.Check(user, resource, action)
  └─ deny → 403(短路,无 ABAC trace)
  └─ allow → ABAC 收窄:
      按 priority 降序评估 access_policies(effect=deny 一票否决,命中即终)
      全部 allow 策略条件不满足(require 语义,fail-closed)→ deny
      trace = {subject_attrs, resource_attrs, matched_policies[], decisions[]}
  → 通过后进入 RLS 数据级过滤(读路径 SQL/图遍历注入)
  • 四类属性(PIP):主体(user_id/role/department/clearance/project_ids)、资源(resource_type/classification/project_id/owner_id/tags)、操作(read/create/update/delete/export/…)、环境(time_of_day/ip/device_type)。
  • deny 一票否决且总是优先传播,默认 deny(白名单);评估返回 reasoning trace 入审计(G-ABAC4)。
  • 策略资源类型支持 ontology_action(Foundry Action Type),图合并/解析审核/报告发布等写操作按 Action 授权(R2 红线)。
  • RBAC 基础门在 server 组装时注入(admin 角色放行全部;非 admin 对 delete/export/write 类高危动作默认拒绝)。

错误示例:{code:"GOTHAM_ABAC_DENIED", data:{decision:"deny", trace:{...}}}

图谱域:行级图谱化导入 / 图分区压缩 / 时序图分析(V5,B4)

行级图谱化导入(gotham/fusion/graph_mapping.go,B4-1)

  • 连接器扩展 platform/connector/keyset.go:可选接口 KeysetReader.ReadKeyset(WHERE pk>last 循环分页)+ DetectForeignKeys(PG/MySQL 读 referential_constraints、SQLite 读 PRAGMA foreign_key_list),MySQL/PostgreSQL/SQLite 三实现,不支持时明确错误;
  • 映射配置 gf_graph_mappings(node_label_col/node_id_col/node_type/prop_cols/time_col/edge_rules/chunk_size);keyset 分批拉行 → 构造 GraphNode(ID=<type>:<pk>,Props+source 标注)→ UpsertNode;按 edge_rules 对 FK 列生成 GraphEdge(Props 含 occurrence_time);
  • IngestAsync 融合:ingestTaskRunner 落库后追加图谱化步骤(进度 0.6~1.0),未配置映射完整退化为既有行为;
  • API:GET|PUT /ingestion/sources/:id/graph-mappingPOST /ingestion/sources/:id/map-to-graph(任务化)、GET /ingestion/sources/:id/mapping-suggest(外键自动建议)。

图分区与压缩(gotham/analysis/partition.go,B4-2)

  • DetectPartition:多层折叠 Louvain(层间 foldWeighted 折叠,取模块度最高层)+ 小社区合并(<MinCommunitySize 并入共享边权最大邻居,孤立豁免)+ 并行 Phase1(确定性归并);CompressGraph 输出 CommunityGraph{Nodes, Edges}
  • 缓存 ga_partitions(id=归一化参数 JSON SHA-256 前 16 字节,参数幂等命中,OnConflict upsert);
  • 修复 Louvain 确定性 bug(平局按 map 迭代序随机 → 按 size+minMember 字典序确定);
  • API:POST /analysis/graph/partitionGET /analysis/graph/partitions(admin-only)。

时序图分析(gotham/analysis/temporal.go,B4-3)

  • TemporalSubgraph:边 Props["occurrence_time"] RFC3339 时窗过滤,节点保留两端至少一条边命中者;TemporalTrend:day/week/month 桶统计 Nodes/Edges 新增;PathWithTime:时窗子图快照复用 ShortestPathWeighted;
  • API:POST /analysis/graph/temporal/subgraph|trend|path(admin-only);
  • 回归红线:analysis 既有算法文件与 graph 包零修改。
图谱域三功能前端页:/gotham/graph-mapping(图谱映射)、/gotham/graph-partition(图分区压缩)、/gotham/temporal(时序分析);GothamLayout 侧边栏新增「图谱域」分组。

HTTP API 分组(/api/v1)

分组路径
图谱 / 分析/graph/nodes|edges|stats|neighbors/analysis/graph/expand|path|centrality|community|pagerank|closeness|label-propagation|scc|subgraph|stats
图谱域(v5)/ingestion/sources/:id/graph-mapping|map-to-graph|mapping-suggest/analysis/graph/partition|partitions/analysis/graph/temporal/subgraph|trend|path(admin)
数据接入/ingestion/sources|batches|entities
实体解析/resolution/jobs + clusters/pairs/stats
地图 / 时间轴/map/features + bbox/radius、/timeline/events + range/aggregate
模式识别/patterns/rules + evaluate/evaluate-all/hits
情报报告/reports CRUD + publish/archive/generate + /reports/:id/html|pdf|docx
ABAC / 联动/access-policies + evaluate/traces、/views/sessions + filter/linked/links

demo seed 幂等重建:Person/Organization/Event 节点 + transferred_to/uses 边、地理/时间轴/模式/报告/ABAC 策略。