Discover / Token & Cost Optimization
Semantic Router
by aurelio-labsPython
Superfast decision layer for routing queries to the right LLM or logic using semantic similarity.
Maturity: experimental because latest release v0.1.16 is pre 1.0. Derived from release and commit history, not a rating.
- Stars
- 3.8k
- Forks
- 358
- Downloads / mo
- 441k
- Last commit
- 2026-07-26
- License
- MIT
- Open issues
- 86
Market and trust evidence
Edition not yet matchedNo exact skills.sh identity match is available for this repository. Repository adoption and freshness remain visible above; install momentum is not inferred.
Trust analysis is a screening signal, not a security warranty. Read the ranking and trust methodology.
In practice
Written by AI from this repository’s README · high confidenceUsing an LLM call to pick a tool or guard a topic adds latency and cost to every single request.
Use it when
Use it when a chatbot or agent must classify intent, block topics or pick a tool in milliseconds.
Not the right pick when
Returns None when nothing matches, so it does not replace an LLM for open ended or unseen requests.
Capabilities
- Route objects defined by example utterances
- SemanticRouter layer that makes the decision
- encoders for Cohere, OpenAI, Hugging Face and FastEmbed
- fully local option with HuggingFaceEncoder and LlamaCppLLM
- hybrid route layer via the hybrid extra
- index integrations with Pinecone and Qdrant
Requirements
- An encoder API key such as COHERE_API_KEY or OPENAI_API_KEY, unless using the local extra
Cost: Free and open source
Install
Derived from the published package name in the repository, not from a model.
Video walkthroughs
Third-party YouTube uploads matched to this tool by title, channel and repository name on 2026-08-03. Not made, reviewed or endorsed by SkillPilot. View counts and publish months are as of the match date and the month is approximate. Nothing loads from YouTube until you press play.
What the repository ships
Detected from the actual files in the repository root.
Latest release v0.1.16
Published 2026-07-26
What's Changed
- fix: correct aggregation error message case and aget_routes signature by @totto in https://github.com/aurelio-labs/semantic-router/pull/667
- fix: top_scores must return results sorted by score by @lntutor in https://github.com/aurelio-labs/semantic-router/pull/673
- feat: add healthcare based semantic routing notebook by @bhargavikalicheti in https://github.com/aurelio-labs/semantic-router/pull/675
- chore: release v0.1.16 by @jamescalam in https://github.com/aurelio-labs/semantic-router/pull/676
New Contributors
- @totto made their first contribution in https://github.com/aurelio-labs/semantic-router/pull/667
- @lntutor made their first contribution in https://github.com/aurelio-labs/semantic-router/pull/673
- @bhargavikalicheti made their first contribution in https://github.com/aurelio-labs/semantic-router/pull/675
Full Changelog: https://github.com/aurelio-labs/semantic-router/compare/v0.1.15...v0.1.16
Tags
README
<p>
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/semantic-router?logo=python&logoColor=gold" />
<a href="https://github.com/aurelio-labs/semantic-router/graphs/contributors"><img alt="GitHub Contributors" src="https://img.shields.io/github/contributors/aurelio-labs/semantic-router" />
<a href="https://github.com/aurelio-labs/semantic-router/commits/main"><img alt="GitHub Last Commit" src="https://img.shields.io/github/last-commit/aurelio-labs/semantic-router" />
<img alt="" src="https://img.shields.io/github/repo-size/aurelio-labs/semantic-router" />
<a href="https://github.com/aurelio-labs/semantic-router/issues"><img alt="GitHub Issues" src="https://img.shields.io/github/issues/aurelio-labs/semantic-router" />
<a href="https://github.com/aurelio-labs/semantic-router/pulls"><img alt="GitHub Pull Requests" src="https://img.shields.io/github/issues-pr/aurelio-labs/semantic-router" />
<img src="https://codecov.io/gh/aurelio-labs/semantic-router/graph/badge.svg?token=H8OOMV2TUF" />
<a href="https://github.com/aurelio-labs/semantic-router/blob/main/LICENSE"><img alt="Github License" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
</p>
Semantic Router is a superfast decision-making layer for your LLMs and agents. Rather than waiting for slow LLM generations to make tool-use decisions, we use the magic of semantic vector space to make those decisions — _routing_ our requests using _semantic_ meaning.
Read the Docs
Quickstart
To get started with _semantic-router_ we install it like so:
pip install -qU semantic-router
❗️ _If wanting to use a fully local version of semantic router you can use HuggingFaceEncoder and LlamaCppLLM (pip install -qU "semantic-router[local]", see here). To use the HybridRouteLayer you must pip install -qU "semantic-router[hybrid]"._
We begin by defining a set of Route objects. These are the decision paths that the semantic router can decide to use, let's try two simple routes for now — one for talk on _politics_ and another for _chitchat_:
from semantic_router import Route
# we could use this as a guide for our chatbot to avoid political conversations
politics = Route(
name="politics",
utterances=[
"isn't politics the best thing ever",
"why don't you tell me about your political opinions",
"don't you just love the president",
"they're going to destroy this country!",
"they will save the country!",
],
)
# this could be used as an indicator to our chatbot to switch to a more
# conversational prompt
chitchat = Route(
name="chitchat",
utterances=[
"how's the weather today?",
"how are things going?",
"lovely weather today",
"the weather is horrendous",
"let's go to the chippy",
],
)
# we place both of our decisions together into single list
routes = [politics, chitchat]
We have our routes ready, now we initialize an embedding / encoder model. We currently support a CohereEncoder and OpenAIEncoder — more encoders will be added soon. To initialize them we do:
import os
from semantic_router.encoders import CohereEncoder, OpenAIEncoder
# for Cohere
os.environ["COHERE_API_KEY"] = "<YOUR_API_KEY>"
encoder = CohereEncoder()
# or for OpenAI
os.environ["OPENAI_API_KEY"] = "<YOUR_API_KEY>"
encoder = OpenAIEncoder()
With our routes and encoder defined we now create a RouteLayer. The route layer handles our semantic decision making.
from semantic_router.routers import SemanticRouter
rl = SemanticRouter(encoder=encoder, routes=routes, auto_sync="local")
We can now use our route layer to make super fast decisions based on user queries. Let's try with two queries that should trigger our route decisions:
rl("don't you love politics?").name
[Out]: 'politics'
Correct decision, let's try another:
rl("how's the weather today?").name
[Out]: 'chitchat'
We get both decisions correct! Now lets try sending an unrelated query:
rl("I'm interested in learning about llama 2").name
[Out]:
In this case, no decision could be made as we had no matches — so our route layer returned None!
Integrations
The _encoders_ of semantic router include easy-to-use integrations with Cohere, OpenAI, Hugging Face, FastEmbed, and more — we even support multi-modality!.
Our utterance vector space also integrates with Pinecone and Qdrant!
📚 Resources
Docs
| Notebook | Description |
| -------- | ----------- |
| Introduction | Introduction to Semantic Router and static routes |
| Dynamic Routes | Dynamic routes for parameter generation and functionc calls |
| Save/Load Layers | How to save and load RouteLayer from file |
| LangChain Integration | How to integrate Semantic Router with LangChain Agents |
| Local Execution | Fully local Semantic Router with dynamic routes — local models such as Mistral 7B outperform GPT-3.5 in most tests |
| Route Optimization | How to train route layer thresholds to optimize performance |
| Multi-Modal Routes | Using multi-modal routes to identify Shrek vs. not-Shrek pictures |
| Healthcare Administrative Routing | Fully local routing, threshold optimization, and evaluation across seven synthetic healthcare administrative workflows |
Online Course
Community
- Dimitrios Manias, Ali Chouman, Abdallah Shami, Semantic Routing for Enhanced Performance of LLM-Assisted Intent-Based 5G Core Network Management and Orchestration, IEEE GlobeCom 2024
- Julian Horsey, Semantic Router superfast decision layer for LLMs and AI agents, Geeky Gadgets
- azhar, Beyond Basic Chatbots: How Semantic Router is Changing the Game, AI Insights @ Medium
- Daniel Avila, Semantic Router: Enhancing Control in LLM Conversations, CodeGPT @ Medium
- Yogendra Sisodia, Stop Chat-GPT From Going Rogue In Production With Semantic Router, Medium
- Aniket Hingane, LLM Apps: Why you Must Know Semantic Router in 2024: Part 1, Medium
- Adrien Sales, 🔀 Semantic Router w. ollama/gemma2 : real life 10ms hotline challenge 🤯
- Adrien Sales, Kaggle Notebook 🔀 Semantic Router:
ollama/gemma2:9bhotline