Skip to main content
All CollectionsBuild your first AI Agent
Install the Native App with an SQL script
Install the Native App with an SQL script

This guide shows how to install the Lang's Native App manually

Updated over a week ago

πŸ’‘ Learn more
This guide shows the steps needed to install the app with SQL script. This gives more transparency and flexibility to the teams managing the provisioning.

If you want to have a look at the SQL script in one file, you can check it here.

Overview

In this guide you will learn how to install our Snowflake AI agents app to empower data teams to create custom agents that derive actionable priorities from customer interaction, driving retention and growth. If you prefer to install it by using the UI, please follow this guide.

1. Install the app from the Snowflake Marketplace

2. Create databases, roles, network rules, and privileges for Lang

3. Launch the Native App


​

1. Install the app from the Snowflake Marketplace

The first step is to request access to our Native App. Once done, our team will review your request and you will be able to start the installation.

The application will show up in Data Products > Apps > Recently Shared with You. After installing the app, a modal window will show up. Click on Configure to go to the next step.

2. Create databases, roles, network rules, and privileges for Lang

🀚 Heads up
Note that the following steps can only be done using the ACCOUNTADMIN role or by an user/role with the appropriate privileges.

Step 1: Set the warehouse to run the installation scripts

Set the warehouse that will be running the scripts to setup the application.

SET USER_WAREHOUSE = '<YOUR_WAREHOUSE>';

-- Set the name of the LangAI application
-- IMPORTANT: Ensure this matches the exact name used during installation
SET LANGAI_APP_NAME = 'LANGAI_APP';

-- Use the same role that installed the application with the appropriate privileges.
-- https://other-docs.snowflake.com/en/native-apps/consumer-installing#set-up-required-privileges
USE ROLE ACCOUNTADMIN;
USE WAREHOUSE IDENTIFIER($USER_WAREHOUSE);

Step 2. Grant necessary privileges

Grant the BIND SERVICE ENDPOINT privilege to the Lang application to enable network ingress and access to the Lang UI. Details of the privilege can be found here.
​
Grant the EXECUTE TASK privilege to enable automatic generation of insights on a weekly basis (when activated).

GRANT BIND SERVICE ENDPOINT ON ACCOUNT TO APPLICATION IDENTIFIER($LANGAI_APP_NAME);

GRANT EXECUTE TASK ON ACCOUNT TO APPLICATION IDENTIFIER($LANGAI_APP_NAME);

Step 3. Create database and schema to save configuration

Database and schema to hold network rules for the Lang application along with usage for the LangAI application.
​

SET LANGAI_APP_DB = CONCAT($LANGAI_APP_NAME, '_APP_DATA');
CREATE DATABASE IF NOT EXISTS IDENTIFIER($LANGAI_APP_DB);
USE DATABASE IDENTIFIER($LANGAI_APP_DB);
CREATE SCHEMA IF NOT EXISTS CONFIGURATION;
USE SCHEMA CONFIGURATION;

Step 4. Create external access integrations

These integrations are necessary to allow the App to make requests to resources outside of Snowflake. They enable secure connections to external services and APIs required for the App's functionality. Learn more here.

Our app needs access to an LLM and Slack. The Slack connection is required to send the AI Agent insights to your selected Slack room.

---------------------
-- CONFIGURE Slack --
---------------------
-- Set up network rule to allow access to Slack
CREATE OR REPLACE NETWORK RULE SLACK_EXTERNAL_ACCESS_NETWORK_RULE
MODE = EGRESS
TYPE = HOST_PORT
VALUE_LIST = ('slack.com');

-- Create external access integration for Slack
-- This enables the app to send insights via Slack
CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION SLACK_EXTERNAL_ACCESS_INTEGRATION
ALLOWED_NETWORK_RULES = (SLACK_EXTERNAL_ACCESS_NETWORK_RULE)
ENABLED = true;

Choosing your LLM

A) Open AI

If you want to use Open AI, you must provide an API token from your organization. Learn how to get an API token.

B) Llama

If you want to use Llama (via Snowflake's Cortex), see the script below.

-------------------
-- CONFIGURE LLM --
-------------------
-- OpenAI configuration is required for app functionality, even if not used.
-- Llama configuration is optional and only needed if you want to use it.
-- If both are configured, OpenAI will be used preferentially by the app.

-- OpenAI Configuration (Required)
SET OPENAI_TOKEN = '<YOUR_OPENAI_TOKEN>'; -- Leave empty if not using OpenAI
SET OPENAI_URL = 'api.openai.com'; -- Use 'not-used' if not using OpenAI

-- Create a secret for OpenAI API calls
CREATE OR REPLACE SECRET OPENAI_TOKEN
TYPE = GENERIC_STRING
SECRET_STRING = $OPENAI_TOKEN;

-- Set up network rule to allow access to OpenAI API
CREATE OR REPLACE NETWORK RULE OPENAI_EXTERNAL_ACCESS_NETWORK_RULE
MODE = EGRESS
TYPE = HOST_PORT
VALUE_LIST = ($OPENAI_URL);

-- Create external access integration for OpenAI
CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION OPENAI_EXTERNAL_ACCESS_INTEGRATION
ALLOWED_NETWORK_RULES = (OPENAI_EXTERNAL_ACCESS_NETWORK_RULE)
ALLOWED_AUTHENTICATION_SECRETS=(OPENAI_TOKEN)
ENABLED = true;

-- Llama Configuration (Optional)
-- Necessary for the app to access to snowflake cortex
-- https://medium.com/snowflake/unlocking-the-power-of-snowflake-native-app-and-cortex-llm-building-applications-with-ease-61ef0d3b5296
GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO APPLICATION IDENTIFIER($LANGAI_APP_NAME);

Step 5. Create application references

These references are necessary to allow the Snowflake Native App to access existing objects in the consumer account. They enable the app to interact with specific tables, views, or other objects that exist outside the application object.

References provide a secure way for the app to access consumer data without knowing the exact schema and object names. Learn more here.

Create the View the agents will use to generate insights

The AI Agents need read access to a Snowflake view containing the unstructured text data generated by your users, such as support tickets, call transcripts, or survey responses.

🀚 The view must have AT LEAST the following columns in order to work:

  • id: The id of the document (ticket, survey, etc.)

  • text: The unstructured text to be analyzed

  • creation_date: The date of creation of the unstructured text

  • user_id: The id of the user that generated the unstructured text

You may include additional columns that may be used by the AI agent to aggregate the insights generated. Here is an example of a view created in Snowflake with the required format:​

-- This is not part of the installation script. If you already configure a view to use with the Native App, you may skip this step.

create or replace view APP_DATABASE.PUBLIC.LANGAI_APP_VIEW(
ID,
TEXT,
CREATION_DATE,
USER_ID,
PLAN
) as SELECT id, text as text, creation_date, user_id, plan FROM APP_DATABASE.PUBLIC.OPSWD_REVIEWS;

The last column plan is not mandatory, but we included so the agent is able to group the insights by the user's subscription plan.

This is a preview of the view we created:

Here is the script that set the references, including the reference to the view:

-- Set reference to OpenAI token
SET OPENAI_TOKEN_REFERENCE = (SELECT SYSTEM$REFERENCE('SECRET', CONCAT($LANGAI_APP_DB, '.CONFIGURATION.OPENAI_TOKEN'), 'PERSISTENT', 'READ', 'USAGE'));
CALL LANGAI_APP.CONFIG.REGISTER_SINGLE_REFERENCE('OPENAI_TOKEN', 'ADD', $OPENAI_TOKEN_REFERENCE);

-- Set reference to OpenAI external access integration
SET OPENAI_EXTERNAL_ACCESS_REFERENCE = (SELECT SYSTEM$REFERENCE('EXTERNAL_ACCESS_INTEGRATION', 'OPENAI_EXTERNAL_ACCESS_INTEGRATION', 'PERSISTENT', 'USAGE'));
CALL LANGAI_APP.CONFIG.REGISTER_SINGLE_REFERENCE('OPENAI_EXTERNAL_ACCESS', 'ADD', $OPENAI_EXTERNAL_ACCESS_REFERENCE);

-- Set reference to Slack external access integration
SET SLACK_EXTERNAL_ACCESS_REFERENCE = (SELECT SYSTEM$REFERENCE('EXTERNAL_ACCESS_INTEGRATION', 'SLACK_EXTERNAL_ACCESS_INTEGRATION', 'PERSISTENT', 'USAGE'));
CALL LANGAI_APP.CONFIG.REGISTER_SINGLE_REFERENCE('SLACK_EXTERNAL_ACCESS', 'ADD', $SLACK_EXTERNAL_ACCESS_REFERENCE);

-- Set reference to the view containing user interactions
-- It allows the app to access and read user interactions for insight generation
-- IMPORTANT: USE FULLY QUALIFIED NAME
SET VIEW_NAME = '<YOUR_DB.YOUR_SCHEMA.YOUR_VIEW>';
SET VIEW_REFERENCE = (SELECT SYSTEM$REFERENCE('VIEW', $VIEW_NAME, 'PERSISTENT', 'SELECT'));
CALL LANGAI_APP.CONFIG.REGISTER_SINGLE_REFERENCE('UNSTRUCTURED_DATA_VIEW', 'ADD', $VIEW_REFERENCE);

3. Launch the Native App

Step 1: Create the warehouse

Create a warehouse for the app to execute queries.

CREATE WAREHOUSE IF NOT EXISTS LANGAI_APP_WAREHOUSE
WAREHOUSE_SIZE = 'X-SMALL'
WAREHOUSE_TYPE = 'STANDARD'
AUTO_SUSPEND = 30
AUTO_RESUME = true
INITIALLY_SUSPENDED = true
COMMENT = 'Langai app warehouse';

-- Grant usage of the warehouse to the app
GRANT USAGE ON WAREHOUSE LANGAI_APP_WAREHOUSE TO APPLICATION IDENTIFIER($LANGAI_APP_NAME)

Step 2: Create the compute pool

Create a compute pool for the application services.

CREATE COMPUTE POOL IF NOT EXISTS LANGAI_APP_COMPUTE_POOL
FOR APPLICATION IDENTIFIER($LANGAI_APP_NAME)
MIN_NODES = 1
MAX_NODES = 1
AUTO_SUSPEND_SECS = 60
INSTANCE_FAMILY = HIGHMEM_X64_S
AUTO_RESUME = true;

-- Grant usage of the compute pool to the app
GRANT USAGE ON COMPUTE POOL LANGAI_APP_COMPUTE_POOL TO APPLICATION IDENTIFIER($LANGAI_APP_NAME);

Step 3: Start the application

The last step is to activate and start the application.

Not that this operation may take several minutes to complete.

CALL LANGAI_APP.APP_PUBLIC.MANUAL_START_APP();

Optional: Create a role to access the app

This step allows for more granular control over who can use the app.

-- Create a new role for LangAI app users if it doesn't already exist
CREATE ROLE IF NOT EXISTS LANGAI_APP_USER_ROLE;

-- Grant the app-specific user role to the newly created role
SET LANGAI_APP_USER = CONCAT($LANGAI_APP_NAME, '.APP_USER');
GRANT APPLICATION ROLE IDENTIFIER($LANGAI_APP_USER) TO ROLE LANGAI_APP_USER_ROLE;

-- Assign the new role to a ROLE or USER
GRANT ROLE LANGAI_APP_USER_ROLE TO USER|ROLE <YOUR_USER|YOUR_ROLE>;

If you want to test the application with sample data, follow our Quickstart guide.

Appendix

Deleting the Lang.ai Native App

You can reset your account and remove all objects associated with Lang.ai using the following script. Note that this will permanently delete all the data from the Native app and this cannot be reverted. Please reach out to support if you have any questions regarding the deletion of the app.

USE ROLE ACCOUNTADMIN;

SET USER_WAREHOUSE = '<YOUR_WAREHOUSE>';
USE WAREHOUSE IDENTIFIER($USER_WAREHOUSE);

-- Set the name of the LangAI application
-- IMPORTANT: This should be the default name of the application as it is installed
SET LANGAI_APP_NAME = 'LANGAI_APP';
SET LANGAI_APP_DB = CONCAT($LANGAI_APP_NAME, '_APP_DATA');

-- Delete the LangAi application and all associated objects.
DROP APPLICATION IF EXISTS IDENTIFIER($LANGAI_APP_NAME) CASCADE;
DROP WAREHOUSE IF EXISTS LANGAI_APP_WAREHOUSE;
DROP COMPUTE POOL IF EXISTS LANGAI_APP_COMPUTE_POOL;
DROP DATABASE IF EXISTS IDENTIFIER($LANGAI_APP_DB);

-- Drop the external access rule created for the LangAI app.
DROP EXTERNAL ACCESS INTEGRATION IF EXISTS OPENAI_EXTERNAL_ACCESS_INTEGRATION;
DROP EXTERNAL ACCESS INTEGRATION IF EXISTS SLACK_EXTERNAL_ACCESS_INTEGRATION;

-- Drop the role created for the user of LangAI app.
DROP ROLE IF EXISTS LANGAI_APP_USER_ROLE;


Additional resources:

Did this answer your question?