Key API Changes
Module Imports and Class Renaming
-
from semantic_router import RouteLayer→from semantic_router.routers import SemanticRouterTheRouteLayerclass has been renamed toSemanticRouterand moved to theroutersmodule to better reflect its purpose and fit into the modular architecture.
Method Signatures
-
SemanticRouter.add(route: Route)→SemanticRouter.add(routes: List[Route])Theaddmethod 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)orSemanticRouter.acall(limit=None)Theretrieve_multiple_routesmethod has been removed. If you need similar functionality:- In versions 0.1.0-0.1.2: You can use the deprecated
_semantic_classify_multiple_routesmethod - In version 0.1.3+ (0.1.5+ is recommended): Use the
__call__oracallmethods with appropriatelimitparameter.
Whenlimit=1(the default), a singleRouteChoiceobject is returned. Whenlimit=Noneorlimit > 1, a list ofRouteChoiceobjects is returned.Important Note About
top_k: Thetop_kparameter (default: 5) can still limit the number of routes returned, regardless of thelimitparameter. When usinglimit > 1, we recommend settingtop_kto a higher value such as 100 or more. If you’re usinglimit=Noneto get all possible results, make sure to settop_kto be equal to or greater than the total number of utterances shared across all of your routes. - In versions 0.1.0-0.1.2: You can use the deprecated
Synchronization Strategy
-
If expecting routes to sync between local and remote on initialization, use
SemanticRouter(..., auto_sync="local"). Theauto_syncparameter provides control over how routes are synchronized between local and remote indexes. Read more aboutauto_syncand 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
TheRouterConfig 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 oldRouteLayerHybridRouter: A router that can combine dense and sparse embedding methodsBaseRouter: An abstract base class for creating custom routers

