Keyword Based Routing
本指南向您展示如何使用显式 keyword rule 和 regex 模式来路由请求。Keyword routing 提供透明、可审计的路由 decision,这对于 compliance、security 和需要可解释 AI 的场景至关重要。
关键优势
- 透明:路由 decision 完全可解释且可审计
- 合规:确定性行为满足监管要求(GDPR, HIPAA, SOC2)
- 快速:亚毫秒级 latency,无 ML 推理开销
- 可解释:清晰的 rule 使 debug 和验证变得简单直接
它解决了什么问题
基于 ML 的 classification 是一个难以审计和解释的黑箱。Keyword routing 提供:
- 可解释的 decision:确切知道为什么一个查询被路由到特定 category
- 监管 compliance:审计人员可以验证路由逻辑是否符合要求
- 确定性行为:相同的 input 始终产生相同的 output
- 零 latency:无需 model 推理,瞬时 classification
- 精确控制:针对 security、compliance 和业务 逻辑的显式 rule
何时使用
- 需要 audit trail 的受监管行业(金融、医疗、法律)
- 需要确定性 PII 检测的security/compliance场景
- 亚毫秒级 latency 至关重要的高吞吐量系统
- 具有清晰 keyword 指示的紧急/优先级路由
- 匹配 regex 模式的结构化数据(email、ID、文件路径)
配置
在您的 config.yaml 中添加 keyword signal:
# 定义 keyword signal
signals:
keywords:
- name: "urgent_keywords"
operator: "OR" # 匹配任意关键词
keywords: ["urgent", "immediate", "asap", "emergency", "紧急"]
case_sensitive: false
- name: "sensitive_data_keywords"
operator: "OR"
keywords: ["SSN", "social security", "credit card", "password", "身份证"]
case_sensitive: false
- name: "spam_keywords"
operator: "OR"
keywords: ["buy now", "free money", "click here", "免费领取"]
case_sensitive: false
# 使用 keyword signal 定义 decision
decisions:
- name: urgent_request
description: "路由紧急请求"
priority: 100 # 高优先级
rules:
operator: "OR"
conditions:
- type: "keyword"
name: "urgent_keywords"
modelRefs:
- model: "openai/gpt-oss-120b"
use_reasoning: false
plugins:
- type: "system_prompt"
configuration:
system_prompt: "你是一位响应迅速的助手,专门处理紧急请求。"
- name: sensitive_data
description: "路由敏感数据查询"
priority: 90
rules:
operator: "OR"
conditions:
- type: "keyword"
name: "sensitive_data_keywords"
modelRefs:
- model: "openai/gpt-oss-120b"
use_reasoning: false
plugins:
- type: "system_prompt"
configuration:
system_prompt: "你是一位具有安全意识的助手,专门处理敏感数据。"
- name: filter_spam
description: "拦截垃圾查询"
priority: 95
rules:
operator: "OR"
conditions:
- type: "keyword"
name: "spam_keywords"
modelRefs:
- model: "openai/gpt-oss-120b"
use_reasoning: false
plugins:
- type: "system_prompt"
configuration:
system_prompt: "此查询似乎是垃圾信息。请提供礼貌的回复。"