Conversational Analytics APIで自然言語でデータ分析を行う
2025.11.6

Topics
はじめに
お客様と話す際に、生成AIを用いて自然言語でデータ分析をしたいと相談をいただくことが多くなりました。
選択肢の一つとして Google Cloud の Conversational Analytics API を使った場合にどのような形で分析できるのかをご紹介します。
Conversational Analytics API: データ エージェントを構築し、データを使ってチャットするの記事にも紹介されている通り、様々な実行方法があります。
本記事ではその中でもStreamlit クイックスタート アプリをCloud Shell上で実行、動作確認を行った内容をご紹介します。
リリース状況について
Conversational Analytics API は2025年11月6日現在pre-GAのサービスになります。
現在のリリース状況につきましてはサービスのリリースノートを参照ください
Conversational Analytics API リリースノート
設定の流れ
前提
クイックスタートのサンプルを動作させるための必要条件として、以下の内容が提示されています。
- Python 3.11 or higher
- Git
- Google Cloud SDK (gcloud CLI)
Cloud Shellを利用する場合は上記内容は満たしているかと思います。
設定内容
1. 権限設定
実行時に必要な権限は以下になります。
| Data source | Roles |
|---|---|
| BigQuery | roles/bigquery.dataViewer BigQuery Data Viewer roles/bigquery.user BigQuery User |
| Looker | roles/looker.instanceUser Looker Instance User |
2. 必要なサービスの有効化
クイックスタートアプリを動作させる際に、BigQueryやCloud Shellに加えて Data Analytics API with Gemini を有効にしておく必要があります。
gcloud services enable geminidataanalytics.googleapis.com bigquery.googleapis.com cloudaicompanion.googleapis.com
3. 必要なソースのダウンロード、依存ライブラリのインストール
git clone https://github.com/looker-open-source/ca-api-quickstarts.git cd ca-api-quickstarts pip install -r requirements.txt
pip install時にpip’s dependency resolverエラーが出た場合
自分の環境ではインストール時に依存関係の競合を解決するため、以下のようにバージョンを調整しました。
Installing collected packages: tenacity, numpy
Attempting uninstall: tenacity
Found existing installation: tenacity 8.5.0
Uninstalling tenacity-8.5.0:
Successfully uninstalled tenacity-8.5.0
Attempting uninstall: numpy
Found existing installation: numpy 2.1.3
Uninstalling numpy-2.1.3:
Successfully uninstalled numpy-2.1.3
WARNING: The scripts f2py and numpy-config are installed in '/home/{ユーザ名}/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow 2.19.0 requires numpy<2.2.0,>=1.26.0, but you have numpy 2.2.3 which is incompatible.
google-genai 1.25.0 requires tenacity<9.0.0,>=8.2.3, but you have tenacity 9.0.0 which is incompatible.
- numpy==2.2.3 + numpy==2.1.3 - tenacity==9.0.0 + tenacity==8.3.0
4. .streamlit 内にsecrets.tomlを新規作成する
ca-api-quickstarts/.streamlit 内に実行する環境情報を記したsecrets.tomlを作成する必要があります。
BigQuery をデータソースとする場合は以下のようなproject_idのみですが、Looker をデータソースをする場合はclient_idやclient_secretを設定する必要があります。
[cloud] project_id = "YOUR_PROJECT_ID"
![]()
5. アプリ起動
Cloud Shell上から起動する場合、以下のようにCORSを無効化する必要があります。
streamlit run app.py --server.enableCORS false --server.enableXsrfProtection false
以下のようにlocalhostやIPがいくつか表示されると思いますので、localhostを選択していただくことで別タブとして起動したアプリが表示されるかと思います。


bash: streamlit: command not foundと言われる場合
pip show -f streamlit | grep bin を実行すると/binまでのパスが表示されていると思いますので、こちらのパスを通す必要があります。
$ pip show -f streamlit | grep bin ../../../bin/streamlit ../../../bin/streamlit.cmd
自分の場合だと以下のようなexportコマンドになります。
export PATH=$PATH:/home/{ユーザ名}/.local/bin
data agentの作成
BigQuery or Lookerの接続情報を設定します。
今回はplaceholderにpublic dataが表示されておりましたのでそちらを指定してみます。

作成が完了すると 作成した内容がData agents availableの欄に表示されているかと思います。

agentとのチャット形式でのデータ分析
Chatタブに移動し、作成したAgentを選び Start new conversation with agent を行うことでチャット形式での分析を開始できます。

動作検証
自然言語での分析例①

自然言語での分析例②


生成されたクエリ
SELECT care_taker, COUNT(tree_id) AS count_of_trees FROM bigquery-public-data.san_francisco_trees.street_trees GROUP BY care_taker ORDER BY COUNT(tree_id) DESC LIMIT 5;
自然言語での分析例③


生成されたクエリ
SELECT EXTRACT(YEAR FROM street_trees.plant_date) AS planting_year, street_trees.species, COUNT(DISTINCT street_trees.tree_id) AS count_of_trees FROM bigquery-public-data.san_francisco_trees.street_trees AS street_trees WHERE street_trees.plant_date IS NOT NULL GROUP BY planting_year, street_trees.species ORDER BY planting_year ASC, COUNT(DISTINCT street_trees.tree_id) DESC;
おわりに
BigQueryにデータを集められている場合、ざっくり日本語で何を見たいと指示をすればSQLや説明文の生成ができるので、データ分析の第一歩として利用しやすいなと感じました。
NHN テコラスの採用情報はこちら
テックブログ新着情報のほか、AWSやGoogle Cloudに関するお役立ち情報を配信中!
Follow @twitter2022年に中途入社した人です。好きなAWSサービスはLambdaです。
Recommends
こちらもおすすめ
-
TROCCO を Terraform で構築してみた
2025.11.4
Special Topics
注目記事はこちら
データ分析入門
これから始めるBigQuery基礎知識
2024.02.28

AWSの料金が 10 %割引になる!
『AWSの請求代行リセールサービス』
2024.07.16
