Skip to main content

Squid AI for Your Data

Use Squid AI to discover insights about your data in real time

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

With Squid 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 where x is the month and y is 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

Squid AI for Your Data 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.

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 integrations, view the database integrations documentation. Once your database integration is added, you can continue to the next step.

  1. Click the '...' 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

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 Rudder 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 is managing the coding so you don't have to!

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:

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:

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!