Semantic Router Evaluation
Purpose
Semantic routers direct requests to the appropriate handlers (e.g., to a RAG system, to a summarizer, or to direct generation). Evaluating the quality of routing is critical for the overall system performance.
Metrics
| Metric | Description |
|---|---|
| Accuracy | Proportion of correctly routed requests |
| Precision | Proportion of requests directed to the correct handler among all directed |
| Recall | Proportion of correctly directed requests among all requiring the handler |
| Latency Overhead | Additional delay introduced by the router |
| Fallback Rate | Proportion of requests directed to the fallback handler |
Evaluation Methods
- Gold dataset: labeled queries with expected routes.
- A/B testing: comparison with heuristic rules.
- End-to-end evaluation: assessment of the quality of the final response.
def evaluate_router(router, test_queries):
correct = 0
for query, expected_route in test_queries:
actual_route = router.route(query)
if actual_route == expected_route:
correct += 1
return correct / len(test_queries)