Skip to main content
The v0.1 release of semantic router introduces several breaking changes to improve the API design and add new functionality. This guide will help you migrate your code to the new version.

Key API Changes

Module Imports and Class Renaming

  • from semantic_router import RouteLayerfrom semantic_router.routers import SemanticRouter The RouteLayer class has been renamed to SemanticRouter and moved to the routers module to better reflect its purpose and fit into the modular architecture.

Method Signatures

  • SemanticRouter.add(route: Route)SemanticRouter.add(routes: List[Route]) The add method now accepts a list of routes, making it easier to add multiple routes at once. However, it still supports adding a single route for backward compatibility.
  • RouteLayer.retrieve_multiple_routes()SemanticRouter.__call__(limit=None) or SemanticRouter.acall(limit=None) The retrieve_multiple_routes method has been removed. If you need similar functionality:
    • In versions 0.1.0-0.1.2: You can use the deprecated _semantic_classify_multiple_routes method
    • In version 0.1.3+ (0.1.5+ is recommended): Use the __call__ or acall methods with appropriate limit parameter.
    When limit=1 (the default), a single RouteChoice object is returned. When limit=None or limit > 1, a list of RouteChoice objects is returned.
    Important Note About top_k: The top_k parameter (default: 5) can still limit the number of routes returned, regardless of the limit parameter. When using limit > 1, we recommend setting top_k to a higher value such as 100 or more. If you’re using limit=None to get all possible results, make sure to set top_k to be equal to or greater than the total number of utterances shared across all of your routes.

Synchronization Strategy

  • If expecting routes to sync between local and remote on initialization, use SemanticRouter(..., auto_sync="local"). The auto_sync parameter provides control over how routes are synchronized between local and remote indexes. Read more about auto_sync and synchronization strategies. Available synchronization modes:
    • error: Raise an error if local and remote are not synchronized.
    • remote: Take remote as the source of truth and update local to align.
    • local: Take local as the source of truth and update remote to align.
    • merge-force-local: Merge both local and remote keeping local as the priority.
    • merge-force-remote: Merge both local and remote keeping remote as the priority.
    • merge: Merge both local and remote, with local taking priority for conflicts.

Other Important Changes

Router Configuration

The RouterConfig class has been introduced as a replacement for the LayerConfig class, providing a more flexible way to configure routers:

Advanced Router Options

The modular architecture now provides access to different router types:
  • SemanticRouter: The standard router that replaces the old RouteLayer
  • HybridRouter: A router that can combine dense and sparse embedding methods
  • BaseRouter: An abstract base class for creating custom routers

Migration Example