配置
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 字段。
仓库中的配置资产
仓库将详尽的 canonical 参考配置与可复用路由片段分开:
config/config.yaml:详尽 canonical 参考配置config/fragments/signal/:可复用的routing.signals片段config/fragments/decision/:可复用的routing.decisions规则形状片段config/fragments/algorithm/:可复用的decision.algorithm片段config/fragments/plugin/:可复用的路由插件片段
config/fragments/decision/ 按布尔情形组织:single/、and/、or/、not/、composite/。
config/fragments/algorithm/ 按路由策略族组织:looper/ 与 selection/。
config/fragments/plugin/ 按每个插件或可复用包单独目录组织。
仓库在 go test ./pkg/config/... 中强制该片段目录,因此路由表面变更须同步更新 config/ 树。
四类片段原先直接位于 config/ 下。仓库链接和自动化脚本现在必须使用
config/fragments/...。这仅是资源路径迁移;YAML 配置结构和运行时字段名
均未改变。
最新教程遵循同一分类:
tutorials/signal/overview以及tutorials/signal/heuristic/、tutorials/signal/learned/对应config/fragments/signal/tutorials/decision/对应config/fragments/decision/tutorials/algorithm/对应config/fragments/algorithm/,每种算法一页tutorials/plugin/对应config/fragments/plugin/,每种插件一页tutorials/global/对应global:下的稀疏路由器级覆盖
与仓库相关的运行时与测试台资产现位于 config/ 之外:
config/runtime/semantic-cache/config/runtime/response-api/config/runtime/tools/e2e/config/deploy/local/envoy.yaml
仅测试用 ONNX 绑定资产位于 e2e/config/onnx-binding/