feat: protocol base lib + rule-based parser MVP + 31 tests
This commit is contained in:
@ -44,64 +44,35 @@
|
||||
|
||||
### 推理路径张量格式
|
||||
|
||||
```json
|
||||
{
|
||||
"header": {
|
||||
"source": "logic_trace",
|
||||
"target": "core",
|
||||
"tensor_type": "reasoning_path",
|
||||
"trace_id": "trace-uuid",
|
||||
"timestamp": 1717200000
|
||||
},
|
||||
"payload": {
|
||||
"reasoning_steps": [
|
||||
{
|
||||
"step_id": 1,
|
||||
"type": "deduction",
|
||||
"input": "用户想要查询天气",
|
||||
"operation": "提取地点和时间信息",
|
||||
"output": "地点: 北京, 时间: 今天",
|
||||
"confidence": 0.95,
|
||||
"source_evidence": ["memory:偏好_北京天气"]
|
||||
},
|
||||
{
|
||||
"step_id": 2,
|
||||
"type": "retrieval",
|
||||
"input": "需要天气数据",
|
||||
"operation": "查询记忆子网获取北京天气偏好",
|
||||
"output": "用户关注空气质量>温度",
|
||||
"confidence": 0.88,
|
||||
"source_evidence": ["graph:用户_北京_HAS_PERSONA_关注空气质量"]
|
||||
},
|
||||
{
|
||||
"step_id": 3,
|
||||
"type": "verification",
|
||||
"input": "步骤1-2结果",
|
||||
"operation": "交叉验证",
|
||||
"output": "结论一致",
|
||||
"confidence": 0.92,
|
||||
"source_evidence": ["cross_validation"]
|
||||
}
|
||||
],
|
||||
"final_confidence": 0.92,
|
||||
"alternative_paths": [
|
||||
{
|
||||
"path_id": "alt_1",
|
||||
"conclusion": "用户可能不在北京(上次对话提到出差)",
|
||||
"confidence": 0.45,
|
||||
"rejection_reason": "信息过时(3天前的记录)"
|
||||
}
|
||||
],
|
||||
"verified": true,
|
||||
"error_log": []
|
||||
},
|
||||
"metadata": {
|
||||
"step_count": 3,
|
||||
"mcts_iterations": 50,
|
||||
"search_depth": 5,
|
||||
"verification_status": "passed"
|
||||
}
|
||||
}
|
||||
遵循统一通信张量协议,**无 JSON 结构**,全部为纯数值张量:
|
||||
|
||||
```
|
||||
统一通信张量 (纯数值)
|
||||
prefix: [fmt_id=4, parser_id=4]
|
||||
payload:
|
||||
[n_steps] # 推理步数
|
||||
[step_embeddings...] # 每步的语义嵌入 [n_steps, 768]
|
||||
[step_confidences...] # 每步置信度 [n_steps]
|
||||
[search_depth, mcts_iters, verified] # 元信息 [3]
|
||||
```
|
||||
|
||||
**编码示例(内部推理路径 → 统一张量)**:
|
||||
|
||||
```python
|
||||
def encode_reasoning_path(steps: list[Step],
|
||||
depth: int, iters: int) -> Tensor:
|
||||
"""内部推理路径 → 统一通信张量"""
|
||||
n = len(steps)
|
||||
step_vecs = [encode_step_io(s) for s in steps] # 每步编码
|
||||
confs = [s.confidence for s in steps]
|
||||
|
||||
payload = concat(
|
||||
tensor([n]), # 步数
|
||||
stack(step_vecs).flatten(), # 步嵌入
|
||||
tensor(confs), # 置信度
|
||||
tensor([depth, iters, 1.0 if verified]) # 元信息
|
||||
)
|
||||
return codec.encode(fmt_id=4, parser_id=4, data=payload)
|
||||
```
|
||||
|
||||
## 子网内部架构
|
||||
|
||||
Reference in New Issue
Block a user