Core Components: - PDFStorageService with Dify/OSS adapters - LLM12FieldsService with Nougat-first + dual-model + 3-layer JSON parsing - PromptBuilder for dynamic prompt assembly - MedicalLogicValidator with 5 rules + fault tolerance - EvidenceChainValidator for citation integrity - ConflictDetectionService for dual-model comparison Prompt Engineering: - System Prompt (6601 chars, Section-Aware strategy) - User Prompt template (PICOS context injection) - JSON Schema (12 fields constraints) - Cochrane standards (not loaded in MVP) Key Innovations: - 3-layer JSON parsing (JSON.parse + json-repair + code block extraction) - Promise.allSettled for dual-model fault tolerance - safeGetFieldValue for robust field extraction - Mixed CN/EN token calculation Integration Tests: - integration-test.ts (full test) - quick-test.ts (quick test) - cached-result-test.ts (fault tolerance test) Documentation Updates: - Development record (Day 2-3 summary) - Quality assurance strategy (full-text screening) - Development plan (progress update) - Module status (v1.1 update) - Technical debt (10 new items) Test Results: - JSON parsing success rate: 100% - Medical logic validation: 5/5 passed - Dual-model parallel processing: OK - Cost per PDF: CNY 0.10 Files: 238 changed, 14383 insertions(+), 32 deletions(-) Docs: docs/03-涓氬姟妯″潡/ASL-AI鏅鸿兘鏂囩尞/05-寮€鍙戣褰?2025-11-22_Day2-Day3_LLM鏈嶅姟涓庨獙璇佺郴缁熷紑鍙?md
11 KiB
11 KiB
数据库全局视图
目的: 提供所有Schema和表的快速索引,便于查找和理解全局数据架构
详细设计: 请查看各模块的01-数据库设计.md
数据库: PostgreSQL 15+
最后更新: 2025-11-06
📊 Schema划分策略
Schema隔离原则 ⭐
为什么需要Schema隔离:
- ✅ 模块独立性:每个业务模块有独立的Schema
- ✅ 支持独立部署:可以单独导出某个模块的数据
- ✅ 权限隔离:可以为不同Schema设置不同权限
- ✅ 避免命名冲突:不同模块可以有相同的表名
Schema命名规范:
platform_schema # 平台基础层(全局共享)
aia_schema # AI智能问答
asl_schema # AI智能文献
pkb_schema # 个人知识库
dc_schema # 数据清洗整理
ssa_schema # 智能统计分析
st_schema # 统计分析工具
rvw_schema # 稿件审查系统
admin_schema # 运营管理端(可选,可合并到platform_schema)
📋 Schema一览表
| Schema | 说明 | 表数量 | 状态 | 详细设计 |
|---|---|---|---|---|
| platform_schema | 平台基础层 | ~15个 | ✅ 使用中 | 查看 |
| aia_schema | AI智能问答 | ~8个 | ✅ 使用中 | 查看 |
| pkb_schema | 个人知识库 | ~5个 | ✅ 使用中 | 查看 |
| rvw_schema | 稿件审查系统 | ~6个 | ✅ 使用中 | 查看 |
| asl_schema | AI智能文献 | ~10个 | ⏳ 设计中 | ASL/01-数据库设计 |
| dc_schema | 数据清洗整理 | ~8个 | ⏳ 规划中 | 待设计 |
| ssa_schema | 智能统计分析 | ~10个 | ⏳ 规划中 | 待设计 |
| st_schema | 统计分析工具 | ~5个 | ⏳ 规划中 | 待设计 |
总表数: ~70个(预估)
🔍 platform_schema(平台基础层)
职责: 存储全局共享的平台数据,所有业务模块都依赖
详细设计: UAM/01-数据库设计
核心表(用户与权限)
| 表名 | 说明 | 记录数预估 | 详细设计 |
|---|---|---|---|
| users | 用户基础信息 | 10万/年 | UAM/01-数据库设计 |
| roles | 角色定义 | <100 | 同上 |
| permissions | 权限定义 | <500 | 同上 |
| user_roles | 用户-角色关联 | 10万/年 | 同上 |
| feature_flags | Feature Flag配置 ⭐ | <100 | 同上 |
| user_feature_flags | 用户-Feature Flag关联 ⭐ | 10万/年 | 同上 |
LLM相关表
| 表名 | 说明 | 记录数预估 | 详细设计 |
|---|---|---|---|
| llm_models | LLM模型配置 | <20 | LLM网关/01-数据库设计 |
| llm_usage | LLM使用记录 ⭐ | 1000万/年 | 同上 |
| llm_quotas | LLM配额管理 | 10万/年 | 同上 |
监控与日志
| 表名 | 说明 | 记录数预估 | 详细设计 |
|---|---|---|---|
| admin_logs | 管理员操作日志 | 10万/年 | 监控与日志/01-数据库设计 |
| error_logs | 错误日志 | 100万/年 | 同上 |
| audit_logs | 审计日志 | 100万/年 | 同上 |
系统配置
| 表名 | 说明 | 记录数预估 | 详细设计 |
|---|---|---|---|
| system_configs | 系统配置 | <100 | 系统配置/01-数据库设计 |
| prompt_templates | Prompt模板 | <500 | 同上 |
| announcements | 系统公告 | <1000 | 同上 |
🤖 aia_schema(AI智能问答)
职责: 存储AI智能问答相关数据(12个智能体、对话历史)
状态: ✅ 已实现
详细设计: AIA/01-数据库设计(待创建)
核心表
| 表名 | 说明 | 记录数预估 |
|---|---|---|
| conversations | 对话会话 | 100万/年 |
| messages | 对话消息 | 1000万/年 |
| agents | 智能体配置 | <20 |
| conversation_contexts | 对话上下文 | 100万/年 |
📚 pkb_schema(个人知识库)
职责: 存储个人知识库、文档、RAG问答相关数据
状态: ✅ 已实现
详细设计: PKB/01-数据库设计(待创建)
核心表
| 表名 | 说明 | 记录数预估 |
|---|---|---|
| knowledge_bases | 知识库 | 30万/年 |
| documents | 文档 | 300万/年 |
| document_chunks | 文档分块(向量化) | 3000万/年 |
| kb_conversations | 知识库对话 | 100万/年 |
| kb_messages | 知识库对话消息 | 1000万/年 |
📄 rvw_schema(稿件审查系统)
职责: 存储稿件审查、评估报告相关数据
状态: ✅ 已实现(独立系统)
详细设计: RVW/01-数据库设计(待创建)
核心表
| 表名 | 说明 | 记录数预估 |
|---|---|---|
| review_tasks | 审查任务 | 10万/年 |
| manuscripts | 稿件信息 | 10万/年 |
| review_results | 审查结果 | 10万/年 |
| methodology_assessments | 方法学评估 | 10万/年 |
| guideline_assessments | 稿约规范性评估 | 10万/年 |
📖 asl_schema(AI智能文献)
职责: 存储文献筛选、提取、分析相关数据
状态: ⏳ 设计中(P0优先级)
详细设计: ASL/01-数据库设计
核心表(预览)
| 表名 | 说明 | 记录数预估 |
|---|---|---|
| literature_projects | 文献项目 | 10万/年 |
| literature_items | 文献条目 | 1000万/年 |
| pico_configs | PICO纳入排除标准 | 10万/年 |
| screening_results | 筛选结果 | 1000万/年 |
| screening_history | 筛选历史(可回溯) | 1000万/年 |
| extraction_tasks | 提取任务 | 100万/年 |
| extraction_results | 提取结果 | 100万/年 |
🧹 dc_schema(数据清洗整理)
职责: 存储数据清洗任务、ETL配置、NER结果
状态: ⏳ 规划中(P1优先级)
详细设计: 待设计
核心表(预览)
| 表名 | 说明 | 记录数预估 |
|---|---|---|
| cleaning_projects | 清洗项目 | 10万/年 |
| data_sources | 数据源 | 100万/年 |
| etl_configs | ETL配置 | 10万/年 |
| ner_tasks | NER任务 | 100万/年 |
| ner_results | NER结果 | 1000万/年 |
🔗 跨Schema依赖关系
依赖规则 ⭐ 重要
允许的依赖:
✅ 业务模块 → platform_schema(允许外键)
✅ 通用能力 → platform_schema(允许外键)
❌ 业务模块之间(禁止直接依赖)
❌ platform_schema → 业务模块(反向依赖)
依赖关系图
platform_schema.users (1)
↓ (N) 所有业务模块都依赖用户表
├── aia_schema.conversations
├── asl_schema.literature_projects
├── pkb_schema.knowledge_bases
├── dc_schema.cleaning_projects
├── ssa_schema.analysis_projects
├── st_schema.tool_usage
└── rvw_schema.review_tasks
platform_schema.llm_usage (独立)
- 记录所有模块的LLM调用
- 通过module字段区分:'AIA', 'ASL', 'PKB'等
外键示例
-- ✅ 允许:业务模块引用platform_schema
CREATE TABLE asl_schema.literature_projects (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES platform_schema.users(id) ON DELETE CASCADE
);
-- ❌ 禁止:业务模块之间互相引用
CREATE TABLE ssa_schema.analysis_projects (
id SERIAL PRIMARY KEY,
-- 错误:不能引用其他业务模块
literature_project_id INTEGER REFERENCES asl_schema.literature_projects(id)
);
-- ✅ 正确做法:通过user_id关联
-- 在应用层处理跨模块关联,不在数据库层
📊 数据量统计(预估)
按Schema统计
| Schema | 表数量 | 年增长记录数 | 存储预估(5年) |
|---|---|---|---|
| platform_schema | 15 | 1000万 | 50GB |
| aia_schema | 8 | 1100万 | 30GB |
| pkb_schema | 5 | 3300万 | 200GB(向量) |
| rvw_schema | 6 | 50万 | 5GB |
| asl_schema | 10 | 2100万 | 50GB |
| dc_schema | 8 | 1100万 | 100GB |
| ssa_schema | 10 | 500万 | 50GB |
| st_schema | 5 | 100万 | 10GB |
| 总计 | ~70 | ~4000万/年 | ~500GB(5年) |
大表监控(年增长>100万)
| 表名 | Schema | 年增长 | 索引策略 |
|---|---|---|---|
| llm_usage | platform | 1000万 | 按月分区 |
| messages | aia | 1000万 | 按created_at索引 |
| document_chunks | pkb | 3000万 | 向量索引 |
| literature_items | asl | 1000万 | 按project_id索引 |
| screening_results | asl | 1000万 | 复合索引 |
🔍 快速查找指南
场景1:我要开发某个模块
- 在上面的表格中找到对应的Schema
- 点击"详细设计"链接
- 查看该模块的完整表结构
场景2:我要查看某个表的结构
- 先确定表属于哪个Schema(根据功能判断)
- 转到对应模块的数据库设计文档
- 搜索表名
场景3:我要设计跨模块功能
- 查看本文档的"跨Schema依赖关系"
- 遵循依赖规则
- 在应用层处理跨模块关联,不在数据库层
场景4:我要查看全局数据架构
- 阅读本文档(快速了解所有Schema)
- 查看架构设计全景图
⚠️ 重要提醒
Schema隔离的注意事项
✅ 正确做法:
- 业务模块只引用
platform_schema.users - 跨模块数据关联在应用层处理
- 使用
user_id + 业务ID的方式
❌ 错误做法:
- 业务模块之间直接外键关联
- 在
platform_schema中存储业务数据 - 不同模块使用相同的表名(虽然Schema隔离了,但容易混淆)
性能优化建议
- 大表必须分页查询(如
llm_usage、messages) - 热点字段必须加索引(如
user_id、created_at) - 考虑表分区(按月/按年,如
llm_usage) - 定期归档历史数据(如1年前的日志)
🔗 相关文档
规范:
模块设计:
模板:
最后更新: 2025-11-06
维护人: 技术架构师
版本: v1.0