Files
myWiki/concepts/hierarchical-semantic-routing.md

64 lines
1.9 KiB
Markdown
Raw 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.

---
title: "层次语义路由 — Hierarchical Semantic Routing"
created: 2026-06-19
updated: 2026-06-19
type: concept
tags: [semantic-routing, retrieval, mcp-zero, two-stage, hierarchical]
sources:
- https://arxiv.org/abs/2506.01056
---
# 层次语义路由Hierarchical Semantic Routing
## 定义
Hierarchical Semantic Routing 是 MCP-Zero 的两级粗到细检索算法:先在 server 层面过滤候选,再在 tool 层面精确排序。将搜索复杂度从 O(n) 降至 O(m+k)m+k ≪ n。
## 两级流程
```
Active Tool Request
第一级Server 匹配
├── 原始 server description 匹配
├── 增强 server summary 匹配(含使用示例)
└── 取两者较高相似度
第二级Tool 排序
└── 在选中 server 内按语义相似度排序
返回 top-k tools
```
## 评分公式
```
score = (s_server × s_tool) × max(s_server, s_tool)
```
其中 s_server 和 s_tool 是 server 和 tool 级别的余弦相似度。
乘法项保证**只有两级都高相似才得高分**max 项让**某一维度特别强时也能被召回**——平衡精度和召回。
## 增强摘要策略
Server 描述通常只有简短一句话。MCP-Zero 为每个 server 构建了包含综合使用示例的增强摘要,在匹配时同时使用原始描述和增强摘要,取更高相似度——提升 server 级匹配精度。
## 复杂度分析
| | 被动方案 | 层次路由 |
|---|---|---|
| 复杂度 | O(n)n = 全部 tools | O(m+k)m ≪ n |
| 注意力分布 | 1/n per tool | 1/k per toolk ≪ n |
| 实例 (MCP-tools) | 2,797 tools | 308 servers → 每 server 平均 ~9 tools |
## 参考
- [[active-tool-discovery|主动工具发现]]
- [[active-tool-request|Active Tool Request]]
- [[fei-mcp-zero-2025|MCP-Zero 论文]]
- [[skill-retrieval|Skill 检索]](类比:层级检索 vs 层次路由)