You're reading the docs for Semantic Router 0.x. This guide covers 0.0.x to 0.1. The migration guide covers upgrading from 0.x to 1.0.
v0.1 reworked the API and added new capabilities. Some of those changes are breaking. This guide covers what moved, what got renamed, and how to update your code.
add now accepts a list of routes. A single route still works.
# beforeroute_layer = RouteLayer(encoder=encoder)route_layer.add(route1)route_layer.add(route2)# aftersemantic_router = SemanticRouter(encoder=encoder)semantic_router.add([route1, route2]) # several at oncesemantic_router.add(route3) # one still works
To get more than one route back, call the router with a limit:
# before (v0.0.x)route_layer = RouteLayer(encoder=encoder, routes=routes)multiple_routes = route_layer.retrieve_multiple_routes(query_text)# transitional (v0.1.0–0.1.2) — deprecated, not recommendedsemantic_router = SemanticRouter(encoder=encoder, routes=routes, auto_sync="local")query_results = semantic_router._query(query_text)multiple_routes = semantic_router._semantic_classify_multiple_routes(query_results)# after (v0.1.3+, 0.1.5+ recommended)semantic_router = SemanticRouter(encoder=encoder, routes=routes, auto_sync="local")all_routes = semantic_router(query_text, limit=None) # every route that passes its thresholdtop_routes = semantic_router(query_text, limit=3) # the top 3 that pass# to score every route regardless of thresholdsemantic_router.set_threshold(threshold=0.0)all_route_scores = semantic_router(query_text, limit=None)
With limit=1 (the default) you get a single RouteChoice. With limit=None or limit > 1 you get a list.
Watch top_k. It defaults to 5 and caps how many routes come back, independently of limit. If you use limit > 1, raise top_k — 100 or more is reasonable. If you use limit=None to get everything, set top_k to at least the total number of utterances across all your routes.
If you expect local and remote routes to sync at startup, say so with auto_sync:
semantic_router = SemanticRouter( encoder=encoder, routes=routes, index=PineconeIndex(...), auto_sync="local", # push local routes to the remote index)