Route score thresholds are what defines whether a route should be chosen. If the score we identify for any given route is higher than theDocumentation Index
Fetch the complete documentation index at: https://docs.aurelio.ai/llms.txt
Use this file to discover all available pages before exploring further.
Route.score_threshold it passes, otherwise it does not and either another route is chosen, or we return no route.
Given that this one score_threshold parameter can define the choice of a route, it’s important to get it right — but it’s incredibly inefficient to do so manually. Instead, we can use the fit and evaluate methods of our SemanticRouter. All we must do is pass a smaller number of (utterance, target route) examples to our methods, and with fit we will often see dramatically improved performance within seconds.
Full Example
Define SemanticRouter
As usual we will define ourSemanticRouter. The SemanticRouter requires just routes and an encoder. If using dynamic routes you must also define an llm (or use the OpenAI default).
We will start by defining four routes; politics, chitchat, mathematics, and biology.
HuggingFaceEncoder. Other popular encoders include CohereEncoder, FastEmbedEncoder, OpenAIEncoder, and AzureOpenAIEncoder.
SemanticRouter.
evaluate method. All we need is to pass a list of utterances and target route labels:
Router Optimization
Our optimization works by finding the best route thresholds for eachRoute in our SemanticRouter. We can see the current, default thresholds by calling the get_thresholds method:
fit method and provide our training utterances X, and target route labels y:
0.5 to 0.8 range.
After training we have a final performance of:

