Cortex Code CLI ワークフローの例

このトピックでは、Cortex Code CLI を最大限に活用するのに役立つ一般的なタスクのワークフロー例を示します。データ検出、合成データ生成、ダッシュボードの構築、Cortex Agentの作成などについて説明します。

ユースケース:データ検出とクエリ

このセクションでは、合成データセットを作成し、基本的な分析を実行してダッシュボードを生成する方法について説明します。

Snowflakeアカウントへの接続

cortex -c <your-demo-account>
Copy

またはインタラクティブに接続します。

> connect to <my demo account>
Copy

データの発見と探索

データカタログを検索し、系統を理解して、関連するテーブルを見つけます。

> Find all tables related to customers that I have write access to
Copy

適切な権限を持つ適切なロールがあることの確認

> What privileges does my role have on this database?
Copy

アクセスの問題を診断し、ロールの権限を理解します。

> Why am I getting a permissions error?
Copy

合成データを生成

以下は、さまざまなユースケースで合成データを生成する例です。

Fintech会社の不正分析:

> Generate realistic looking synthetic data into <database name>. Create a table of 10000
  financial transactions where ~0.5% of them are fraudulent. Include Amount, Location,
  Merchant, and Time. Make the fraudulent ones look suspicious based on location or amount.
Copy

製薬会社の治験データ:

> Make a dummy dataset for a clinical trial of a new blood pressure medication. List 100
  patients, their age, their dosage group (Placebo vs. 10mg), and their blood pressure
  readings over 4 weeks.
Copy

顧客チャーンデータ:

> Create a customer churn dataset for a telecom company showing customer usage for 100000
  customers. Include basic demographic data such as fake names, phone numbers, US city and
  state. Also include data usage (GB), call minutes, contract length, and whether they
  cancelled their service (churn). Ensure there's a customer_id column that's unique.
  Create the data locally and then upload it to Snowflake.
Copy

このデータに対する基本的なクエリの実行

> Calculate the Churn Rate grouped by state and contract length. Order the results by the
  highest churn rate first so I can see the most risky regions and contract types.
Copy
> I want to identify the heaviest data users who are also churning.
Copy

インタラクティブなダッシュボードの構築

チャート、フィルター、インタラクティブ性のあるStreamlitアプリを作成し、デプロイします。

Tip

好きなダッシュボードの例を開き(またはオンラインで見つけて)、クリップボードにコピーします。画像をデザイン参照としてCortex Codeに直接貼り付ける(Ctrl+V)ことができます。

> Build an interactive Streamlit dashboard on this data with state filters and use the
  conversation so far for examples of the kinds of charts to show. Use the attached image
  as a template for visuals and branding.
Copy

ダッシュボードが動作し、正常に表示されていることを確認したら、Snowflakeにアップロードします。

> Ensure that the Streamlit app will work with Snowflake and upload it to Snowflake.
  Give me a link to access the dashboard when it's done.
Copy

おめでとうございます。これで、作成したデータセットを表示するStreamlitダッシュボードが動作します。

ユースケース:Cortex Agentの構築

このセクションでは、Snowflake Intelligenceのデータに関する質問に答えるCortex Agentの作成について説明します。顧客の通話記録で既存の合成データを強化します。

Cortex Analyst用のセマンティックビューの作成

データでCortex Analystを使用できるように、セマンティックビューを作成します。尋ねるすべての質問にはデフォルトを使用します。

> Write a Semantic View named DEMO_TELECOM_CHURN_ANALYTICS for Cortex Analyst based on
  this data. Use the semantic-view optimization skill.
Copy

Cortex Search Serviceの作成

まず、顧客のサービス通話を含む合成データを生成します。

> Generate a new table called customer_call_logs. Generate 50 realistic customer service
  transcripts (2-3 sentences each) as PDF files. Some should be angry complaints about
  coverage, others should be questions about billing. Then use the AI_PARSE_DOCUMENT
  function to extract the text and layout information from the PDFs into the TRANSCRIPT_TEXT
  column. Split text into chunks for better search quality.
Copy

次に、トランスクリプトにインデックスを付けるCortex Search Serviceを作成します。

> Create a Cortex Search Service named CALL_LOGS_SEARCH that indexes these transcripts.
  It should index the TRANSCRIPT_TEXT column and filter by CUSTOMER_ID.
Copy

Cortex Agentの作成

Analystと検索サービスの両方を使用するCortex Agentを構築します。

> Build a Cortex Agent that has access to two tools:
  - cortex_analyst: For querying the TELECOM_CUSTOMERS SQL table.
  - cortex_search: For searching the CALL_LOGS_SEARCH service.

  Write a system prompt for this agent:
  - Persona: You are a Senior Retention Specialist.
  - Routing Logic: If the user asks for 'metrics', 'counts', or 'averages', use the
    Analyst tool. If the user asks for 'sentiment', 'reasons', or 'summaries of calls',
    use the Search tool.
  - Output Format: Always verify the customer ID before answering. If the risk score is
    high, end the response with a recommended retention offer (e.g., 'Offer 10% discount').
  - Constraint: Never reveal the raw CHURN_RISK_SCORE to the user; interpret it as 'Low',
    'Medium', or 'High'.
Copy

Snowflake Intelligenceへのデプロイ

Snowflake Intelligenceにエージェントをデプロイします。

> Let's deploy this agent to Snowflake Intelligence.
Copy

おめでとうございます。Snowflake Intelligenceエージェントを正常に作成し、デプロイしました。

これで、Snowflake Intelligenceでこのエージェントにアクセスし、次のような質問ができるようになります。

  • 「お客様は何に対して通話で苦情を言っていますか?」

  • 「$100以上の月額料金の高リスクの顧客を表示してください」

こちらもご覧ください

Cortexコード CLI

インストールと最初のプロンプトをはじめる

スキル

セマンティックモデル、エージェント、ドキュメントに特化した権限

Cortex Analyst

Cortex Analyst ドキュメント