Skip to main content

Semantic Hypothesis Routing

Semantic hypothesis routing is a powerful feature that allows you to route incoming messages to the appropriate department or team based on the content of the message. The TrueState Python SDK provides a high-level API for making predictions on your semantic routing models. These models are effective in text-based proccessing tasks where reliability is critical.

Compared to embedding-based semantic routing, semantic hypothesis routing provides a more reliable routing mechanism when the decision between two or more classes is nuanced. This is due to the underlying universal classification model that is used to make predictions vs embedding models used in embedding-based routing.

from truestate.inference import route

sample_text = "I have a question about my order."


def send_to_order_agent(text: str):
return f"Sending message to order agent: '{text}'"

def send_to_support_agent(text: str):
return f"Sending message to support agent: '{text}'"

def send_to_general_agent(text: str):
return f"Would send message to general agent: '{text}'"

routing_strategies = {
"the user message is about an order": send_to_order_agent,
"the user message is about a problem with a product / service": send_to_support_agent,
"__default__": send_to_general_agent
}

response = route(sample_text, routing_strategies, threshold=0.5)

print(response)
# Sending message to order agent: I have a question about my order....