Detecting intents and routing messages
Your chatbot now has memory, and it’s able to retrieve information that matches its memory. What else do you need? Well, you might want to route messages based on the intent of the user. In LangChain, there are two ways for routing messages: a custom routing function and routing based on semantic similarity. While setting up a custom routing function is easy and quick, semantic routing requires using an additional embedding function to achieve better routing results. Let us show you how to do it!
Custom routing functions
First, we need to define the intentions of our users. Let’s start with a simple example. Our bank offers loans, credit cards, and other stuff. Depending on what customers want to buy, they need to be routed to a different sales agent. Let’s see how we build this with a routing function:
from langchain_core.prompts import PromptTemplate from langchain_google_vertexai import ChatVertexAI from langchain_core...