什么是信号驱动决策?
信号驱动决策是语义路由的核心架构:从请求中提取多种信号并组合它们,以做出更优的路由决策。
核心思想
传统路由往往依赖单一信号:
# 传统:单一分类模型
if classifier(query) == "math":
route_to_math_model()
信号驱动路由组合多种信号:
# 信号驱动:多信号组合
if (keyword_match AND domain_match) OR high_embedding_similarity:
route_to_math_model()
为何重要:多信号共同「投票」比任何单一信号都更可靠。
十三类信号
1. 关键词信号
- 含义:支持 AND/OR 的快速模式匹配
- 延迟:小于 1ms
- 场景:确定性路由、合规、安全
signals:
keywords:
- name: "math_keywords"
operator: "OR"
keywords: ["calculate", "equation", "solve", "derivative"]
示例:「Calculate the derivative of x^2」→ 匹配「calculate」与「derivative」
2. 嵌入信号
- 含义:用语义嵌入衡量相似度
- 延迟:10–50ms
- 场景:意图识别、同义改写
signals:
embeddings:
- name: "code_debug"
threshold: 0.70
candidates:
- "My code isn't working, how do I fix it?"
- "Help me debug this function"
示例:「Need help debugging this function」→ 相似度 0.78 → 命中
3. 领域信号
- 含义:MMLU 领域分类(14 类)
- 延迟:50–100ms
- 场景:学术与专业领域路由
signals:
domains:
- name: "mathematics"
mmlu_categories: ["abstract_algebra", "college_mathematics"]
示例:「Prove that the square root of 2 is irrational」→ 数学领域
4. 事实核查信号
- 含义:基于 ML 检测是否需要事实核验
- 延迟:50–100ms
- 场景:医疗、金融、教育
signals:
fact_checks:
- name: "factual_queries"
threshold: 0.75
示例:「What is the capital of France?」→ 需要事实核查
5. 用户反馈信号
- 含义:对用户反馈与纠正进行分类
- 延迟:50–100ms
- 场景:客服、自适应学习
signals:
user_feedbacks:
- name: "negative_feedback"
feedback_types: ["correction", "dissatisfaction"]
示例:「That's wrong, try again」→ 检测到负面反馈
6. 偏好信号
- 含义:基于 LLM 的路由偏好匹配
- 延迟:200–500ms
- 场景:复杂意图分析
signals:
preferences:
- name: "creative_writing"
llm_endpoint: "http://localhost:8000/v1"
model: "gpt-4"
routes:
- name: "creative"
description: "Creative writing, storytelling, poetry"
示例:「Write a story about dragons」→ 偏好创意路由
7. 语言信号
- 含义:多语言检测(100+ 种语言)
- 延迟:小于 1ms
- 场景:将查询路由到语言专用模型或应用语言策略
signals:
language:
- name: "en"
description: "English language queries"
- name: "es"
description: "Spanish language queries"
- name: "zh"
description: "Chinese language queries"
- name: "ru"
description: "Russian language queries"
- 示例 1:「Hola, ¿cómo estás?」→ 西班牙语(es)→ 西语模型
- 示例 2:「你好,世界」→ 中文(zh)→ 中文模型
8. 上下文信号
- 含义:基于 token 数量的长短请求路由
- 延迟:约 1ms(处理过程中计算)
- 场景:长上下文请求路由到大窗口模型
- 指标:用
llm_context_token_count直方图记录输入 token 数
signals:
context_rules:
- name: "low_token_count"
min_tokens: "0"
max_tokens: "1K"
description: "Short requests"
- name: "high_token_count"
min_tokens: "1K"
max_tokens: "128K"
description: "Long requests requiring large context window"
示例:5000 token 的请求 → 命中「high_token_count」→ 路由到 claude-3-opus
9. 复杂度信号
- 含义:基于嵌入的查询难度分类(难/易/中)
- 延迟:50–100ms(嵌入计算)
- 场景:复杂查询用大模型,简单查询用高效模型
- 逻辑:两步分类:
- 将查询与规则描述比对,找出最匹配规则
- 在该规则内用难/易候选嵌入判定难度
signals:
complexity:
- name: "code_complexity"
threshold: 0.1
description: "Detects code complexity level"
hard:
candidates:
- "design distributed system"
- "implement consensus algorithm"
- "optimize for scale"
easy:
candidates:
- "print hello world"
- "loop through array"
- "read file"
示例:「How do I implement a distributed consensus algorithm?」→ 匹配「code_complexity」→ 与 hard 候选高相似 → 输出「code_complexity:hard」
机制:
- 查询嵌入与各规则描述比对
- 选取描述相似度最高的规则
- 在该规则内与 hard/easy 候选比对
- 难度信号 = max_hard_similarity − max_easy_similarity
- 若信号 > 阈值 →「hard」;若 < −阈值 →「easy」;否则 →「medium」
10. 模态信号
- 含义:判断提示是纯文本(AR)、图像生成(DIFFUSION)或二者(BOTH)
- 延迟:50–100ms(内联模型推理)
- 场景:将创意/多模态提示路由到专用生成模型
signals:
modality:
- name: "image_generation"
description: "Requests that require image synthesis"
- name: "text_only"
description: "Pure text responses with no image output"
示例:「Draw a sunset over the ocean」→ DIFFUSION → 图像生成模型
机制:在 inline_models 下配置的模态检测器用小分类器判定输出是文本、图像或两者;结果作为信号发出,决策中通过规则的 name 引用。