分类器调优
本指南提供了在 vLLM 语义路由中调优分类阈值的快速配置方案。根据您的具体用例调整这些设置,以平衡精确率和召回率。
类别分类器阈值
调整领域分类的置信度阈值:
classifier:
category_model:
model_id: "models/lora_intent_classifier_bert-base-uncased_model"
threshold: 0.6 # 默认值:0.6
use_cpu: true
category_mapping_path: "models/lora_intent_classifier_bert-base-uncased_model/category_mapping.json"
| 阈值 | 行为 |
|---|---|
| 0.5 - 0.6 | 更宽松,更高召回率 |
| 0.7 - 0.8 | 平衡精确率/召回率 |
| 0.9+ | 非常严格,更少匹配 |
PII 检测阈值
配置 PII 检测器敏感度:
classifier:
pii_model:
model_id: "models/lora_pii_detector_bert-base-uncased_model"
threshold: 0.9 # 默认值:0.9(严格)
use_cpu: true
pii_mapping_path: "models/pii_classifier_modernbert-base_presidio_token_model/pii_type_mapping.json"
提示
在生产环境中使用较高阈值(0.9+)以最小化 PII 误报。
越狱检测阈值
调优提示词防护敏感度 :
prompt_guard:
enabled: true
use_modernbert: true
model_id: "models/jailbreak_classifier_modernbert-base_model"
threshold: 0.7 # 默认值:0.7
use_cpu: true
jailbreak_mapping_path: "models/jailbreak_classifier_modernbert-base_model/jailbreak_type_mapping.json"
| 阈值 | 权衡 |
|---|---|
| 0.5 - 0.6 | 激进拦截,更多误报 |
| 0.7 | 平衡(推荐) |
| 0.8 - 0.9 | 宽松,更少拦截 |
路由置信度阈值
微调智能路径选择:
router:
# 自动 LoRA 选择的高置信度阈值
high_confidence_threshold: 0.99
# 路径评估的基准分数
lora_baseline_score: 0.8
traditional_baseline_score: 0.7
embedding_baseline_score: 0.75
# 成功计算阈值
success_confidence_threshold: 0.8
# 默认置信度阈值
default_confidence_threshold: 0.95
语义缓存相似度阈值
按决策调整缓存匹配严格程度:
decisions:
- name: "health_decision"
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.95 # 健康类非常严格
- name: "general_decision"
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.75 # 通用类较宽松
BERT 模型阈值
配置嵌入模型的语义匹配阈值:
bert_model:
model_id: models/all-MiniLM-L12-v2
threshold: 0.6 # 语义相似度阈值
use_cpu: true
调优指南
何时降低阈值
- 缺少有效分类(低召回率)
- 缓存命中率过低
- 用户报告查询未被正确路由
何时提高阈值
- 太多误报匹配
- 触发错误的类别
- PII/越狱误报
调试分类
启用详细日志以诊断阈值问题:
observability:
metrics:
enabled: true
tracing:
enabled: true
sampling:
type: "always_on"
然后检查日志中的分类置信度分数:
Classified query with confidence 0.72 to category 'math'