Files
InternalAuditInterprise/docs/adr/ADR-0002-data-platform-modeling.md
2026-06-16 00:38:57 +08:00

34 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ADR-0002 · 数据中台建模决策(本体 / 双时态 / 时序 / 图谱)
> 项目:AIAudit 状态:已接受(MVP 日期:2026-06
> 关联:`0-req-AIAudit.md`R2、R3)、任务 P1.2 / P1.3
## 背景
审计数据中台需同时满足:①按审计本体组织实体与关系(知识图谱穿透);②双时态建模(业务时间+系统时间,可回放历史);③时间序列(时序造假识别)。需在能力与可靠性/组件数之间平衡。
## 决策
### 1. 本体与知识图谱:关系表 + 递归 CTE(MVP)
-`entity`(实体)+ `entity_relationship`(关系边)两张通用表承载审计本体,实体类型与关系类型由 `ontology_entity_type` / `ontology_relationship_type` 字典定义。
- 多跳穿透(如实控人识别)用 PostgreSQL **递归 CTE** 实现。
- 不在 MVP 引入 Apache AGE,规避源码编译的构建脆弱性;后续多跳压力增大再评估迁移到 AGE/Neo4j。
### 2. 双时态建模
- 关键审计对象采用双时态:
- 业务有效期:`valid_from` / `valid_to`(应用时间)。
- 系统记录期:`system_from` / `system_to`(事务时间)。
-`tstzrange` + `btree_gist` 排他约束防止同一实体业务有效期重叠。
- "按任意历史时点回放"= 给定 `(as_of_valid, as_of_system)` 过滤两条时间线。
### 3. 时间序列
- 行为/指标类数据(用户生命周期事件、回款、话务、佣金、资源使用)写入 `metric_event` 等表。
- 生产环境(Linux)用 TimescaleDB `create_hypertable` 转为超表,按时间分区/压缩。
- **本地开发(macOS**:因 TimescaleDB 在 macOS 上 Homebrew 编译不稳定,本地跳过该扩展,`metric_event` 作为普通索引表使用;超表转换在迁移中条件执行(扩展存在才转),**不影响功能**,仅少了规模优化。
### 4. 数据版本与可追溯
- 每批数据落地登记 `data_version`(来源、批次、时间、行数),业务记录引用 `data_version_id`,使任一结论可回溯到当时数据版本(R3)。
## 影响
- MVP 仅依赖 TimescaleDB + pgvector + btree_gist,镜像可靠(`timescaledb-ha:pg16` 内置)。
- 图能力以关系建模实现,接口层(统一穿透查询服务)对上层屏蔽底层是关系还是图库,便于将来替换。