Skip to main content

Query your data sources with AI

Discover insights about your data and generate charts and graphs in real time.

You can interact with the data in a database integration using Squid's Query with AI feature. The client provides a prompt, which can be written in sentence form. Query with AI then responds with a reply in sentence form along with the query it executed to get the result.

With Query with AI, anyone you choose can find key data points, generate charts and graphs, and get answers to questions about data without needing to write queries or graphing functions.

Use cases

You can use Squid AI to get human-readable explanations of your data. Here are some example prompts:

  • How many games has team A won against team B?
  • What is the most popular choice for favorite animal?
  • How many 5-star reviews does Movie A have?
  • Create a line graph of sales in 2022, with x representing the month and y representing the total value of sales in dollars.

You don't need a Squid AI Chatbot integration to use Squid AI for Your Data.

The following guide provides an overview of the key concepts with accompanying code snippets. For a complete code sample and instructions, see the step by step tutorial.

Configure your database integration

Query with AI makes queries on a database integration. The fields available for Squid AI to query come from the database schema. Squid AI also uses descriptions of the collections and fields to help it determine what query to make.

There are two options for providing collection and field descriptions:

  • Manually enter descriptions in your own words.
  • Let Squid AI generate schema descriptions for you.

Manually enter descriptions

Follow these steps to view your database schema and provide collection and field descriptions:

  1. In the Squid Console, click the Integrations tab and find the database you want to use with Squid AI.

If you haven't yet connected the database you want to use with Squid AI, then add the integration now. To learn more about configuring database integration, view the database integrations documentation. Once your database integration is added, you can continue to the next step.

  1. Click the ellipsis (…) button on your database integration, and select Schema from the dropdown menu.

  2. To update the schema based on data that already exists in the database, click Rediscover schema. Alternatively, you can edit your schema directly in the console.

  3. Add descriptions to collections by clicking the pencil button on the collection. Add descriptions to fields by clicking the '...' on the field and selecting Edit field from the dropdown menu.

After rediscovering the schema or editing descriptions, click Save schema to publish the updates.

Adding descriptions to schema

Use AI-generated descriptions

Squid AI can generate collection and field descriptions on your behalf. This functionality queries a small set of data from a collection and passes it along with your schema to ChatGPT.

Note

Squid uses ChatGPT Enterprise, which means none of your data is ever used in model training. If you do not want any database data to be passed to ChatGPT, then do not use AI-generated descriptions. The Query with AI feature does not send any of your database data to ChatGPT, so you can still use the feature with your own manually-generated descriptions.

Follow these steps to view your database schema and create AI-generated collection and field descriptions:

  1. In the Squid Console, click the Integrations tab and find the database you want to use with Squid AI.

If you haven't yet connected the database you want to use with Squid AI, then add the integration now. To learn more about configuring database integration, view the database integrations documentation. Once your database integration is added, you can continue to the next step.

  1. Click the ellipsis (…) button on your database integration, and select Schema from the dropdown menu.

  2. To update the schema based on data that already exists in the database, click Rediscover schema. Alternatively, you can edit your schema directly in the console.

  3. Add descriptions to collections by clicking the pencil button on the collection, and then clicking Add with AI. You can edit the AI-generated description as desired. To save the description, click Update.

  4. Add descriptions to fields by clicking the '...' on the field and selecting Edit field from the dropdown menu, and then clicking Add with AI. You can edit the AI-generated description as desired. To save the description, click Update.

After rediscovering the schema or editing descriptions, click Save schema to publish the updates.

Test Squid AI for Your Data

Once your schema is configured and descriptions are added, you can query your data with Squid AI in the console. In the schema view of your database integration, click the Query with AI button. You can ask the provided AI agent details about your data and test the responses.

Query with AI in the console

Note

Query with AI might take from 30 seconds to a few minutes to respond depending on the complexity of the question and query generated. Squid AI handles the coding, simplifying the process for you.

Add Squid AI to the backend

You can use an Executable to ask questions about your data from the backend.

The following example executes an AI query in an Executable:

Backend code
export class SquidAiDataService extends SquidService {
@executable()
async askQuestion(question: string): Promise<string> {
const aiResponse = await this.squid
.ai()
.executeAiQuery('DATABASE_INTEGRATION_ID', question);

// Log results to view in Squid Console logs
console.log(
`Question: ${question}
Query: ${aiResponse.executedQuery ?? 'No query executed'}
Explanation: ${aiResponse.explanation ?? 'No explanation'}`
);
// Send the answer to the frontend
return aiResponse.answer;
}
}

To execute this function from the frontend client, use the Squid Client SDK:

Client code
const result = await squid.executeFunction(
'askQuestion',
'how many reviews have been added?'
);
console.log(result); // prints a response like 'There have been 47 reviews added.'

Add Squid AI to the frontend

In place of using Squid AI on the backend through an Executable, you can instead use Squid AI to evaluate your data directly through the frontend. However, this method is generally not recommended because it requires an API key that has admin access, thus bypassing all functions that secure your data.

Backend Security

Using the API key provides direct access to your Squid backend, which means it doesn't use any backend Security Service functions to secure your data. You are strongly encouraged to use an Executable and run Squid AI queries on the backend.

Want to try out Squid AI for your Data? Check out our tutorial to see how you can get up and running in a matter of minutes!