A cheap way to route user messages ("billing", "tech support", "sales") without an LLM call: embed a few example queries per route, average them into a centroid, and send each new query to the nearest centroid. If nothing is close enough, fall back to a general handler.
Implement:
fit_centroids(examples): examples maps route names to lists of embedding vectors. Return a dict of unit-length centroids (normalise each example first, average, then normalise again).route(query, centroids, threshold=0.5): the route with the highest cosine similarity (ties: alphabetical), or "fallback" if the best similarity is below thresholdrouting_accuracy(queries, labels, centroids, threshold=0.5): the fraction routed to the correct label