semantic-router 0.1.11


pip install semantic-router

  Latest version

Released: Aug 11, 2025

Project Links

Meta
Author: Aurelio AI
Requires Python: <3.14,>=3.9

Classifiers

Semantic Router

PyPI - Python Version GitHub Contributors GitHub Last Commit GitHub Issues GitHub Pull Requests Github License

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

Online Course

Semantic Router Course

Community

0.1.11 Aug 11, 2025
0.1.10 Jul 15, 2025
0.1.9 Jun 30, 2025
0.1.8 May 09, 2025
0.1.7 Apr 03, 2025
0.1.6 Mar 25, 2025
0.1.5 Mar 22, 2025
0.1.4 Mar 21, 2025
0.1.3 Mar 21, 2025
0.1.2 Mar 20, 2025
0.1.1 Mar 11, 2025
0.1.0 Mar 11, 2025
0.1.0.dev10 Feb 12, 2025
0.1.0.dev9 Feb 03, 2025
0.1.0.dev8 Jan 31, 2025
0.1.0.dev7 Jan 24, 2025
0.1.0.dev6 Jan 13, 2025
0.1.0.dev5 Dec 20, 2024
0.1.0.dev4 Dec 15, 2024
0.1.0.dev3 Dec 01, 2024
0.1.0.dev2 Nov 29, 2024
0.1.0.dev1 Nov 20, 2024
0.1.0.dev0 Nov 16, 2024
0.0.72 Oct 10, 2024
0.0.71 Oct 08, 2024
0.0.70 Oct 03, 2024
0.0.69 Oct 02, 2024
0.0.68 Sep 23, 2024
0.0.67 Sep 23, 2024
0.0.66 Sep 22, 2024
0.0.65 Sep 06, 2024
0.0.64 Sep 05, 2024
0.0.63 Sep 02, 2024
0.0.62 Aug 29, 2024
0.0.61 Aug 23, 2024
0.0.60 Aug 19, 2024
0.0.59 Aug 14, 2024
0.0.58 Aug 09, 2024
0.0.57 Aug 08, 2024
0.0.56 Aug 08, 2024
0.0.55 Jul 31, 2024
0.0.54 Jul 19, 2024
0.0.53 Jul 16, 2024
0.0.52 Jul 15, 2024
0.0.51 Jul 12, 2024
0.0.50 Jul 05, 2024
0.0.49 Jul 03, 2024
0.0.48 Jun 20, 2024
0.0.47 Jun 13, 2024
0.0.46 Jun 02, 2024
0.0.45 May 31, 2024
0.0.44 May 21, 2024
0.0.43 May 16, 2024
0.0.42 May 15, 2024
0.0.41 May 15, 2024
0.0.40 May 14, 2024
0.0.39 May 11, 2024
0.0.38 May 03, 2024
0.0.37 Apr 28, 2024
0.0.36 Apr 28, 2024
0.0.35 Apr 28, 2024
0.0.34 Apr 17, 2024
0.0.33 Apr 17, 2024
0.0.32 Apr 08, 2024
0.0.31 Apr 07, 2024
0.0.30 Apr 07, 2024
0.0.29 Mar 25, 2024
0.0.28 Mar 15, 2024
0.0.27 Mar 02, 2024
0.0.26 Feb 27, 2024
0.0.25 Feb 27, 2024
0.0.24 Feb 23, 2024
0.0.23 Feb 23, 2024
0.0.22 Feb 18, 2024
0.0.21 Feb 18, 2024
0.0.20 Jan 28, 2024
0.0.19 Jan 28, 2024
0.0.18 Jan 24, 2024
0.0.17 Jan 17, 2024
0.0.16 Jan 14, 2024
0.0.15 Jan 07, 2024
0.0.14 Dec 28, 2023
0.0.13 Dec 28, 2023
0.0.12 Dec 20, 2023
0.0.11 Dec 18, 2023
0.0.10 Dec 18, 2023
0.0.9 Dec 15, 2023
0.0.8 Dec 14, 2023
0.0.7 Dec 13, 2023
0.0.5 Dec 11, 2023
0.0.3 Nov 15, 2023
0.0.2 Nov 13, 2023
0.0.1 Nov 09, 2023

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
aiohttp (<4,>=3.10.11)
aurelio-sdk (>=0.0.19)
colorama (<0.5,>=0.4.6)
colorlog (<7,>=6.8.0)
litellm (>=1.61.3)
numpy (>=1.25.2)
openai (<2.0.0,>=1.10.0)
pydantic (<3,>=2.10.2)
pyyaml (<7,>=6.0.1)
regex (>=2023.12.25)
tiktoken (<1.0.0,>=0.6.0)
tornado (<7,>=6.4.2)
urllib3 (<3,>=1.26)