分类器微调
本指南提供了微调 vLLM 语义路由中分类阈值的快速配置方案。请根据您的具体用例调整这些设置,以平衡精确率(precision)和召回率(recall)。
类别分类器阈值
调整领域分类的置信度阈值
classifier:
category_model:
model_id: "models/lora_intent_classifier_bert-base-uncased_model"
threshold: 0.6 # Default: 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 # Default: 0.9 (strict)
use_cpu: true
pii_mapping_path: "models/pii_classifier_modernbert-base_presidio_token_model/pii_type_mapping.json"
提示
在生产环境中对 PII 使用较高的阈值(0.9+),以尽量减少误报。
越狱检测阈值
微调 Prompt Guard 灵敏度
prompt_guard:
enabled: true
use_modernbert: true
model_id: "models/jailbreak_classifier_modernbert-base_model"
threshold: 0.7 # Default: 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:
# High confidence threshold for automatic LoRA selection
high_confidence_threshold: 0.99
# Baseline scores for path evaluation
lora_baseline_score: 0.8
traditional_baseline_score: 0.7
embedding_baseline_score: 0.75
# Success calculation threshold
success_confidence_threshold: 0.8
# Default confidence threshold
default_confidence_threshold: 0.95
语义缓存相似度阈值
针对每个决策调整缓存匹配的严格程度
decisions:
- name: "health_decision"
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.95 # Very strict for health
- name: "general_decision"
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.75 # Relaxed for general
BERT 模型阈值
配置用于语义匹配的嵌入模型阈值
bert_model:
model_id: models/all-MiniLM-L12-v2
threshold: 0.6 # Semantic similarity threshold
use_cpu: true
调优指南
何时降低阈值
- 遗漏了有效的分类(召回率低)
- 缓存命中率太低
- 用户报告查询未被正确路由
何时提高阈值
- 出现过多的误报匹配
- 触发了错误的类别
- PII/越狱检测误报
调试分类
启用详细日志记录以诊断阈值问题
observability:
metrics:
enabled: true
tracing:
enabled: true
sampling:
type: "always_on"
然后查看日志中的分类置信度得分
Classified query with confidence 0.72 to category 'math'