配置
Semantic Router v0.3 在本地 CLI、控制台、Helm 与 Operator 之间使用同一套 canonical YAML 契约:
version:
listeners:
providers:
routing:
global:
背景说明见 统一配置契约 v0.3。本页为如何实际使用该契约的操作指南。
Canonical 契约
version:schema 版本。请使用v0.3。listeners:路由器监听端口与超时等。providers:部署绑定与提供商默认值。routing:路由语义。global:稀疏运行时覆盖。若某字段省略,则使用路由器内置默认。
各节的职责划分
routing为 DSL 所拥有 的表面。routing.modelCardsrouting.modelCards[].lorasrouting.signalsrouting.projections(分区及派生路由输出)routing.decisions
providers拥有部署与默认选择元数据。defaultsmodelsproviders.defaults存放default_model、reasoning_families、default_reasoning_effortproviders.models[*]存放provider_model_id、backend_refs、pricing、api_format、external_model_ids
global拥有路由器级运行时覆盖。global.router聚合路由引擎控制项(如配置来源选择、route-cache、模型选择默认等)global.router.config_source选择运行时配置来自 canonical YAML 文件(file)还是进程内 Kubernetes CRD 协调(kubernetes)global.services聚合共享 API 与控制面服务,如response_api、router_replay、observability、authz、ratelimitglobal.stores聚合有存储支撑的服务,如semantic_cache、memory、vector_store
global.integrations聚合辅助运行时集成,如tools、looperglobal.model_catalog聚合路由器持有的模型资产,如嵌入、系统模型、外部模型、可复用分类器与模型支撑模块global.model_catalog.embeddings.semantic.embedding_config.top_k限制打分后路由要输出的嵌入规则条数上限;内置默认为1prototype_scoring是嵌入驱动 signal 家族共用的 prototype-aware 打分块;需要把 exemplar bank 压缩成代表性 prototypes 时,可放在global.model_catalog.embeddings.semantic.embedding_config、global.model_catalog.modules.classifier.preference、global.model_catalog.kbs[]以及global.model_catalog.modules.complexityglobal.model_catalog.classifiers[]为启动时加载的分类器包(如分类体系分类器)的可复用注册表global.model_catalog.modules聚合能力模块,如prompt_guard、classifier、complexity、hallucination_mitigation
Canonical 示例
version: v0.3
listeners:
- name: http-8899
address: 0.0.0.0
port: 8899
timeout: 300s
providers:
defaults:
default_model: qwen3-8b
reasoning_families:
qwen3:
type: chat_template_kwargs
parameter: enable_thinking
default_reasoning_effort: medium
models:
- name: qwen3-8b
reasoning_family: qwen3
provider_model_id: qwen3-8b
backend_refs:
- name: primary
endpoint: host.docker.internal:8000
protocol: http
weight: 100
api_key_env: OPENAI_API_KEY
routing:
modelCards:
- name: qwen3-8b
modality: text
capabilities: [chat, reasoning]
loras:
- name: math-adapter
description: Adapter used for symbolic math and proof-style prompts.
signals:
keywords:
- name: math_terms
operator: OR
keywords: ["algebra", "calculus"]
structure:
- name: many_questions
feature:
type: count
source:
type: regex
pattern: '[??]'
predicate:
gte: 3
embeddings:
- name: technical_support
threshold: 0.75
candidates: ["installation guide", "troubleshooting steps"]
- name: account_management
threshold: 0.72
candidates: ["billing information", "subscription management"]
projections:
partitions:
- name: support_intents
semantics: exclusive
temperature: 0.3
members: [technical_support, account_management]
default: technical_support
scores:
- name: request_difficulty
method: weighted_sum
inputs:
- type: embedding
name: technical_support
weight: 0.18
value_source: confidence
- type: context
name: long_context
weight: 0.18
- type: structure
name: many_questions
weight: 0.12
mappings:
- name: request_band
source: request_difficulty
method: threshold_bands
outputs:
- name: support_fast
lt: 0.25
- name: support_escalated
gte: 0.25
decisions:
- name: support_route
description: Route support requests that need an escalated answer
priority: 100
rules:
operator: AND
conditions:
- type: embedding
name: technical_support
- type: projection
name: support_escalated
modelRefs:
- model: qwen3-8b
use_reasoning: true
lora_name: math-adapter
global:
router:
config_source: file
services:
observability:
metrics:
enabled: true
对于 routing.signals.structure,feature.type: density 现使用内置多语言文本单位归一化:每个 CJK 字符计为一个单位,连续拉丁字母与数字串计为一个单位,标点忽略,从而使同一 density 规则在英文、中文与混写提示下行为一致,且无需单独的 normalize_by 字段。