How aurelio-labs/semantic-router works
Semantic Router is a Python decision layer that maps a user query to a configured route using semantic similarity, returning no match when none qualifies. The principal workflow is to define routes and utterances, select an encoder, initialize a router, and submit queries; router implementations also support hybrid routing and index synchronization. Routes can invoke LLM-backed dynamic parameter or function-call extraction. The README also documents multimodal routing, threshold optimization, and local execution. Some subsystem links are based on documented capabilities or module references; unsampled implementation details are not assumed.
Main entry points: semantic.py Semantic router · route.py Route definitions · routers/base.py Router core · encoders/base.py Encoder interfaces
Components 21
Routing
- Route definitions
semantic_router/route.py - Semantic router
semantic_router/routers/semantic.py - Router core
semantic_router/routers/base.py - Hybrid router
semantic_router/routers/hybrid.py - Threshold optimization
semantic_router/linear.py
Encoding
- Encoder interfaces
semantic_router/encoders/base.py - Encoder input types
semantic_router/encoders/encode_input_type.py - Encoder providers
semantic_router/encoders - Multimodal encoding
semantic_router/encoders/clip.py
Indexes
- Index interface
semantic_router/index/base.py - Local index
semantic_router/index/local.py - Hybrid local index
semantic_router/index/hybrid_local.py - Pinecone index
semantic_router/index/pinecone.py - Postgres index
semantic_router/index/postgres.py - Qdrant index
semantic_router/index/qdrant.py
LLM and calls
- LLM interface
semantic_router/llms/base.py - LLM providers
semantic_router/llms/openai.py - Function extraction
semantic_router/utils/function_call.py
Shared models
- Route and index schemas
semantic_router/schema.py - Model defaults
semantic_router/utils/defaults.py
Other components
- User query
Connections 21
- User query → Semantic router: submits query
- Route definitions → Semantic router: configures routes
semantic_router/routers/semantic.py - Semantic router → Router core: builds on
semantic_router/routers/semantic.py - Router core → Route definitions: calls route
semantic_router/routers/base.py - Route definitions → LLM interface: extracts inputs
semantic_router/route.py - Route definitions → Function extraction: uses helpers
semantic_router/route.py - Semantic router → Encoder interfaces: uses encoder
semantic_router/routers/semantic.py - Router core → Index interface: uses index
semantic_router/routers/base.py - Hybrid router → Hybrid local index: queries index
semantic_router/routers/hybrid.py - Hybrid router → Encoder interfaces: encodes query
semantic_router/routers/hybrid.py - Encoder providers → Encoder interfaces: implements interface
semantic_router/encoders/litellm.py - Multimodal encoding → Encoder interfaces: provides encoding
- Semantic router → Local index: supports local sync
- Semantic router → Pinecone index: supports integration
- Semantic router → Qdrant index: supports integration
- Index interface → Route and index schemas: uses metadata
semantic_router/index/base.py - Router core → Route and index schemas: builds config
semantic_router/routers/base.py - LLM providers → LLM interface: implements interface
semantic_router/llms/openai.py - Encoder providers → Model defaults: reads defaults
semantic_router/encoders/openai.py - Threshold optimization → Semantic router: optimizes thresholds
- Route definitions → LLM providers: dynamic generation