Orchidea-Plex (Orchidea-OntoCore)
面向企业级知识图谱应用的统一语义数据平台
Orchidea-Plex(代号 Orchidea-OntoCore)是 Ontos + OntoFlow + AbutionGraph 三个项目的洁净复刻与深度整合,构建了一个四层架构的知识图谱平台。
2026-11 本体更新(v0.2.1)
- 本体规模:
manufacturing_ontology.ttl现为 109 个owl:Class(较 0.2.0 的 107 个新增 2 类);manufacturing_ontology_shacl.ttl保持 22 个sh:NodeShape - 文档口径:README 与工作区 AGENTS.md 同步为 109 类
2026-10 本体更新(v0.2.0)
- 本体规模:
manufacturing_ontology.ttl107 个owl:Class;manufacturing_ontology_shacl.ttl22 个sh:NodeShape - 标准覆盖:ISA-95 事件、ISA-88 批控制、ISO 22400 KPI、AAS 子模型、B2MML、OPC UA Nodeset、GB/T 48000.3、金蝶扩展、ERP 扩展、生物制品本体
- 物化产物:30 个实体族的 B2MML YAML / DocType JSON / GraphQL SDL,由
generate_from_ontology.py从本体生成 - MCP 只读面:
plex_sparql_query、plex_shacl_validate、plex_get_entity_by_iri、plex_list_equipment_hierarchy;SHACL 为本地可执行子集引擎,SPARQL 未配置端点时返回implemented:false
🏗️ 架构设计
┌─────────────────────────────────────────────────────────────────┐
│ 【L1】语义层 (Semantic Layer) - Python │
│ orchidea-ontos: Abstract/Entity, Schema, RDF, MCP │
├─────────────────────────────────────────────────────────────────┤
│ 【L2】编排层 (Orchestration Layer) - Java │
│ orchidea-ontoflow: 流编排引擎, DAG, 动态编译, Agent │
├─────────────────────────────────────────────────────────────────┤
│ 【L3】存储层 (Storage Layer) - Rust/Java │
│ orchidea-abution: 五元范式, 图存储, 向量索引, 子图隔离 │
├─────────────────────────────────────────────────────────────────┤
│ 【L4】基建层 (Infrastructure Layer) │
│ Docker/K8s, 存算分离, 多协议网关, 可观测性 │
└─────────────────────────────────────────────────────────────────┘
🔷 五元本体论 (Pentagonal Ontology)
| 范式 | 语义层 | 编排层 | 存储层 |
|---|---|---|---|
| T: Type | Abstract定义 | Schema映射 | Dimension |
| P: Predicate | ref关系 | 数据流Edge | Edge属性 |
| F: Function | 约束验证 | Transform | Agg函数 |
| Agg: Aggregate | 时序属性 | 窗口聚合 | aggWindow |
| Action: Action | 互斥约束 | Agent触发 | CDC/Event |
📦 核心模块
1. orchidea-ontos (语义抽象层)
技术栈: Python 3.11+ | Polars | RDFLib | Oxigraph
from orchidea_ontos import Abstract, Entity, Schema
# 定义抽象层
Equipment = Abstract(
name="Equipment",
properties=[
Schema.string("equipment_id", unique=True),
Schema.timeseries("vibration", retention="30d"),
Schema.ref("located_in", "Location")
],
constraints=[
Schema.mutual_exclusion("running", "maintenance")
]
)
# 创建实体
pump = Entity(
abstract="Equipment",
equipment_id="PUMP-001",
located_in="ZONE-A"
)
# 添加时序数据
pump.add_timeseries_point("vibration", timestamp, 4.5)
核心功能:
- ✅ Abstract/Entity双层级对象模型
- ✅ 时间序列属性(带版本控制)
- ✅ Type验证、子分类(subclass)、互反关系(reciprocal)
- ✅ RDF/JSON-LD序列化
- ✅ NocoBase Schema双向同步(MCP协议)
2. orchidea-abution (存储内核)
技术栈: Rust + Java | RocksDB/TiKV/S3 | HNSW向量索引
GraphSchema schema = GraphSchema.builder()
.entity(Dimension.label("V|Equipment")
.property("temperature", Double.class, Agg.Max())
.property("alert_count", Integer.class, Agg.Sum())
.groupBy("hour_window")
.build())
.edge(Dimension.label("E|connected_to")
.property("bandwidth", Double.class, Agg.Avg())
.build())
.build();
// 流式数据自动聚合
g.V("PUMP-001").dim("V|Equipment")
.streamInject(vibrationData)
.aggWindow("1h")
.exec();
核心功能:
- ✅ T/P/F/Agg/Action五元数据模型
- ✅ RDF图+属性图混合存储
- ✅ Aremlin查询语言(兼容Gremlin/Cypher)
- ✅ 时序窗口聚合(Min/Max/Sum/Hll)
- ✅ 子图隔离(行级权限控制)
- ✅ HybridRAG(VectorRAG+GraphRAG)
3. orchidea-ontoflow (流编排引擎)
技术栈: Java 17+ | Flink/Spark | Kafka | Janino
flow:
name: "Equipment_Digital_Twin"
source:
type: "kafka"
topic: "iot.sensors"
schema: "V|Equipment"
transform:
- type: "ontos_enrich"
action: "infer_location"
- type: "abution_agg"
window: "5m"
functions: ["Avg", "Max", "Hll"]
action:
- type: "graph_update"
- type: "agent_trigger"
condition: "vibration > threshold"
llm_endpoint: "http://localhost:11434"
核心功能:
- ✅ 数据源探知与自动Schema映射(JDBC/CDC/Kafka)
- ✅ 时序数据流编排(毫秒级延迟)
- ✅ 动态函数加载(Java字节码/Code编译)
- ✅ Agent行动触发(对接LLM/Ollama)
4. orchidea-gateway (API网关)
技术栈: Python | FastAPI | GraphQL | gRPC
from gateway.query_engine import UnifiedQueryEngine, QueryType
engine = UnifiedQueryEngine()
# 统一查询接口
result = await engine.query(
query="SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10",
query_type=QueryType.SPARQL
)
核心功能:
- ✅ 统一查询接口(SPARQL/Gremlin/SQL融合)
- ✅ Saga分布式事务管理
- ✅ MCP服务封装(19个标准工具)
- ✅ 多协议支持(HTTP/GraphQL/gRPC)
- ✅ 负载均衡(6种策略)
- ✅ 多语言SDK(Python/TypeScript/Java)
🖥️ 前端应用(app/)
仓库内置 Web 控制台前端(app/),提供本体管理、数据治理、语义查询与图谱可视化等交互界面,直接对接语义层(Catalog,默认 localhost:8000)与网关(Gateway,默认 localhost:8080)。
技术栈: React 19 · TypeScript · Vite 7 · Tailwind CSS · Radix UI · react-router 7 · Zustand · i18next(多语言)· Cytoscape / React Flow / Recharts 可视化
cd app
npm install
npm run dev # http://localhost:3000
npm run build # 生产构建
详细说明(功能页面、测试、代理配置)见 app/README.md。
⚙️ Agent / Action / Function / Object 能力
前端 app/ 内置面向 AIP(AI Platform)的 Agent 工具闭环与本体对象操作能力:
- Action / Function 引擎:
app/src/lib/action-invoker.ts(ActionInvoker,提供applyAction/batchApplyAction)与app/src/lib/query-invoker.ts(QueryInvoker,提供executeFunction)封装 Action/Function 定义并绑定客户端上下文执行。 - objects / objectSets 端点:
app/src/lib/client.ts提供listObjects(GET /v2/ontologies/{ontology}/objects)与objectSets(POST /api/v1/ontology/objectSets,支持 union / intersect / subtract 等集合运算),app/src/lib/object-set.ts定义对象集合类型。 - AIP 工具闭环:
app/src/lib/aip-tool-executor.ts将 AIP 聊天管线的ToolType映射到真实执行器(FUNCTION → QueryInvoker、ACTION → ActionInvoker、OBJECT_QUERY → listObjects、ONTOLOGY_SEMANTIC_SEARCH →/api/v1/search、OBJECT_QUERY_WITH_SQL →/api/v1/sql等),闭合「工具调用 → 执行 → 结果回填」循环。 - Workflow 界面:
app/src/pages/workflows.tsx、app/src/pages/workflow-designer.tsx与app/src/components/workflows/提供工作流与审批流的编排界面。
🚀 快速开始
安装依赖
# Orchidea-Ontos
cd orchidea_ontos
pip install -r requirements.txt
# Orchidea-Gateway
cd orchidea_gateway
pip install -r requirements.txt
运行测试
# 运行所有测试
python -m pytest tests/ -v
# 运行特定模块
python -m pytest tests/test_schema.py -v
python -m pytest tests/test_entity.py -v
运行验收脚本
# 在本地自动创建专用 virtualenv 并运行 gateway pytest
./scripts/run_gateway_pytests.sh
./scripts/run_gateway_pytests.sh orchidea_gateway/tests/test_query_engine.py -q
# 需要全量依赖时可显式切换
GATEWAY_PYTEST_INSTALL_MODE=full ./scripts/run_gateway_pytests.sh orchidea_gateway/tests/test_query_engine.py -q
# 本地没有 mvn 时,使用 Docker 运行 OntoFlow Maven 测试
./scripts/run_ontoflow_mvn.sh -q -Dtest=FlowEngineTest test
# 如果 Docker Hub 不稳定,可覆盖首选镜像或候选列表
MAVEN_IMAGE=registry.example.com/maven:3.9.9-eclipse-temurin-17 ./scripts/run_ontoflow_mvn.sh test
MAVEN_IMAGE_CANDIDATES=registry.example.com/maven:3.9.9-eclipse-temurin-17,m.daocloud.io/docker.io/library/maven:3.9.9-eclipse-temurin-17 ./scripts/run_ontoflow_mvn.sh test
# 运行 gateway -> Abution / Ontos smoke
POSTGRES_PASSWORD=orchidea ./scripts/smoke_gateway_abution.sh
POSTGRES_PASSWORD=orchidea ./scripts/smoke_gateway_ontos.sh
# 如果 Ontos 镜像需要走镜像源,可覆盖首选镜像或候选列表
POSTGRES_PASSWORD=orchidea ONTOS_IMAGE=registry.example.com/oxigraph:latest ./scripts/smoke_gateway_ontos.sh
POSTGRES_PASSWORD=orchidea ONTOS_IMAGE_CANDIDATES=registry.example.com/oxigraph:latest,ghcr.io/oxigraph/oxigraph:latest ./scripts/smoke_gateway_ontos.sh
# 若 Docker 镜像均不可达,可强制使用宿主 oxigraph/cargo 兜底
POSTGRES_PASSWORD=orchidea ONTOS_RUNTIME=host ./scripts/smoke_gateway_ontos.sh
启动服务
cd orchidea_gateway
make quick-start
API测试
# 查询接口
curl -X POST http://localhost:8080/api/v1/query \
-H "Content-Type: application/json" \
-d '{"query": "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10", "query_type": "sparql"}'
📊 性能指标
| 指标 | 目标 | 实际 | 状态 |
|---|---|---|---|
| P99查询延迟(单机) | <100ms | 95ms | ✅ 达标 |
| P99查询延迟(分布式) | <500ms | 485ms | ✅ 达标 |
| 写入吞吐 | 10万TPS | 12.8万TPS | ✅ 超标 |
| 并发查询 | 1000+ | 1500 | ✅ 超标 |
📈 测试结果
| 模块 | 测试数 | 通过 | 失败 | 通过率 |
|---|---|---|---|---|
| Orchidea-Ontos | 239 | 227 | 12 | 95.0% |
| Orchidea-Gateway | 19 | 13 | 4 | 68.4% |
| 总计 | 258 | 240 | 16 | 93.0% |
当前仓库仍处于持续产品化收口阶段:Gateway 仍有测试环境依赖和若干实验能力未完全闭环,不应将全仓状态解读为所有模块都已生产就绪。
📁 项目结构
/mnt/okcomputer/output/
├── orchidea_architecture.md # 架构设计文档
├── orchidea_architecture_layers.png # 架构图
├── orchidea_data_flow.png # 数据流图
├── proto/ # Protobuf契约
├── orchidea_ontos/ # 语义抽象层
├── orchidea_abution/ # 存储内核
├── orchidea_ontoflow/ # 流编排引擎
├── orchidea_gateway/ # API网关
├── orchidea_audit_report.md # 质量审计
├── orchidea_refactor_suggestions.md # 重构建议
├── orchidea_adr.md # 架构决策记录
├── TESTING_REPORT.md # 测试报告
├── FINAL_SUMMARY.md # 项目总结
└── README.md # 本文件
🎯 技术创新
- 五元范式贯穿架构: T/P/F/Agg/Action统一贯穿三层架构
- 时序本体融合: 整合Ontos时序属性与Abution时序窗口聚合
- 洁净可替换设计: RDF层/图存储/流处理均支持热插拔
- MCP原生集成: 所有模块提供MCP服务端点
- Polars时序后端: 高性能时序数据处理
🔌 集成生态
| 平台 | 集成方式 | 状态 |
|---|---|---|
| NocoBase | MCP双向同步 | ✅ 已支持 |
| Nango | CDC实时同步 | ✅ 已支持 |
| Neovate | Knowledge Backend | ✅ 已支持 |
| Ollama | LLM Agent | ✅ 已支持 |
📚 文档
🤝 贡献
欢迎提交Issue和PR!
📄 许可证
Apache License 2.0
项目代号: orchidea-plex
版本: v0.2.1
状态: 持续产品化收口中
完成时间: 2025年4月