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.
from semantic_router import RouteLayer
→ from 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.
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:
_semantic_classify_multiple_routes
method__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
: 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.
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.The RouterConfig
class has been introduced as a replacement for the LayerConfig
class, providing a more flexible way to configure routers:
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 methodsBaseRouter
: An abstract base class for creating custom routers