原生后端(Native Backends)
Semantic Router 使用原生 Rust 与 CGo 绑定来实现学习型分类器、基于 embedding 的信号、多模态 embedding 以及基于 MLP 的模型选择。Router 通过 CurrentNativeBackendCapabilities 暴露所选后端的运行时能力契约;调用方应以该契约为准,而不是通过 build tag 或包名来猜测是否支持某项能力。
后端选择
| 构建形态 | 后端名称 | 选择方式 |
|---|---|---|
| 默认 CGO 构建 | candle | 未启用 onnx tag 且 CGO 开启。 |
| ONNX 构建 | onnx | 启用 onnx tag 且 CGO 开启。 |
| 非 CGO 或 Windows 构建 | stub | CGO_ENABLED=0 或在 Windows 上构建。 |
示例:
# Default Candle-backed build from the Go router module.
cd src/semantic-router
go build ./cmd
# ONNX-backed build.
cd src/semantic-router
go build -tags=onnx ./cmd
# Non-CGo stub build for environments where native bindings are unavailable.
cd src/semantic-router
CGO_ENABLED=0 go build ./cmd
运行时能力(Runtime capabilities)
| 能力 | candle | onnx | stub |
|---|---|---|---|
| 统一批量分类(Unified batch classification) | Yes | No | No |
| LoRA 批量分类(LoRA batch classification) | Yes | No | No |
| 批量 embedding(Batched embedding) | Yes | Yes | No |
| 多模态 embedding(Multimodal embedding) | Yes | No | No |
| 模态路由(Modality routing) | Yes | No | No |
| MLP selector | Yes | No | No |
| 显式重置(Explicit reset) | No | No | No |
当所选后端未声明支持“统一批量分类”或“LoRA 批量分类”时,Router 会在分类层尽早失败。不要因为 Go 包能编译就假设 ONNX 或非 CGO 构建具备与 Candle 一致的分类器行为。