Table queries

Overview

Table queries enable assistants to generate and execute SQL queries on structured data before replying (CSV, Notion Databases, Google Sheets).

This comes as complement of the Search Data Source assistant action which generally falls short on quantitative questions (semantic search presents chunk of data ordered by pertinence to the assistant that make it impossible for the assistant to properly answer quantitative questions since it does not have access to the entire data). Instead Table Queries allow the assistant to query these structured data sources using SQL (query language), enabling the assistant to answer analytical questions.

There are two ways to use Table Queries:

  • On Tables manually created in Folders (CSV upload, or API)
  • On Tables automatically discovered by Dust from Google Drive (Sheets) and Notion (Databases)
Untitled

Use-cases

Table queries are suited for quantitative questions. ****Conversely to semantic search, they are not suited for questions on unstructured / raw text data. Both actions (Data Source Search and Table Queries) should be use complementary based on your use-case.

Example

carsproduction_yearcolordescription
toyota2001redPerfect car for young people who love the city
mercedes2004redperfect car if you love fancy things
volkswagen2008bluea great car if you like the countryside
renault2012brownideal car if you like going to your local repair shop
citroen2020greena great car if you don’t like cars

The following question is well suited for a Table Query but poorly suited for Data Source search:

What is the most common color for cars produced between 2000 and 2010 ?

The following question is poorly suited for a Table Query but well suited for Data Source search:

What is the best car to buy if I live in NYC ?

Creating assistants with Table Queries

When creating or editing an assistant, in the Action & Data sources section select Add a tool with the Query Tables method.

Screenshot 2024-02-27 at 13.18.00.png

Select one or more tables that you would like your assistant to use.

Joining tables together (advanced)

Assistant have the ability to use data from multiple tables at once, and even join tables together, even if the tables come from different data sources.

To enable this, you can simply pick several tables when creating your assistant.

If you want your assistant to join data between tables, it is useful to explain how to join the tables in the assistant’s instructions.

Consider this example with a users table and an orders table:

nameemail
john powell[email protected]
tom peralta[email protected]
product_nameuser_email
solid gold lint roller[email protected]
tungsten toothbrush handle[email protected]

To help the assistant properly join data between these tables it is desirable to add something like this in the instructions:

You can join data between the users and orders tables using respectively the email and user_email columns

This is especially true in more complex use-cases where the ideal join columns are not obvious.

Creating Tables

Creating Tables from CSV files

  1. Make sure you have builder rights on your Dust workspace.

  2. Go to the Build tab and go to Folders . Pick the folder you want to add your table to, or create a new folder by clicking on Add a new folder at the top of the page.

  3. Go to the Tables tab and click on Add table.

    Screenshot 2024-02-27 at 13.12.44.png
  4. Upload a file in CSV format, and enter a good description for your table. Providing a detailed description for your table will help the AI generate better queries !

namedatestage
ACME CORP20/10/2022lead
STARK CORP21/11/2023closing
PERMUTATION LABS19/08/2020customer

Based on this example, a good table description would be:

This table is an extract from our CRM. Each line represents a potential customer, and includes the date of the last meeting we had with them and what stage they are at in our sales pipeline.

Creating Tables from API

You can create Tables from API on existing Folders Data Sources. Please refer to our API documentation available here: Upsert a table

Tables from Google Sheets and Notion Databases

Dust automatically creates a table for every Google Sheet and Notion Database that we find in your connections.

Make sure the Notion and Google Sheet connections are setup, and that the Dust integration has access to the Google Sheets or Notion Databases that you want to use.