Let's be real: as anyone with a younger sibling knows, humans aren't always great at asking for what they want. For example, a six-year-old might say 'I'M HUNGRY 😤", rather than "what's for dinner?". While (hopefully) your agent's users won't be six-year-olds, that doesn't mean they'll be great at writing queries. Luckily, we can use AI to optimize their questions.
Optimizing queries using the Set step
Drag a Set step to above your KB Search step. Then, press the + icon next to Variables to set and select Prompt. This lets us set a variable to the output of a prompt.

When asked to select a prompt, create a new prompt.

Rather conveniently, we can use the Optimize query template to optimize the user's query. This prompt is designed to simplify a full-message query down into something more searchable. For example, it'll turn "Hello, I'm a first time homebuyer and want to understand the best neighbourhoods to purchase a condo in!" into "Best neighborhoods for first-time homebuyers to purchase a condo".

Now our prompt is selected, we need to choose a variable to save it to. Close the prompt window, then click back onto the variable. Then choose Select variable and create a new variable.

Give your variable the name simplified_query
, add a description, then click Create variable.

Updating our KB Search step
Okay, nearly there! The simplified_query
variable now contains an optimized version of the user's question. Now we need to use that variable inside our KB Search step.
Click on your KB Search step and change Question option to use the simplified_query
variable we just created.

That's it! Our agent is now capable of optimizing queries before searching for them in the vector database, improving its accuracy. It's ready for prime time... but there's also some more features you could add.
Resources
Build AI Agents for customer support and beyond
Ready to explore how Voiceflow can help your team? Let’s talk.
