# Semantic Router (Aurelio Labs)

> Embedding-based decision layer that routes LLM and agent requests without an extra LLM call

- Category: Evaluation & Production Ops / Gateways & Routing
- Language: Python
- Licence: MIT
- Repository: https://github.com/aurelio-labs/semantic-router
- Website: https://www.aurelio.ai/semantic-router
- Canonical page: https://ai-tldr.dev/tools/semantic-router-aurelio-labs/

## In short

Semantic Router (Aurelio Labs) is Embedding-based decision layer that routes LLM and agent requests without an extra LLM call. It sits in the Gateways & Routing category of the Evaluation & Production Ops tools and is open-source, written in Python and licensed MIT. To get started: install.

## Overview

Semantic Router is an open-source Python library from Aurelio Labs that acts as a decision-making layer for LLMs and agents. Instead of asking another LLM which tool or path to take, it compares the meaning of an incoming request against a set of example phrases using vector embeddings, then picks the matching route.

It fits the gateway and routing category: you define named routes, each with a handful of example utterances, and the router decides which one a user query belongs to. Because the decision is a vector lookup rather than a generation, it returns quickly and avoids the latency and cost of an extra model call.

It is aimed at developers building chatbots and agents who need to branch on intent, enforce guardrails, or steer requests to different prompts or models. If a query matches no route, the router returns None, so you can fall back to default behavior.

## What it does

- Routes requests by semantic similarity using embeddings instead of an extra LLM call
- Define decision paths as named Route objects, each with a list of example utterances
- Pluggable encoders including OpenAI, Cohere, Hugging Face, and FastEmbed
- Optional fully local execution with HuggingFaceEncoder and LlamaCppLLM
- Vector index integrations with Pinecone and Qdrant for storing utterances
- Supports dynamic routes for parameter generation and function calls, plus multi-modal routes

## Getting started

Install the package, define your routes, pick an encoder, and create a router to start making decisions.

1. Install

   Install Semantic Router from PyPI.

```bash
pip install -qU semantic-router
```

2. Define routes

   Each Route has a name and a list of example utterances that represent its intent.

```python
from semantic_router import Route

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",
    ],
)

chitchat = Route(
    name="chitchat",
    utterances=[
        "how's the weather today?",
        "how are things going?",
        "lovely weather today",
    ],
)

routes = [politics, chitchat]
```

3. Pick an encoder

   Initialize an embedding model. The README shows Cohere and OpenAI encoders.

```python
import os
from semantic_router.encoders import OpenAIEncoder

os.environ["OPENAI_API_KEY"] = "<YOUR_API_KEY>"
encoder = OpenAIEncoder()
```

4. Create the router and route a query

   Build a SemanticRouter from the encoder and routes, then call it with a user query. It returns the matching route name, or None if nothing matches.

```python
from semantic_router.routers import SemanticRouter

rl = SemanticRouter(encoder=encoder, routes=routes, auto_sync="local")

rl("don't you love politics?").name
# 'politics'
```

## When to use it

- Steer a chatbot to a different prompt based on whether a user wants chitchat, support, or another topic
- Add a guardrail that detects and avoids certain conversation topics before they reach the model
- Route requests to different tools, agents, or models without paying for an extra LLM decision call
- Trigger function calls or parameter generation via dynamic routes when a query matches a known intent
