If someone doesn’t understand what you’re saying, they ask you to rephrase. You then try different ways to say it until you’re sure you’re on the same page. That’s precisely what the Query Expansion does but for the Chatbot.
What is the Query Expansion component?
The Query Expansion finds related words and synonyms to help AI understand your query and retrieve the correct information. The same method is why Google always understands what you’re looking for, no matter how you say it.
How to connect the Query Expansion component to your Flow
The Query Expansion should be connected right after the chat input. Thanks to this, all the subsequent components use the expanded query.
Input
- Input (required): This is the human query that gets expanded.
- Chat history (optional): Let previous messages give more context to the expansion.
- LLM (optional): Connect an LLM component to change the model used for Query Expansion. By default, the component uses ChatGPT-4o.
TIP: Query Expansion works just as well with older LLMs. Switching to a less advanced model cuts costs and makes the chatbot faster.
Number of Alternatives
This setting limits the number of alternative phrases and words generated. Feel free to adjust this based on your use case. Remember that a higher limit will cost more, and too many alternatives may lower relevancy.
Output
The output is an augmented version of the original query. This component’s output is suitable for any component asking for Input or Context.
The difference Query Expansion makes
You can safely assume that users will find many ways to phrase the same question and make all sorts of spelling mistakes. To demonstrate, we’ll put the Query Expansion through a stress test.
Let’s try a query using an unlikely term. We’ll take it a bit further by making some heavy typos. Lastly, let’s not forget to botch the product name.
This is our final test query:
“What the expendatur of urslab?”
Let’s see how the bot fares without the Query Expansion first:
It figured out we were talking about expenditures but struggled to find suitable information. It then opted to send us to the contact page instead.
Now let’s try with Query Expansion:
This time, it understands the query and retrieves the correct information from linked knowledge sources.
Note: Even without Query Expansion, the chatbot is bound to figure out most queries, but the result may vary. Query Expansion ensures consistency.