Key API Changes
Module Imports and Class Renaming
-
from semantic_router import RouteLayer
→from semantic_router.routers import SemanticRouter
TheRouteLayer
class has been renamed toSemanticRouter
and moved to therouters
module to better reflect its purpose and fit into the modular architecture.
Method Signatures
-
SemanticRouter.add(route: Route)
→SemanticRouter.add(routes: List[Route])
Theadd
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)
orSemanticRouter.acall(limit=None)
Theretrieve_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__
oracall
methods with appropriatelimit
parameter.
Whenlimit=1
(the default), a singleRouteChoice
object is returned. Whenlimit=None
orlimit > 1
, a list ofRouteChoice
objects is returned.Important Note About
top_k
: Thetop_k
parameter (default: 5) can still limit the number of routes returned, regardless of thelimit
parameter. When usinglimit > 1
, we recommend settingtop_k
to a higher value such as 100 or more. If you’re usinglimit=None
to get all possible results, make sure to settop_k
to 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_sync
parameter provides control over how routes are synchronized between local and remote indexes. Read more aboutauto_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
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 oldRouteLayer
HybridRouter
: A router that can combine dense and sparse embedding methodsBaseRouter
: An abstract base class for creating custom routers