Amity NLQ Optimizer

Amity NLQ Optimizer

With the rise of generative AI, enterprises around the world are leveraging generative AI based chatbot to create chatbot that can dynamically “read” data from their enterprise knowledge repository. In addition to connecting generative AI to their document repository, we start to see more enterprises asking for the ability to retrieve data from their existing structured database. A system that would perform natural language query needs to be developed to properly comprehend and retrieve the right data.

What is Natural Language Query (NLQ)?

Natural Language Query is the ability for a system to understand a user’s question in natural language, and translate the question into SQL query that would correctly retrieve the data needed to answer the question. For example “I want to know YTD sales number” - the system need to be able to comprehend that “YTD” means “Year-to-Date” and to retrieve the sum of all sales number this year.

Natural Language Query (NLQ)

Why is NLQ complex?

Unlike document search where most information inherently resides within the document itself, structured data is traditionally optimized to store data as efficiently as possible, and often lacks explanation and context. Some challenges we often faced are:

Lack of Data Context

A sales data table could have just the column name to hint what the data is, with a data dictionary residing in a separate place.

Lack of Format Context

Categorical, nominal, ordinal, etc - also present a challenge when a system tries to generate the right SQL statement.

Lack of Business Context

A user’s question can sometimes be difficult to translate into the right data source - for example there can be multiple sales data tables with multiple columns denoting several numbers that is very similar to each other - sales number before tax, after tax, or transaction date that differ from the record’s timestamp. This often requires additional business context on how the tables are designed to be used by the business team in each particular scenario.

JOIN Query

Oftentimes a single business question would require data to be retrieved from multiple tables.

Amity NLQ Optimizer

Through working with several enterprises through a vast array of data structures, our AI Labs have created the Amity NLQ optimizer - an agentic workflow optimizer that is designed to specifically handle NLQ tasks.

The optimizer has been proven to improve accuracy from less than 50% to over 95% and is designed to work with complex natural language query scenarios that require the system to correctly retrieve from 10 or more database tables.

Although not utilizing all query enrichment of the optimizer, Amity NLQ Optimizer has also shown improvement in sql-eval benchmark with Spider and BERT Dataset, providing up to 22% improvement.

NLQ Optimizer Architecture

Amity NLQ Optimizer architecture is broken down into 4 distinct stages that perform 4 prompt augmentations before generating an SQL query. These components are designed to be composable and removable, allowing the optimizer to scale up and down its complexity according to the scenario.

This architecture walkthrough is intended for a highly-complex scenario that requires all the components to be activated.

Retrieval Stage

Retrieval Stage is the first that takes in user enquiry in its raw form. This includes the current user’s question as well as all chat history. The input is then processed through a Query Generator that comprehends the user’s question in relation to the chat history, and generates a summarized query of the user’s question.

The query is then sent into an Context Classifier that would classify the intent into a predefined Context Group. This grouping of context allows different sets of scenarios to be grouped away from each other, allowing each context group to have a more specific prompt for their subsequent enrichment stages.

Once the query is classified and sent to a Context Group. Each query group performs 3 query augmentations.

  • Instruction Selection dynamically retrieves the most relevant instruction - a textual instruction that contains the business context of the query group.
  • Schema Linking fetches and links all table schema and definition together.
  • Few Shots Selection dynamically retrieves the most relevant examples containing questions and target SQL query.

SQL Generation Stage

After a Context Group has retrieved and augmented all necessary context into the prompt, a final stage of prompt augmentation is done whereby we add in Chain-of-thought and Reflexion techniques to enhance the SQL Generator’s reasoning capability.

The SQL Generator generates both chain-of-thought and reflection output alongside with the actual SQL Query. The final SQL Query is extracted and sent over to the next stage.

Self Correction Loop

Despite all the preprocessing, the resulting SQL query can still be faulty. The Self Correction stage is therefore designed to be a trial-and-error loop should the database return any error. Error, along with the original content generation prompts, are looped back into SQL Generator for up to 3 times, allowing the generator to learn from the mistakes.

Answer Generation Stage

Once a query result is returned from the database, the result and context guidelines then go into an Answer Generator to respond back to the user.

NLQ Tuning Framework

NLQ Tuning Framework

Amity NLQ Optimizer allows users to continuously improve the quality of the NLQ system. By consolidating all context-specific configuration into Context Group, business users from different groups, with different context domains, can therefore tune their own scenarios without impacting the wider system.

Get Started with Amity NLQ Optimizer

Unlock the power of seamless and intelligent natural language understanding with the Amity NLQ Optimizer. Designed to enhance query interpretation, this cutting-edge solution ensures that your system processes user queries with greater accuracy, delivering precise and context-aware results.

Our team of experts will work with you to integrate the Amity NLQ Optimizer into your platform, optimizing the way your system handles natural language queries to boost efficiency and user satisfaction.

Contact us today to schedule a demo and discover how the Amity NLQ Optimizer can transform the way your system processes queries.

Contact Us