Cortex Search Example

Using the Cortex Search Template

This guide walks you through the process of using the Snowflake Cortex Search Template to create an intelligent search experience over your Snowflake data using natural language queries.

Overview

The Snowflake Cortex Search Template demonstrates how to build a natural language search interface for your Snowflake data. In this guide, we'll work with an Airbnb listings dataset to show how Cortex Search can help users explore and analyze data through conversational queries.

You'll learn how to:

  • Set up and configure a Cortex Search service
  • Grant necessary permissions
  • Deploy and interact with an AI agent that can answer questions about your data

Prerequisites

Before starting this guide, ensure you have:

After following the Snowflake tutorial to create a Cortex Search service, you should have the following objects created:

Object NameDescription
cortex_search_tutorial_db.public.airbnb_listingsContains the Airbnb listings data
cortex_search_tutorial_db.public.airbnb_svcThe Cortex Search service configured for the listings data

Here's what the data looks like:

Sample of Search service data in Snowflake
Sample of Search service data in Snowflake

Using the Template

Grant Required Permissions

Before your agent can use the Cortex Search service from Sema4.ai Studio, you need to grant it the necessary permissions. Run the following SQL commands as a user with appropriate privileges (ACCOUNTADMIN or similar):

Remember to update the following statements with the role you used when linking Studio to Snowflake.

GRANT USAGE ON DATABASE CORTEX_SEARCH_TUTORIAL_DB TO PUBLIC;
GRANT USAGE ON SCHEMA CORTEX_SEARCH_TUTORIAL_DB.PUBLIC TO PUBLIC;
GRANT SELECT ON ALL TABLES IN SCHEMA CORTEX_SEARCH_TUTORIAL_DB.PUBLIC TO PUBLIC;
GRANT USAGE ON CORTEX SEARCH SERVICE cortex_search_tutorial_db.public.airbnb_svc TO PUBLIC;
GRANT USAGE ON WAREHOUSE CORTEX_SEARCH_TUTORIAL_WH TO PUBLIC;

When executing the above SQL commands in Snowsight, remember to make sure to run them all one by one.

Create the Agent

  1. Open Sema4.ai Studio
  2. Click the Try Now button under Template Agents section, or click Agents in the left-hand sidebar.
  3. Find the Cortex Search Example template and click the Create button.
Cortex Search Template
Cortex Search Template

Configure the Snowflake Cortex Search Actions

The agent has one action package: Snowflake Cortex Search. This package contains actions to use the Cortex Search service, and it needs to be configured with the correct database, schema, and Cortex Search service.

  1. Click Configure next to the Snowflake Cortex Search action
Configure the action
Configure the action
  1. Add the following configuration:
    SettingValue
    DatabaseCORTEX_SEARCH_TUTORIAL_DB
    SchemaPUBLIC
    Cortex Search serviceAIRBNB_SVC
    WarehouseCORTEX_SEARCH_TUTORIAL_WH - or any other compute warehouse you have access to
Configure parameters for Snowflake Cortex Search
Configure parameters for Snowflake Cortex Search

You can click the icon in any input field to reveal its contents.

  1. Click Confirm to save the configuration

Deploy the Agent

Once configuration is confirmed, the Deploy button will become active. Click it to deploy your agent. It'll take a minute or two to deploy.

Review the Runbook

After deployment, you'll be taken to the agent chat view:

Agent chat view, and the Runbook editor
Agent chat view, and the Runbook editor

Once your agent is up and running, you'll be taken to the agent chat view. Take a moment to review what you have created. Open the runbook to review what the agent is tasked with. You don't need to make any changes to the runbook, but it is what you edit to change the agent's behavior.

Just close the editor when you are ready to start chatting with the agent.

Start Chatting

Close the runbook and start interacting with your agent. Try asking questions like:

Are there specific neighborhoods or areas where prices are consistently higher or lower?

Agent chat and responses
Agent chat and responses

The agent uses natural language understanding to interpret your questions and leverages the Cortex Search service to find relevant information in your data.

Conversation Guide

Use these example messages to explore your Airbnb data with Cortex Search. Each message gives you a sense for the different capabilities of the agent, from basic data exploration to complex analysis.

What can you tell me about the data you have?

Quickly grasp the scope and structure of your Airbnb dataset, setting the foundation for deeper exploration.

Can you analyze the different types of cancellation policies by room type?

Uncover insights into how cancellation policies vary across different accommodation types, informing pricing and booking strategies.

Tell me more about the super strict policies

Dive deep into specific policy types, combining Snowflake data with external sources for a comprehensive understanding of their implications.

Can you perform a pricing analysis for all properties with a super strict policy?

Leverage data filtering and analysis capabilities to uncover pricing trends for properties with specific policies, enabling data-driven decision-making.

Tell me more about Moderate and do the same analysis

Seamlessly compare different policy types and their associated pricing trends, facilitating informed strategy adjustments and market positioning.

Additional actions can be added to agents at any time simply by clicking Edit Agent > Add Action

Deploying agent in Team Edition Control Room

When deploying the agent in Team Edition Control Room running in SPCS, you will need to ensure that you grant the necessary privileges to the application. If you have installed the application with something else than standard app name, remember to update the statements below.

GRANT USAGE ON DATABASE CORTEX_SEARCH_TUTORIAL_DB TO APPLICATION ENTERPRISE_AI_AGENTS_TEAM_EDITION;
GRANT USAGE ON SCHEMA CORTEX_SEARCH_TUTORIAL_DB.PUBLIC TO APPLICATION ENTERPRISE_AI_AGENTS_TEAM_EDITION;
GRANT SELECT ON ALL TABLES IN SCHEMA CORTEX_SEARCH_TUTORIAL_DB.PUBLIC TO APPLICATION ENTERPRISE_AI_AGENTS_TEAM_EDITION;
GRANT USAGE ON CORTEX SEARCH SERVICE cortex_search_tutorial_db.public.airbnb_svc TO APPLICATION ENTERPRISE_AI_AGENTS_TEAM_EDITION;
GRANT USAGE ON WAREHOUSE CORTEX_SEARCH_TUTORIAL_WH TO APPLICATION ENTERPRISE_AI_AGENTS_TEAM_EDITION;

Next Steps

Now that you've successfully set up the Cortex Search template with sample data, you can:

  1. Apply this template to your own datasets by creating a new Cortex Search service
  2. Explore the Snowflake Cortex Analyst Template for more advanced analysis capabilities
  3. Combine both templates to create powerful data exploration and analysis solutions