sparklesSemantic Router

gllm-pipelinearrow-up-right | Involves EM | Tutorial: Semantic Router | API Referencearrow-up-right

The Semantic Router uses backend-agnostic semantic similarity to classify queries into predefined routes. It supports multiple backend implementations for flexibility and scalability.

chevron-rightPrerequisiteshashtag

This tutorial requires familiarity with these concepts:

Overview

The Semantic Router delegates routing logic to pluggable backend implementations, allowing you to switch between different semantic routing algorithms without changing your code.

Supported Backends:

  • Native - Built-in GLLM semantic similarity implementation (via SemanticRouter.native())

  • Aurelio - Aurelio Labs semantic router (via SemanticRouter.aurelio()). More functionalities (encoder, index, etc.) can be found in Aurelio Backend

Installation

pip install gllm-pipeline gllm-inference

For Aurelio backend support:

pip install semantic-router

Quickstart

Step 1: Set up embeddings

Step 2: Define routes with examples

Step 3: Create the router

Option 1: Native Backend

Option 2: Aurelio Backend with EM Invoker

Option 3: Aurelio Backend with EM Invoker Encoder

Step 4: Route queries

Using Presets

Load predefined route configurations:

Advanced Configuration

For detailed information on encoders, indexes, and advanced configuration options, see the Aurelio Backend Guide:

  • Encoders: EM Invoker, Langchain, TEI

  • Indexes: Local, Azure AI Search, Datastore Adapter

  • Sync Modes: Local, Remote, Async

  • Production Setup: Complete examples and best practices

Configuration Options

Similarity Threshold

Controls the minimum similarity score required to match a route:

Route Filtering

Restrict available routes at runtime:

Complete Example

Best Practices

  1. Route Examples: Provide diverse, representative examples for each route

  2. Threshold Tuning: Start with 0.5 and adjust based on your use case

  3. Default Route: Always set a sensible default for unmatched queries

  4. Validation: Test with edge cases and ambiguous queries

  5. Monitoring: Log routing decisions for analysis and improvement

Troubleshooting

Routes not matching correctly?

  • Lower the similarity_threshold

  • Add more diverse examples to routes

  • Verify embedding model quality

Always falling back to default route?

  • Increase the similarity_threshold

  • Check that route examples are semantically distinct

  • Ensure embedding model is appropriate for your domain

See Also

Last updated

Was this helpful?