配置
本指南涵盖了语义路由 (Semantic Router) 的配置选项。系统使用单个 YAML 配置文件来控制信号驱动路由、插件链处理和模型选择。
架构概览
配置定义了三个主要层:
- 信号提取层:定义 6 种类型的信号(关键词、嵌入、领域、事实核查、用户反馈、偏好)
- 决策引擎:使用 AND/OR 运算符组合信号以做出路由决策
- 插件链:配置用于缓存、安全和优化的插件
配置文件
配置文件位于 config/config.yaml。以下是基于实际实现的结构:
# config/config.yaml - 实际配置结构
# 用于语义相似度的 BERT 模型
bert_model:
model_id: sentence-transformers/all-MiniLM-L12-v2
threshold: 0.6
use_cpu: true
# 语义缓存
semantic_cache:
backend_type: "memory" # 选项: "memory" 或 "milvus"
enabled: false
similarity_threshold: 0.8 # 全局默认阈值
max_entries: 1000
ttl_seconds: 3600
eviction_policy: "fifo" # 选项: "fifo", "lru", "lfu"
# 工具自动选择
tools:
enabled: false
top_k: 3
similarity_threshold: 0.2
tools_db_path: "config/tools_db.json"
fallback_to_empty: true
# 越狱防护
prompt_guard:
enabled: false # 全局默认 - 可以针对每个类别覆盖
use_modernbert: true
model_id: "models/jailbreak_classifier_modernbert-base_model"
threshold: 0.7
use_cpu: true
# vLLM 端点 - 您的后端模型
vllm_endpoints:
- name: "endpoint1"
address: "192.168.1.100" # 替换为您的服务器 IP 地址
port: 11434
models:
- "your-model" # 替换为您的模型
weight: 1
# 模型配置
model_config:
"your-model":
pii_policy:
allow_by_default: true
pii_types_allowed: ["EMAIL_ADDRESS", "PERSON"]
preferred_endpoints: ["endpoint1"]
# 示例:具有自定义名称的 DeepSeek 模型
"ds-v31-custom":
reasoning_family: "deepseek" # 使用 DeepSeek 推理语法
preferred_endpoints: ["endpoint1"]
# 示例:具有自定义名称的 Qwen3 模型
"my-qwen3-model":
reasoning_family: "qwen3" # 使用 Qwen3 推理语法
preferred_endpoints: ["endpoint2"]
# 示例:不支持推理的模型
"phi4":
preferred_endpoints: ["endpoint1"]
# 分类模型
classifier:
category_model:
model_id: "models/category_classifier_modernbert-base_model"
use_modernbert: true
threshold: 0.6
use_cpu: true
pii_model:
model_id: "models/pii_classifier_modernbert-base_presidio_token_model"
use_modernbert: true
threshold: 0.7
use_cpu: true
# 信号 - 信号提取配置
signals:
# 基于关键词的信号(快速模式匹配)
keywords:
- name: "math_keywords"
operator: "OR"
keywords:
- "calculate"
- "equation"
- "solve"
- "derivative"
- "integral"
case_sensitive: false
- name: "code_keywords"
operator: "OR"
keywords:
- "function"
- "class"
- "debug"
- "compile"
case_sensitive: false
# 基于嵌入的信号(语义相似度)
embeddings:
- name: "code_debug"
threshold: 0.70
candidates:
- "how to debug the code"
- "troubleshooting steps for my code"
aggregation_method: "max"
- name: "math_intent"
threshold: 0.75
candidates:
- "solve mathematical problem"
- "calculate the result"
aggregation_method: "max"
# 领域信号(MMLU 分类)
domains:
- name: "mathematics"
description: "Mathematical and computational problems"
mmlu_categories:
- "abstract_algebra"
- "college_mathematics"
- "elementary_mathematics"
- name: "computer_science"
description: "Programming and computer science"
mmlu_categories:
- "computer_security"
- "machine_learning"
# 事实核查信号(检测验证需求)
fact_check:
- name: "needs_verification"
description: "Queries requiring fact verification"
# 用户反馈信号(满意度分析)
user_feedbacks:
- name: "correction_needed"
description: "User indicates previous answer was wrong"
# 偏好信号(基于 LLM 的匹配)
preferences:
- name: "complex_reasoning"
description: "Requires deep reasoning and analysis"
llm_endpoint: "http://localhost:11434"
# 类别 - 定义领域类别
categories:
- name: math
- name: computer science
- name: other
# 决策 - 结合信号以做出路由决策
decisions:
- name: math
description: "Route mathematical queries"
priority: 10
rules:
operator: "OR" # 匹配任何条件
conditions:
- type: "keyword"
name: "math_keywords"
- type: "embedding"
name: "math_intent"
- type: "domain"
name: "mathematics"
modelRefs:
- model: your-model
use_reasoning: true # 为数学问题启用推理
# 可选:决策级插件
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.9 # 数学问题需要更高的阈值
- type: "jailbreak"
configuration:
enabled: true
- type: "pii"
configuration:
enabled: true
threshold: 0.8
- type: "system_prompt"
configuration:
enabled: true
prompt: "You are a mathematics expert. Solve problems step by step."
- name: computer_science
description: "Route computer science queries"
priority: 10
rules:
operator: "OR"
conditions:
- type: "keyword"
name: "code_keywords"
- type: "embedding"
name: "code_debug"
- type: "domain"
name: "computer_science"
modelRefs:
- model: your-model
use_reasoning: true # 为代码启用推理
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.85
- type: "system_prompt"
configuration:
enabled: true
prompt: "You are a programming expert. Provide clear code examples."
- name: other
description: "Route general queries"
priority: 5
rules:
operator: "OR"
conditions:
- type: "domain"
name: "other"
modelRefs:
- model: your-model
use_reasoning: false # 通用查询不使用推理
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.75 # 通用查询使用较低的阈值
default_model: your-model
# 推理家族配置 - 定义不同模型家族如何处理推理语法
reasoning_families:
deepseek:
type: "chat_template_kwargs"
parameter: "thinking"
qwen3:
type: "chat_template_kwargs"
parameter: "enable_thinking"
gpt-oss:
type: "reasoning_effort"
parameter: "reasoning_effort"
gpt:
type: "reasoning_effort"
parameter: "reasoning_effort"
# 全局默认推理努力等级
default_reasoning_effort: "medium"
在上面的 model_config 块中分配推理家族——每个模型使用 reasoning_family(参见示例中的 ds-v31-custom 和 my-qwen3-model)。不支持推理语法的模型只需省略该字段(例如 phi4)。
配置方案 (预设)
我们提供精心挑选的、版本化的预设,您可以直接使用或作为起点:
- 精度优化:https://github.com/vllm-project/semantic-router/blob/main/config/config.recipe-accuracy.yaml
- Token 效率优化:https://github.com/vllm-project/semantic-router/blob/main/config/config.recipe-token-efficiency.yaml
- 延迟优化:https://github.com/vllm-project/semantic-router/blob/main/config/config.recipe-latency.yaml
- 指南和用法:https://github.com/vllm-project/semantic-router/blob/main/config/RECIPES.md
快速使用:
- 本地:将方案复制到 config.yaml,然后运行
- cp config/config.recipe-accuracy.yaml config/config.yaml
- make run-router
- Helm/Argo:在您的 ConfigMap 中引用方案文件内容(示例在上述指南中)。
信号配置
信号是智能路由的基础。系统支持 6 种类型的信号,可以组合起来做出路由决策。
1. 关键词信号 - 快速模式匹配
signals:
keywords:
- name: "math_keywords"
operator: "OR" # OR: 匹配任意关键词, AND: 匹配所有关键词
keywords:
- "calculate"
- "equation"
- "solve"
case_sensitive: false
用例:
- 针对特定术语的确定性路由
- 合规性和安全性(PII 关键词、违禁术语)
- 需要 <1ms 延迟的高吞吐量场景
2. 嵌入信号 - 语义理解
signals:
embeddings:
- name: "code_debug"
threshold: 0.70 # 相似度阈值 (0-1)
candidates:
- "how to debug the code"
- "troubleshooting steps"
aggregation_method: "max" # max, avg, 或 min
用例:
- 对释义具有鲁棒性的意图检测
- 语义相似度匹配
- 处理多样化的用户措辞
3. 领域信号 - MMLU 分类
signals:
domains:
- name: "mathematics"
description: "Mathematical problems"
mmlu_categories:
- "abstract_algebra"
- "college_mathematics"
用例:
- 学术和专业领域路由
- 领域专家模型选择
- 支持 14 个 MMLU 类别
4. 事实核查信号 - 验证需求检测
signals:
fact_check:
- name: "needs_verification"
description: "Queries requiring fact verification"
用例:
- 识别事实查询与创意/代码任务
- 路由到具有幻觉检测的模型
- 触发事实核查插件
5. 用户反馈信号 - 满意度分析
signals:
user_feedbacks:
- name: "correction_needed"
description: "User indicates previous answer was wrong"
用例:
- 处理后续更正("that's wrong", "try again")
- 检测满意度水平
- 路由到更强大的模型进行重试
6. 偏好信号 - 基于 LLM 的匹配
signals:
preferences:
- name: "complex_reasoning"
description: "Requires deep reasoning"
llm_endpoint: "http://localhost:11434"
用例:
- 通过外部 LLM 进行复杂意图分析
- 细致的路由决策
- 当其他信号不足时
决策规则 - 信号融合
使用 AND/OR 运算符组合信号:
decisions:
- name: math
description: "Route mathematical queries"
priority: 10
rules:
operator: "OR" # 匹配任意条件
conditions:
- type: "keyword"
name: "math_keywords"
- type: "embedding"
name: "math_intent"
- type: "domain"
name: "mathematics"
modelRefs:
- model: math-specialist
weight: 1.0
策略:
- 基于优先级:首先评估优先级较高的决策
- 基于置信度:选择置信度得分最高的决策
- 混合:结合优先级和置信度
插件链配置
插件在链中处理请求/响应。每个决策都可以覆盖全局插件设置。
全局插件配置
# 全局默认值
semantic_cache:
enabled: true
similarity_threshold: 0.8
prompt_guard:
enabled: true
threshold: 0.7
classifier:
pii_model:
enabled: true
threshold: 0.8
决策级插件覆盖
decisions:
- name: math
description: "Route mathematical queries"
priority: 10
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.9 # 数学问题更高
- type: "jailbreak"
configuration:
enabled: true
- type: "pii"
configuration:
enabled: true
threshold: 0.8
- type: "system_prompt"
configuration:
enabled: true
prompt: "You are a mathematics expert."
- type: "header_mutation"
configuration:
enabled: true
headers:
X-Math-Mode: "enabled"
- type: "hallucination"
configuration:
enabled: false # 可选的实时检测
插件类型
| 插件 | 描述 | 配置 |
|---|---|---|
| semantic-cache | 基于语义相似度的缓存 | similarity_threshold, ttl_seconds |
| jailbreak | 对抗性提示词检测 | threshold, model_id |
| pii | PII 检测和脱敏 | threshold, pii_types_allowed |
| system_prompt | 动态提示词注入 | prompt |
| header_mutation | HTTP Header 操控 | headers |
| hallucination | Token 级幻觉检测 | enabled |
关键配置部分
后端端点
配置您的 LLM 服务器:
vllm_endpoints:
- name: "my_endpoint"
address: "127.0.0.1" # 您的服务器 IP - 必须是 IP 地址格式
port: 8000 # 您的服务器端口
weight: 1 # 负载均衡权重
# 模型配置 - 将模型映射到端点
model_config:
"llama2-7b": # 模型名称 - 必须与 vLLM --served-model-name 匹配
preferred_endpoints: ["my_endpoint"]
"qwen3": # 由同一端点服务的另一个模型
preferred_endpoints: ["my_endpoint"]
示例:Llama / Qwen 后端配置
vllm_endpoints:
- name: "local-vllm"
address: "127.0.0.1"
port: 8000
model_config:
"llama2-7b":
preferred_endpoints: ["local-vllm"]
"qwen3":
preferred_endpoints: ["local-vllm"]
地址格式要求
重要:address 字段必须包含有效的 IP 地址(IPv4 或 IPv6)。不支持域名和其他格式。
✅ 支持的格式:
# IPv4 地址
address: "127.0.0.1"
# IPv6 地址
address: "2001:db8::1"
❌ 不支持的格式:
# 域名
address: "localhost" # ❌ 请使用 127.0.0.1 代替
address: "api.openai.com" # ❌ 请使用 IP 地址代替
# 协议前缀
address: "http://127.0.0.1" # ❌ 删除协议前缀
# 路径
address: "127.0.0.1/api" # ❌ 删除路径,仅使用 IP
# 地址中的端口
address: "127.0.0.1:8080" # ❌ 使用单独的 'port' 字段
模型名称一致性
model_config 中的模型名称必须与启动 vLLM 服务器时使用的 --served-model-name 参数完全匹配:
# vLLM 服务器命令(示例):
vllm serve meta-llama/Llama-2-7b-hf --served-model-name llama2-7b --port 8000
vllm serve Qwen/Qwen3-1.8B --served-model-name qwen3 --port 8000
# config.yaml 必须在 model_config 中引用模型:
model_config:
"llama2-7b": # ✅ 匹配 --served-model-name
preferred_endpoints: ["your-endpoint"]
"qwen3": # ✅ 匹配 --served-model-name
preferred_endpoints: ["your-endpoint"]
模型设置
配置模型特定的设置:
model_config:
"llama2-7b":
pii_policy:
allow_by_default: true # 默认允许 PII
pii_types_allowed: ["EMAIL_ADDRESS", "PERSON"]
preferred_endpoints: ["my_endpoint"] # 可选:指定可以为该模型提供服务的端点
"gpt-4":
pii_policy:
allow_by_default: false
# preferred_endpoints 省略 - 路由器将不设置端点头
# 当外部负载均衡器处理端点选择时很有用
关于 preferred_endpoints 的说明:
- 可选字段:如果省略,路由将不会设置
x-vsr-destination-endpoint头 - 如果指定:路由根据权重选择最佳端点并设置头
- 如果省略:上游负载均衡器或服务网格处理端点选择
- 验证:在类别中使用或作为
default_model的模型必须配置preferred_endpoints
定价(可选)
如果您希望路由计算请求成本并公开 Prometheus 成本指标,请在 model_config 的每个模型下添加每 100 万 token 的定价和货币。
model_config:
phi4:
pricing:
currency: USD
prompt_per_1m: 0.07
completion_per_1m: 0.35
"mistral-small3.1":
pricing:
currency: USD
prompt_per_1m: 0.1
completion_per_1m: 0.3
gemma3:27b:
pricing:
currency: USD
prompt_per_1m: 0.067
completion_per_1m: 0.267
- 成本公式:
(prompt_tokens * prompt_per_1m + completion_tokens * completion_per_1m) / 1_000_000(使用给定货币)。 - 如果未配置,路由仍会报告 token 和延迟指标;成本视为 0。
分类模型
配置 BERT 分类模型:
classifier:
category_model:
model_id: "models/category_classifier_modernbert-base_model"
use_modernbert: true
threshold: 0.6 # 分类置信度阈值
use_cpu: true # 使用 CPU(不需要 GPU)
pii_model:
model_id: "models/pii_classifier_modernbert-base_presidio_token_model"
threshold: 0.7 # PII 检测阈值
use_cpu: true
类别和路由
使用基于决策的路由系统定义如何处理不同的查询类型:
# 类别定义用于分类的领域
categories:
- name: math
- name: computer science
- name: other
# 决策定义带有规则和模型选择的路由逻辑
decisions:
- name: math
description: "Route mathematical queries"
priority: 10
rules:
operator: "OR"
conditions:
- type: "domain"
name: "math"
modelRefs:
- model: your-model
use_reasoning: true # 为该模型在数学问题上启用推理
- name: computer science
description: "Route computer science queries"
priority: 10
rules:
operator: "OR"
conditions:
- type: "domain"
name: "computer science"
modelRefs:
- model: your-model
use_reasoning: true # 为代码启用推理
- name: other
description: "Route general queries"
priority: 5
rules:
operator: "OR"
conditions:
- type: "domain"
name: "other"
modelRefs:
- model: your-model
use_reasoning: false # 通用查询不进行推理
default_model: your-model # 回退模型
模型特定的推理
use_reasoning 字段在每个决策的 modelRefs 中为每个模型配置,允许细粒度控制:
decisions:
- name: math
description: "Route mathematical queries"
priority: 10
rules:
operator: "OR"
conditions:
- type: "domain"
name: "math"
modelRefs:
- model: gpt-oss-120b
use_reasoning: true # GPT-OSS-120b 支持数学推理
- model: phi4
use_reasoning: false # phi4 不支持推理模式
- model: deepseek-v31
use_reasoning: true # DeepSeek 支持数学推理
模型推理配置
配置不同模型如何处理推理模式语法。这允许您在不更改代码的情况下添加新模型:
# 模型推理配置 - 定义不同模型如何处理推理语法
model_reasoning_configs:
- name: "deepseek"
patterns: ["deepseek", "ds-", "ds_", "ds:", "ds "]
reasoning_syntax:
type: "chat_template_kwargs"
parameter: "thinking"
- name: "qwen3"
patterns: ["qwen3"]
reasoning_syntax:
type: "chat_template_kwargs"
parameter: "enable_thinking"
- name: "gpt-oss"
patterns: ["gpt-oss", "gpt_oss"]
reasoning_syntax:
type: "reasoning_effort"
parameter: "reasoning_effort"
- name: "gpt"
patterns: ["gpt"]
reasoning_syntax:
type: "reasoning_effort"
parameter: "reasoning_effort"
# 全局默认推理努力等级(当未按类别指定时)
default_reasoning_effort: "medium"
模型推理配置选项
配置结构:
name:模型家族的唯一标识符patterns:与模型名称匹配的模式数组reasoning_syntax.type:模型期望如何指定推理模式"chat_template_kwargs":使用聊天模板参数(用于 DeepSeek、Qwen3 等模型)"reasoning_effort":使用与 OpenAI 兼容的 reasoning_effort 字段(用于 GPT 模型)
reasoning_syntax.parameter:模型使用的具体参数名称
模式匹配: 系统支持简单的字符串模式和正则表达式,以实现灵活的模型匹配:
- 简单字符串匹配:
"deepseek"匹配任何包含 "deepseek" 的模型 - 前缀模式:
"ds-"匹配以 "ds-" 开头或完全是 "ds" 的模型 - 正则表达式:
"^gpt-4.*"匹配以 "gpt-4" 开头的模型 - 通配符:
"*"匹配所有模型(用于回退配置) - 多个模式:
["deepseek", "ds-", "^phi.*"]匹配这些模式中的任何一个
正则表达式模式示例:
patterns:
- "^gpt-4.*" # Models starting with "gpt-4"
- ".*-instruct$" # Models ending with "-instruct"
- "phi[0-9]+" # Models like "phi3", "phi4", etc.
- "^(llama|mistral)" # Models starting with "llama" or "mistral"
添加新模型: 要支持新的模型家族(例如 Claude),只需添加新配置:
model_reasoning_configs:
- name: "claude"
patterns: ["claude"]
reasoning_syntax:
type: "chat_template_kwargs"
parameter: "enable_reasoning"
未知模型: 不匹配任何已配置模式的模型在启用推理模式时将不会应用任何推理字段。这可以防止不支持推理语法的模型出现问题。
默认推理努力等级: 设置全局默认推理努力等级,当类别未指定其自己的努力等级时使用:
default_reasoning_effort: "high" # 选项: "low", "medium", "high"
决策特定的推理努力等级: 覆盖每个决策的默认努力等级:
decisions:
- name: math
description: "Route mathematical queries"
priority: 10
reasoning_effort: "high" # 对复杂数学使用高努力等级
rules:
operator: "OR"
conditions:
- type: "domain"
name: "math"
modelRefs:
- model: your-model
use_reasoning: true # 为该模型启用推理
- name: general
description: "Route general queries"
priority: 5
reasoning_effort: "low" # 对通用查询使用低努力等级
rules:
operator: "OR"
conditions:
- type: "domain"
name: "general"
modelRefs:
- model: your-model
use_reasoning: true # 为该模型启用推理
安全特性
配置 PII 检测和越狱保护:
# PII 检测
classifier:
pii_model:
threshold: 0.7 # 越高 = PII 检测越严格
# 越狱防护
prompt_guard:
enabled: true # 启用越狱检测
threshold: 0.7 # 检测灵敏度
use_cpu: true # 在 CPU 上运行
# 模型级 PII 策略
model_config:
"your-model":
pii_policy:
allow_by_default: true # 默认允许大多数内容
pii_types_allowed: ["EMAIL_ADDRESS", "PERSON"] # 允许的具体类型
可选特性
配置其他特性:
# 语义缓存
semantic_cache:
enabled: true # 全局启用语义缓存
backend_type: "memory" # 选项: "memory" 或 "milvus"
similarity_threshold: 0.8 # 全局默认缓存命中阈值
max_entries: 1000 # 最大缓存条目
ttl_seconds: 3600 # 缓存过期时间
eviction_policy: "fifo" # 选项: "fifo", "lru", "lfu"
# 决策级缓存配置(新)
# 覆盖特定决策的全局缓存设置
categories:
- name: health
- name: general_chat
- name: troubleshooting
decisions:
- name: health
description: "Route health queries"
priority: 10
rules:
operator: "OR"
conditions:
- type: "domain"
name: "health"
modelRefs:
- model: your-model
use_reasoning: false
plugins:
- type: "semantic-cache"
configuration:
enabled: true
similarity_threshold: 0.95 # 非常严格 - 医疗准确性至关重要
- name: general_chat
description: "Route general chat queries"
priority: 5
rules:
operator: "OR"
conditions:
- type: "domain"
name: "general_chat"
modelRefs:
- model: your-model
use_reasoning: false
plugins:
- type: "semantic-cache"
configuration:
similarity_threshold: 0.75 # 放宽以获得更好的缓存命中率
- name: troubleshooting
description: "Route troubleshooting queries"
priority: 5
rules:
operator: "OR"
conditions:
- type: "domain"
name: "troubleshooting"
modelRefs:
- model: your-model
use_reasoning: false
# 无缓存插件 - 使用全局默认值 (0.8)
# 工具自动选择
tools:
enabled: true # 启用工具自动选择
top_k: 3 # 选择的工具数量
similarity_threshold: 0.2 # 工具相关性阈值
tools_db_path: "config/tools_db.json"
fallback_to_empty: true # 失败时返回空
# 用于相似度的 BERT 模型
bert_model:
model_id: sentence-transformers/all-MiniLM-L12-v2
threshold: 0.6 # 相似度阈值
use_cpu: true # 仅 CPU 推理
# 批量分类 API 配置
api:
batch_classification:
max_batch_size: 100 # 每个批量请求的最大文本数
concurrency_threshold: 5 # 在此大小时切换到并发处理
max_concurrency: 8 # 最大并发 goroutine
# 监控指标配置
metrics:
enabled: true # 启用 Prometheus 指标收集
detailed_goroutine_tracking: true # 跟踪单个 goroutine 生命周期
high_resolution_timing: false # 使用纳秒精度计时
sample_rate: 1.0 # 收集所有请求的指标 (1.0 = 100%)
# 指标的批量大小范围标签(可选 - 使用合理的默认值)
# 默认范围: "1", "2-5", "6-10", "11-20", "21-50", "50+"
# 仅在需要自定义范围时指定:
# batch_size_ranges:
# - {min: 1, max: 1, label: "1"}
# - {min: 2, max: 5, label: "2-5"}
# - {min: 6, max: 10, label: "6-10"}
# - {min: 11, max: 20, label: "11-20"}
# - {min: 21, max: 50, label: "21-50"}
# - {min: 51, max: -1, label: "50+"} # -1 表示无上限
# 直方图桶 - 从下面的预设中选择或自定义
duration_buckets: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30]
size_buckets: [1, 2, 5, 10, 20, 50, 100, 200]
# 快速配置的预设示例(复制上面的值)
preset_examples:
fast:
duration: [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1]
size: [1, 2, 3, 5, 8, 10]
standard:
duration: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]
size: [1, 2, 5, 10, 20, 50, 100]
slow:
duration: [0.1, 0.5, 1, 5, 10, 30, 60, 120]
size: [10, 50, 100, 500, 1000, 5000]
如何使用预设示例
配置包含用于快速设置的预设示例。以下是如何使用它们:
步骤 1:选择您的场景
fast- 用于实时 API(微秒到毫秒响应时间)standard- 用于典型的 Web API(毫秒到秒响应时间)slow- 用于批处理或大量计算(秒到分钟)
步骤 2:复制预设值
# 示例:切换到快速 API 配置
# 从 preset_examples.fast 复制并粘贴到实际配置:
duration_buckets: [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1]
size_buckets: [1, 2, 3, 5, 8, 10]
步骤 3:重启服务
pkill -f "router"
make run-router
默认批量大小范围
系统提供了适用于大多数用例的合理默认批量大小范围:
- "1" - 单个文本请求
- "2-5" - 小批量请求
- "6-10" - 中批量请求
- "11-20" - 大批量请求
- "21-50" - 超大批量请求
- "50+" - 最大批量请求
除非您有特定要求,否则无需配置 batch_size_ranges。 省略配置时会自动使用默认值。