Skip to main content

Question-SQL Pairs

Question-SQL pairs are a powerful feature that allows you to map natural language questions to SQL queries. This enables Wren AI to generate SQL queries more accurately and consistently when users ask similar questions in the future.

Save to Knowledge

When you ask questions and get an answer, you can save the question and the SQL query to your knowledge base by clicking the Save to Knowledge button.

Save to Knowledge

Saving successful queries ensures that Wren AI can quickly retrieve the same information in the future when users ask similar questions.

Manually Adding Question-SQL Pairs

You can proactively add question-SQL pairs to your knowledge base:

Add Question-SQL Pair Add Question-SQL Pair Form

Manual addition is useful when you want to prepare your AI assistant to answer specific questions before they're asked, or when you want to optimize a query.

Managing Question-SQL Pairs

The Question-SQL Pairs management page allows you to view, edit, and delete your saved pairs

Question-SQL Pairs Management

Example - Metric Definition

Let's say you want to calculate the average order value (AOV) for your business. You can save the question "What is our average order value?" along with the SQL query that correctly calculates this metric.

As you can see from the screenshot below, we saved a question What is the AOV (average order value?) and the SQL query that calculates the average order value, which is ROUND(SUM(price + freight_value) / COUNT(DISTINCT order_id), 2).

Example

Now, when you ask Wren AI to calculate the average order value, it will learn the definition of AOV you provided and use it to generate the answer.

Example

You can view the SQL query behind the answer to confirm that it is correct.

Example SQL