# Cortex Analyst (beta)

Cortex Analyst allows users to query Snowflake data using natural language.

1. [Permissions](#id-1.-permissions)
2. [Enable Cortex Analyst in Select Star](#id-2.-enable-cortex-analyst-in-select-star)
3. [Generate Semantic Views](#id-3.-generate-semantic-views)
4. [Leverage Semantic Views in Your Chatbot](#id-4.-leverage-semantic-views-in-your-chatbot)

## 1. Permissions

We recommend creating a **dedicated role** for Cortex usage. This helps keep ingestion and AI access patterns separate, and ensures only the necessary permissions are granted for Cortex-related use cases.

{% hint style="danger" %}
**Key-pair authentication is required.** See [Using Key Pair Authentication](https://docs.selectstar.com/integrations/snowflake/key-pair) for setup instructions.
{% endhint %}

To use Select Star with Snowflake Cortex, your Snowflake role must be granted the following permissions:

* **USAGE** on the database and schema where semantic views will be created.
* **CREATE SEMANTIC VIEW** on the schema ([Snowflake docs](https://docs.snowflake.com/en/sql-reference/sql/create-semantic-view)).
* **SELECT** on all tables and views referenced by the semantic view.

```sql
-- Create a new role
CREATE ROLE <role_name>;

-- Grant the new role to the Select Star user
GRANT ROLE <role_name> TO USER <select_star_user>;

-- Grant usage on the database and schema where semantic views will be created
GRANT USAGE ON DATABASE <db_name> TO ROLE <role_name>;
GRANT USAGE ON SCHEMA <schema_name> TO ROLE <role_name>;

-- Grant the privilege to create semantic views in that schema
GRANT CREATE SEMANTIC VIEW ON SCHEMA <db_name>.<schema_name> TO ROLE <role_name>;

-- Grant select privileges on the underlying tables/views the semantic view will use
GRANT SELECT ON TABLE MY_DB.MY_SCHEMA.TABLE_A TO ROLE <role_name>;
GRANT SELECT ON TABLE MY_DB.MY_SCHEMA.TABLE_B TO ROLE <role_name>;
```

{% hint style="info" %}
For more details, see [Snowflake: CREATE SEMANTIC VIEW](https://docs.snowflake.com/en/sql-reference/sql/create-semantic-view) and [Key-Pair Authentication](https://docs.selectstar.com/integrations/snowflake/key-pair).
{% endhint %}

## 2. Enable Cortex Analyst in Select Star

To get Cortex Analyst up and running:

1. Confirm that you have the **Admin** role.
2. Navigate to **Settings**.
3. In the sidebar, select your **Snowflake** data source.
4. Click the **Cortex Analyst** tab.
5. Hit the **Enable** button.

![Enable Cortext Analyst](https://3470314135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgAiVthA_yg9UXKuhyY%2Fuploads%2Fgit-blob-21a9f44c3d7d8778d316634bf373cf3535941484%2Fcortex-analyst-configure.png?alt=media)

You'll be prompted to provide:

* **Database Name:** This is where your semantic views will be created.
* **Schema Name:** This is the schema within that database where the semantic views will live.
* **Role:** The role that has the necessary permissions to create semantic views and access the underlying tables.

## 3. Generate Semantic Views

Once Cortex Analyst is enabled, you can generate semantic views directly from the dashboard list page (for any data source) or the table list page (for Snowflake data sources only).

![Show AI assist button](https://3470314135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgAiVthA_yg9UXKuhyY%2Fuploads%2Fgit-blob-f999a522fd9926406f5e4d87442c6d900774b80a%2Fcortex-analyst-generate-select.png?alt=media)

1. Go to the **dashboards page**.
2. Click the **AI Assist** button.
3. Select **Generate Snowflake Semantic View**.

A modal will appear, asking you to provide a **Display Name** and a **Description** for your semantic views.

![Generate Semantic View](https://3470314135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgAiVthA_yg9UXKuhyY%2Fuploads%2Fgit-blob-5254c92e719c072713cb0a6a4633af961253534b%2Fcortex-analyst-generate.png?alt=media)

## 4. Leverage Semantic Views in Your Chatbot

Now that your semantic views are generated, they're automatically available to all users in your organization. They'll provide rich, relevant context for your chatbot, making interactions more informed and insightful.

![Cortext Analyst Ask AI](https://3470314135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgAiVthA_yg9UXKuhyY%2Fuploads%2Fgit-blob-6d00f85f382d053d23739436a7b4a64c7077286f%2Fcortex-analyst-chatbot.png?alt=media)
