Amazon Quick Chat のマルチデータセットトピックにおけるベストプラクティス
Amazon QuickSight は、データエンジニアによる事前結合を不要とし、生成 AI が自然言語クエリから動的に SQL を生成する「マルチデータセットトピック」機能を導入し、複雑な分析要件への対応力を大幅に強化しました。
キーポイント
AI 駆動型 SQL 生成の仕組み
明示的な関係定義を事前に設定するのではなく、セマンティックレイヤー(カスタム指示語、フィールド合成語、説明)を提供することで、AI がクエリ実行時に文脈を理解し SQL を自動生成します。
複雑なデータ結合の自動化
外部結合、ユニオン、サブクエリ、自己結合、クロスグライン比較など、従来の構造的制約を超えた複雑なデータ統合パターンを自然言語チャットで実現可能にします。
セマンティックガイダンススタック
AI の生成精度を高めるための階層化されたメタデータ構造(データセットレベル、トピックレベルの指示語など)を提供し、データアーキテクトが制御可能なフレームワークを確立しています。
実用的なベストプラクティスと事例
多くの-to-many 結合や再帰的階層などの複雑パターンへの対処法、アンチパターン、および小売分析における5つのデータセットを跨ぐエンドツーエンドの具体例を示しています。
影響分析・編集コメントを表示
影響分析
本記事は、BI ツールにおけるデータ準備のボトルネックを解消し、非技術的な分析担当者が複雑な多テーブル分析を自律的に行えるようになる重要な転換点を示しています。生成 AI の活用により、従来の静的なデータモデルから動的で文脈依存型のクエリ生成へパラダイムシフトが加速し、組織全体のデータドリブン化の障壁を大幅に下げると予想されます。
編集コメント
データエンジニアの負担を減らしつつ、分析の自由度を飛躍的に高める画期的なアプローチであり、特に大規模で複雑なデータ構造を持つ企業にとって即効性のある解決策となるでしょう。ただし、AI の生成精度はセマンティックレイヤーの設計品質に依存するため、適切なガイドラインの策定が成功の鍵となります。
注意: この文書全体で言及されているトピックは、新しいトピック体験(従来のトピックではありません)を指します。違いの詳細については、Amazon Quick におけるマルチデータセットトピックを使用したデータセット横断の統一されたセマンティックレイヤーの構築 をご覧ください。
実際のビジネス上の質問は、多くの場合複数のテーブルにまたがります。製品カテゴリ別の純収益を理解したい小売業者は、販売事実テーブル、返品事実テーブル、および製品次元からデータを参照する必要があります。これらそれぞれは別々のデータセット内に存在します。最近まで、これらのデータセットを橋渡しするには、データエンジニアが事前に結合して単一のデータセットを作成し、アナリストが質問を行う前に Amazon Quick Sight に提供する必要がありました。
Amazon Quick Sight のマルチデータセットトピックはこの状況を劇的に変え、分析チームが複数のデータセットを 2 つの方法のいずれかで単一のトピックに統合できるようにします。1 つ目は明示的な関係キーを定義する方法です(これは別の記事 Amazon Quick Sight マルチデータセット関係のためのデータモデリングベストプラクティス で解説されています)。2 つ目は、生成 AI エンジンに SQL を自ら記述するために十分なセマンティックコンテキストを与える方法です。この記事では後者のアプローチ、つまりチャット機能を活用した AI 生成 SQL に焦点を当てます。
チャット用のトピックを設定する際、事前にリレーションシップを定義する必要はありません。代わりに、データセットレベルのカスタムインストラクション、トピックレベルのインストラクション、フィールドのシノニム、およびフィールドの説明を含むセマンティックレイヤーを作成します。AI はこの文脈を使用して、クエリ実行時に文脈を意識した SQL を生成します。これにより、外部結合(outer joins)、ユニオン(unions)、サブクエリ(subqueries)、自己結合(self-joins)、クロスグリーン比較(cross-grain comparisons)、および条件付き結合ロジックがすべて利用可能となり、リレーションシップグラフに対する構造的な制約はなくなります。
この投稿は、自然言語ベースのチャットによる探索のために Quick Sight トピックを構築または最適化するデータアーキテクト、ビジネスインテリジェンス(BI)エンジニア、およびアナリティクスエンジニア向けです。以下のような成果が得られます:
- チャット駆動型 SQL 生成と定義済みリレーションシップを持つトピックの違いについての明確な理解。
- AI を導くすべてのメタデータを構造化するための階層化されたフレームワークである「セマンティックガイダンススタック(Semantic Guidance Stack)」。
- 例、アンチパターン、およびサンプルインストラクションをそれぞれ含む 8 つの具体的なベストプラクティス。
- 複雑なパターンの処理技術:外部結合、多対多リレーションシップ、再帰的階層構造、ロールプレイ型ディメンション、クロスグリーン比較。
- 定義済みリレーションシップ、セマンティックのみによるガイダンス、およびハイブリッドアプローチのいずれを選択するかを決定するためのフレームワーク。
- 5 つのデータセットを持つ小売アナリティクストピックを使用した完全なエンドツーエンドのウォークスルー。
チャットと定義済みリレーションシップの違い
ベストプラクティスに深入りする前に、Quick Sight の 2 つのマルチデータセットモード間の根本的なアーキテクチャ上の違いを理解しておくことが役立ちます。
トピック内で明示的なリレーションシップを定義すると、Quick Sight は論理的な結合グラフ (join graph) を構築し、クエリ実行時に内部結合 (inner join) を実行します。このグラフは有向非巡回グラフ (DAG: Directed Acyclic Graph) である必要があり、最大 12 のデータセットをサポートし、すべての結合パスが事前に指定されているため結果は決定論的になります。これは、テーブルの結合方法を厳密に適用する必要があるガバナンスされたレポート作成シナリオに適しています。
ユーザーがチャットを通じて質問をすると、Quick Sight の生成 AI は、定義済みリレーションシップまたはトピックのセマンティックレイヤー (指示、説明、同義語) を読み取り、その質問に答えるための SQL を生成します。AI が決定するのは、どのデータセットを照会するか、どの列を使用するか、どのような結合タイプが適切か、そして結果をどのように集約するかです。事前に配線された結合グラフは存在しません。AI は構造ではなく意図に基づいて動作します。
次元 定義済みリレーションシップ AI 生成 SQL
結合定義 トピック内で明示的かつ事前に定義 クエリ実行時に生成 AI によって推論
サポートされる結合タイプ ダッシュボードでは内部結合のみ 内部結合、左外部結合、右外部結合、完全外部結合、ユニオン、サブクエリ
リレーションシップグラフの制約 有向非巡回グラフ (DAG) である必要あり:循環関係は不可 構造的な制約なし
多事実処理
整合された次元キーを必要とする
AI は指示を通じて橋渡しを行う
ガイダンスメカニズム
リレーションシップキーとデータセットのメタデータ
カスタム指示、類義語、説明
柔軟性
スキーマに縛られる
インテントに縛られる
最適な用途
ガバナンスされたダッシュボード、規制環境
探索的アナリティクス、アドホックな質問、パワーユーザー
定義されたリレーションシップはガードレールとして機能し、誤った結合が試みられないようにします。セマンティックメタデータはガイダンスであり、AI を正しく文脈に適した SQL の方向へ導きます。どちらも価値があります。適切な選択はあなたのシナリオ次第です。本記事の後半にある「意思決定フレームワーク」セクションをご覧ください。
定義されたリレーションシップとセマンティックガイダンスは排他的ではありません。ハイブリッドなトピックでは、コアとなる事実から次元への結合にはリレーションシップを定義し、事前に定義されたグラフの範囲外にある探索的なパターンについてはカスタム指示に依存させることができます。「意思決定フレームワーク」セクションでこれについてさらに詳しく探ります。
定義された関係性のベストプラクティスについては、Amazon Quick Sight のマルチデータセット関係性におけるデータモデリングのベストプラクティス および Amazon Quick Sight のマルチデータセット関係性におけるデータモデリングのパターン をご参照ください。
意味論的ガイダンススタック
Quick Chat を駆動する AI エンジンは、SQL を生成する際に 7 つのメタデータ層を活用します。これらが集まって「意味論的ガイダンススタック」を形成しています。各層を理解することは、効果的なメタデータを記述するための基礎となります。
| Layer | Source | Definition | Purpose | Example |
|---|---|---|---|---|
| 1 | Dataset Output; Dataset | データセットレベルの指示 | 各データセットの粒度、目的、キー、およびビジネスルールを定義する | 「SALES_FACT の各行は、ある注文における 1 つのラインアイテムを表します。」 |
| 2 | Topic | トピックレベルの指示 | データセット横断的なロジック、曖昧さ解消ルール、デフォルトの結合動作を定義する | 「ユーザーが『売上』と言った場合、RETURNS_FACT ではなく SALES_FACT を使用してください。」 |
| 3 | Dataset Output; Field | シノニム | ビジネス用語を技術的なフィールド名にマッピングする | 「Revenue」、「Top line」、「Income」 → total_amount
4
データセット出力; フィールド
フィールド記述
列のセマンティクス、単位、NULL の許容性、有効範囲を説明する
"order_date: 顧客が注文を行った UTC 日付、決して NULL でない、形式 YYYY-MM-DD"
6
データセット変換
列の除外
内部キー、ETL タイムスタンプ、非推奨フィールドなどのノイズを除去する
etl_load_timestamp, surrogate_key, is_deleted_flag を非表示にする
7
データセット変換
計算フィールドと名前付きフィルター
AI が直接参照できるように、一般的なビジネス指標やセグメント定義を事前に構築しておく
フィールド: "Net Revenue" = sales.amount – returns.refund_amount
各レイヤーは、AI のデータに対する不確実性を低減します。各層をより正確に埋め込むほど、妥当な SQL 解釈の範囲は狭くなり、生成される結果の精度は向上します。多くのデータセットを持つ記述が疎なトピックでは、信頼性の低い結果が生じます。これは AI に能力がないからではなく、正しい選択を行うために必要な情報が欠落しているからです。
ベストプラクティス 1: データセットレベルの指示をデータ辞書として記述する
データセットレベルのカスタムインストラクションは、AI が各テーブルと接触する最初のポイントであり、そのデータセットに触れるすべての質問に対する文脈を設定します。
何を含めるべきか
- テーブルの目的と粒度:テーブルが何を表し、1 つの行が何を意味するかを明確に記述してください。これにより、AI が二重集計したり、不適切なレベルで集計したりするのを防ぎます。
- 主キー:各行を一意に識別する列(複数可)を特定してください。
- 外部キーのヒント:このデータセット内のどの列が、関連するデータセット内のどの列と対応するかを AI に伝えてください。自然な言語表現を使用します。「このデータセットは、product_id を用いて PRODUCT_DIM テーブルに結合されます。」
- ビジネスルール:導出された計算を平易な英語で記述してください。「収益は、数量に単価を乗じ、割引額を差し引いたものになります。」これにより、AI が誤った数式を考案する可能性を低減します。
- 既知の例外ケース:NULL 値が許容される列、サニタリ値(代用値)、または特殊コードにフラグを立ててください。「order_status = 'VOID' のレコードは、収益計算から除外する必要があります。」
- 集計ルール:各指標に対して正しい集計関数を指定してください。「収益は常に SUM で集計します。AVERAGE や COUNT は使用しないでください。」
良い指示と悪い指示の比較:例
SALES_FACT データセットに関する以下の対比を検討してください。
悪い指示(汎的すぎる):
「これは売上データテーブルです。販売情報を含んでいます。」
良い指示(精密かつ完全):
"SALES_FACT" テーブルには、注文ラインアイテムごとに 1 行ずつ格納されています。
主キー:order_line_id(整数、NULL 不可)。
粒度:1 ラインアイテム = 1 注文上の 1 製品。
主要カラム:
- order_id: ORDER_HEADER_DIM.order_id にリンク
- product_id: PRODUCT_DIM.product_id にリンク
- customer_id: CUSTOMER_DIM.customer_id にリンク
- order_date_key: DATE_DIM.date_key にリンク(整数、YYYYMMDD 形式)
収益 = quantity * unit_price - discount_amount。常に SUM で集計してください。
order_status が 'VOID' の行は、すべての収益計算から除外してください。
このテーブルは UTC 時間 02:00 に毎夜更新されます。"
避けるべきアンチパターン
- 過度に汎用的な指示:「このテーブルには販売データが含まれています」といった指示では、AI が実行可能な文脈を得られません。
- 過度に厳格な SQL スニペット:指示内に生 SQL を埋め込む(例:"always add WHERE is_deleted = 0")と、AI のクエリ構築と競合する可能性があります。代わりにビジネス言語によるルールを使用し、永続的なフィルタは Quick Sight のデータセット変換エディタでデータセットレベルに適用してください。
- 矛盾するルール:データセットレベルで収益を SUM と定義しながら、フィールドレベルで AVERAGE 集計を定義すると、AI は矛盾したシグナルを受け取ることになります。すべてのレイヤーで一貫性を保ってください。
ベストプラクティス 2:クロスデータセットロジックのためのトピックレベルの指示文を書く
データセットレベルの指示は個々のテーブルを記述するものです。一方、トピックレベルの指示は、AI に対してテーブル間の関係性、用語が曖昧な場合にどちらのデータセットを優先すべきか、そしてクロスデータセット計算をどのように処理するかを伝えます。これらを組み合わせることで、AI はあなたのドメインに関する完全な像を得ることができます。
トピックレベルの指示に含めるべき内容
- 概念的関係:正式な結合キーを定義していなくても、データセットがどのように接続されているかを記述します。「SALES_FACT と RETURNS_FACT は、customer_id を介して CUSTOMER_DIM に、product_id を介して PRODUCT_DIM にそれぞれリンクしています。」
- 曖昧さ解消ルール:同じビジネス用語が複数のデータセットやフィールドにマッピングされる可能性がある場合、AI がどちらを優先すべきかを指示します。「ユーザーが『売上』について質問する場合は SALES_FACT を使用し、『返品』または『返金』については RETURNS_FACT を使用します。『純売上』については両者を結合します。」
- デフォルトの結合動作:意図した意味論を保持する結合方向を指定します。「事実テーブルから次元テーブルへの LEFT JOIN(外部結合)を優先し、一致する次元レコードを持たない事実が静かに除外されないようにします。」
- 複数事実の解決:複数の事実テーブルをどのように組み合わせるかを説明します。「実績と予測を比較するには、まず DAILY_SALES を月レベルに集約してから、month_key と store_id で MONTHLY_FORECAST に結合します。」
- 跨界的なビジネス定義:「純収益 = SALES_FACT.total_amount から RETURNS_FACT.refund_amount を差し引いたもの。二重計上を避けるために常に order_id で結合します。」
- ヒエラルキーのナビゲーション:「製品ヒエラルキー:PRODUCT_DIM.product_id → PRODUCT_DIM.subcategory_id → PRODUCT_DIM.category_id。ドリルダウン分析ではこの順序で集約してください。」
例:小売分析における完全なトピックレベル指示ブロック
以下の例は、5 つのデータセットを含む小売分析用トピック向けの、本番環境で即座に使用可能なトピックレベル指示ブロックを示しています。
トピック:小売分析
このトピックに含まれるデータセット:
- SALES_FACT: 1 日ごとの注文行項目(粒度:注文ごとに 1 行)
- RETURNS_FACT: 返品された注文行項目(粒度:注文行ごとに 1 件の返品)
- CUSTOMER_DIM: 顧客マスター(粒度:顧客ごとに 1 行)
- PRODUCT_DIM: 製品カタログ(粒度:製品 SKU ごとに 1 行)
- DATE_DIM: 日付属性(粒度:暦日のごとに 1 行)
曖昧さ解消ルール:
- 「sales」「revenue」「orders」 -> SALES_FACT
- 「returns」「refunds」「credits」 -> RETURNS_FACT
- 「net sales」「net revenue」 -> order_line_id で SALES_FACT と RETURNS_FACT を LEFT JOIN
- 「customer」「buyer」「shopper」 -> CUSTOMER_DIM
- 「product」「item」「SKU」「category」 -> PRODUCT_DIM
デフォルトの結合方向:
- SALES_FACT を customer_id で CUSTOMER_DIM に LEFT JOIN
- SALES_FACT を product_id で PRODUCT_DIM に LEFT JOIN
- SALES_FACT を order_date_key = date_key で DATE_DIM に LEFT JOIN
データセット間定義:
- 純収益 (Net Revenue) = SUM(SALES_FACT.total_amount) - SUM(RETURNS_FACT.refund_amount)
- 返品率 (Return Rate) = COUNT(RETURNS_FACT.order_line_id) / COUNT(SALES_FACT.order_line_id)
粒度整合性に関する注意:
- SALES_FACT と RETURNS_FACT は日次粒度です。
- 月次集計を行う場合は、DATE_DIM.year_month_key で GROUP BY してください。
行レベルセキュリティ (Row-Level Security: RLS) に関する注意:
- 各データセットは独自の RLS を適用しています。RLS フィルターを回避しようとしないでください。
アンチパターン:データセットレベルの指示と矛盾する
SALES_FACT データセットレベルの指示に「収益 = 数量 * 単価 – 割引額」とあり、トピックレベルの指示に「純収益 = 総額」とある場合、AI は矛盾した定義を受け取ることになります。必ずデータセットレベルとトピックレベルの指示が整合していることを確認してください。トピックレベルの指示は、単一データセットの意味を再定義するのではなく、クロスデータセットの文脈を追加するものであるべきです。
ベストプラクティス 3:ユーザーの実際の話し方に合わせた類義語を設計する
類義語は、ユーザーが質問を表現する方法と、技術的なスキーマで呼ばれているものの間のギャップを埋めます。ビジネスアナリストは「収益」と言いますが、データベースのカラム名は total_amount です。マーケティングマネージャーは「離脱(churn)」と言いますが、スキーマでは customer_status = 'churned' としてフラグが立ちます。類義語がない場合、AI はマッピングを推測する必要があり、推測は一貫性のない結果を生み出します。
類義語カバレッジ戦略
類義語は以下の 4 つの語彙階層に整理してください:
- エグゼクティブ言語(KPI 名):経営陣がボード資料で使用する用語。「Revenue」、「EBITDA」、「Market Share」、「NPS」。
- アナリスト言語(指標定義):BI チームが使用する用語。「Gross Margin」、「AOV」(平均注文額)、"CAC"(顧客獲得コスト)。
- ドメイン専門用語:業界固有の用語。小売業の場合:"SKU"、"planogram"、"shrinkage"。SaaS の場合:"MRR"、"ARR"、"seats"。
- 略語と頭字語:"YTD"、"QTD"、"MTD"、"LTM"、"TTM"。
サンプル類語マッピングテーブル
| ユーザー表現 | 技術分野 / フィルター | 備考 |
|---|---|---|
| Revenue, Sales, Income, Top Line | SALES_FACT.total_amount | 4 つの用語をすべて同一カラムにマップ |
| Churn, Attrition, Lost Customers | CUSTOMER_DIM.status = 'churned' | 類語は単なるカラムではなく、フィルタ条件としてマップ |
| AOV, Average Order Value, Avg Basket | SUM(total_amount)/COUNT(DISTINCT order_id) | フィールド説明にも計算式を記載 |
| Category, Department, Aisle | PRODUCT_DIM.category_name | リテール分野の専門用語マッピング |
| Store, Location, Branch, Shop | STORE_DIM.store_name | 同一概念に対する複数のビジネス用語 |
| YTD, Year to Date | DATE_DIM filter: year = current year AND date | 時間知能(time-intelligence)における類語 |
類語数のガイドライン
一般的にクエリされるカラムあたり、3〜7 個の類語を目標とします。3 未満では一般的な語彙にギャップが生じ、10 を超えると曖昧な用語が含まれすぎて複数のフィールドに一致するリスクがあります。内部利用やめったにクエリされない技術分野の場合、類語は 0〜1 個とするか、あるいはそのフィールド自体を除外するのが適切です。
ベストプラクティス 4:フィールド説明とセマンティックタイプの充実
フィールド説明は、AI に対して各カラムの意味、単位、制約、および意図された用途を正確に理解させるものです。類語が語彙を扱い、指示がロジックを扱うのに対し、説明はデータのセマンティクス(意味)、つまり値が実際に何を表すかを扱います。
効果的なフィールド記述の作成
AI ユーザー向けに記述する、人間向けではない
必ず JSON 形式で返してください。translation フィールドのみ。他のフィールド (technical_terms 等)は一切追加しないこと — 余計なフィールドを書こうとして本文翻訳がトークン上限で打ち切られる事故を防ぐため:
{"translation": "翻訳全文"}
原文を表示
Note: The topics referenced throughout this document refer to the new Topics experience (not legacy Topics). For details on the differences, see Build a unified semantic layer across datasets with multi-dataset Topics in Amazon Quick.
Most real-world business questions span multiple tables. A retailer who wants to understand net revenue by product category must draw from a sales fact table, a returns fact table, and a product dimension. Each of these lives in a separate dataset. Until recently, bridging those datasets required a data engineer to pre-join them and deliver a single dataset to Amazon Quick Sight before any analyst could ask a question.
Amazon Quick Sight’s Multi-Dataset Topics change that equation by letting analytics teams bring multiple datasets into a single Topic in one of two ways. You can define explicit relationship keys (covered in the companion post, Data modeling best practices for Amazon Quick Sight multi-dataset relationships , or you can equip the generative AI engine with enough semantic context to write SQL itself. This post focuses on the second path: Chat-powered, AI-generated SQL.
When you configure a Topic for Chat, you do not need to define relationships in advance. Instead, you author a semantic layer that includes dataset-level custom instructions, topic-level instructions, field synonyms, and field descriptions. The AI uses that context to generate context-aware SQL at query time. This puts outer joins, unions, subqueries, self-joins, cross-grain comparisons, and conditional join logic all within reach, with no structural constraint on the relationship graph.
This post is for data architects, business intelligence (BI) engineers, and analytics engineers building or optimizing Quick Sight Topics for natural-language Chat-based exploration. You will come away with:
- A clear understanding of how Chat-driven SQL generation differs from defined-relationship Topics.
- A layered framework, the Semantic Guidance Stack, for structuring all the metadata that guides the AI.
- Eight concrete best practices, each with examples, anti-patterns, and sample instructions.
- Techniques for handling complex patterns: outer joins, many-to-many, recursive hierarchies, role-playing dimensions, and cross-grain comparisons.
- A decision framework for choosing between defined relationships, semantic-only guidance, and hybrid approaches.
- A complete end-to-end walkthrough using a retail analytics Topic with five datasets.
How Chat differs from defined relationships
Before diving into best practices, it helps to understand the fundamental architectural distinction between Quick Sight’s two multi-dataset modes.
When you define explicit relationships in a Topic, Quick Sight builds a logical join graph and executes inner joins at query time. The graph must be a directed acyclic graph (DAG), supports up to 12 datasets, and produces deterministic results because every join path is pre-specified. This suits governed reporting scenarios where you need to enforce exactly how tables combine.
When a user asks a question through Chat, Quick Sight’s generative AI reads either the defined relationships or your Topic’s semantic layer (instructions, descriptions, and synonyms) and generates SQL to answer that question. The AI determines which datasets to query, which columns to use, what join type is appropriate, and how to aggregate the result. There is no pre-wired join graph. The AI operates on intent, not structure.
Dimension
Defined Relationships
AI-Generated SQL
Join definition
Explicit, pre-defined in Topic
Inferred by generative AI at query time
Join types supported
Inner join only for dashboards
Inner, left, right, full outer, union, subquery
Relationship graph constraint
Must be directed acyclic graph (DAG): no circular relationship
No structural constraint
Multi-fact handling
Requires conformed dimension keys
AI bridges via instructions
Guidance mechanism
Relationship keys + dataset metadata
Custom instructions + synonyms + descriptions
Flexibility
Schema-bound
Intent-bound
Best for
Governed dashboards, regulated environments
Exploratory analytics, ad-hoc questions, power users
Defined relationships are guardrails: they prevent incorrect joins from ever being attempted. Semantic metadata is guidance: it steers the AI toward correct, contextually appropriate SQL. Both have value. The right choice depends on your scenario. See the Decision framework section later in this post.
Defined relationships and semantic guidance are not mutually exclusive. A hybrid Topic can define relationships for the core fact-to-dimension joins while relying on custom instruction for exploratory patterns that fall outside the pre-defined graph. The Decision framework section explores this further.
For the best practices of defined relationship, please refer to Data modeling best practices for Amazon Quick Sight multi-dataset relationships and Data modeling patterns for Amazon Quick Sight multi-dataset relationships
The semantic guidance stack
The AI engine that powers Quick Chat draws on seven layers of metadata when generating SQL, collectively forming the semantic guidance stack. Understanding each layer is the foundation for writing effective metadata.
Layer
Source
Definition
Purpose
Example
1
Dataset Output; Dataset
Dataset-Level Instructions
Define the grain, purpose, keys, and business rules of each individual dataset
“Each row in SALES_FACT represents one line item on one order.”
2
Topic
Topic-Level Instructions
Define cross-dataset logic, disambiguation rules, and default join behaviors
“When the user says ‘sales’, use SALES_FACT, not RETURNS_FACT.”
3
Dataset Output; Field
Synonyms
Map business vocabulary to technical field names
“Revenue”, “Top line”, “Income” → total_amount
4
Dataset Output; Field
Field Descriptions
Explain column semantics, units, nullability, and valid ranges
“order_date: UTC date customer placed order, never null, format YYYY-MM-DD”
6
Dataset Transform
Column Exclusions
Remove noise such as internal keys, ETL timestamps, and deprecated fields
Hide etl_load_timestamp, surrogate_key, is_deleted_flag
7
Dataset Transform
Calculated Fields & Named Filters
Pre-build common business metrics and segment definitions the AI can reference directly
Field: “Net Revenue” = sales.amount – returns.refund_amount
Each layer reduces the AI’s uncertainty about your data. The more precisely you populate each layer, the narrower the space of plausible SQL interpretations, and the more accurate the generated results. A sparsely described Topic with many datasets will produce unreliable results. This is not because the AI is incapable, but because the information it needs to make correct choices is absent.
Best practice 1: Write dataset-level instructions as a data dictionary
Dataset-level custom instructions are the AI’s first point of contact with each table and set the context for every question that touches that dataset.
What to include
- Table purpose and grain: State plainly what the table represents and what one row means. This prevents the AI from double-counting or aggregating at the wrong level.
- Primary key: Identify the column(s) that uniquely identify each row.
- Foreign key hints: Tell the AI which column in this dataset matches which column in related datasets. Use natural-language phrasing: “This dataset joins to PRODUCT_DIM on product_id.”
- Business rules: Express derived calculations in plain English. “Revenue equals quantity multiplied by unit_price minus discount_amount.” This reduces the chance the AI invents an incorrect formula.
- Known edge cases: Flag nullable columns, sentinel values, or special codes. “order_status = ‘VOID’ records should be excluded from revenue calculations.”
- Aggregation rules: Specify the correct aggregation function for each measure. “Always SUM revenue. Do not use AVERAGE or COUNT.”
Good vs. bad instructions: examples
Consider the following contrast for a SALES_FACT dataset:
Bad Instruction (too generic):
"This is the sales data table. It contains sales information."Good Instruction (precise and complete):
"SALES_FACT contains one row per order line item.
Primary key: order_line_id (integer, never null).
Grain: one line item = one product on one order.
Key columns:
- order_id: links to ORDER_HEADER_DIM.order_id
- product_id: links to PRODUCT_DIM.product_id
- customer_id: links to CUSTOMER_DIM.customer_id
- order_date_key: links to DATE_DIM.date_key (integer, YYYYMMDD format)
Revenue = quantity * unit_price - discount_amount. Always SUM revenue.
Exclude rows where order_status = 'VOID' from all revenue calculations.
The table is refreshed nightly at 02:00 UTC."Anti-patterns to avoid
- Overly generic instructions: “This table has sales data.” gives the AI no actionable context.
- Overly prescriptive SQL fragments: Embedding raw SQL snippets in instructions (for example, “always add WHERE is_deleted = 0”) can conflict with the AI’s query construction. Use business-language rules instead, and apply permanent filters at the dataset level in Quick Sight’s dataset transform editor.
- Contradictory rules: If you state that revenue should be SUM at the dataset level and then define an AVERAGE aggregation at the field level, the AI will receive conflicting signals. Be consistent across all layers.
Best practice 2: Write topic-level instructions for cross-dataset logic
Dataset-level instructions describe individual tables. Topic-level instructions tell the AI how tables relate to each other, which dataset takes precedence when terms are ambiguous, and how to handle cross-dataset computations. Together they give the AI a complete picture of your domain.
What to include in topic-level instructions
- Conceptual relationships: Describe how datasets connect even when you have not defined formal relationship keys. “SALES_FACT and RETURNS_FACT both link to CUSTOMER_DIM on customer_id and to PRODUCT_DIM on product_id.”
- Disambiguation rules: When the same business term could map to multiple datasets or fields, tell the AI which one to prefer. “When the user asks about ‘sales’, use SALES_FACT. When the user asks about ‘returns’ or ‘refunds’, use RETURNS_FACT. For ‘net sales’, join both.”
- Default join behavior: Specify the join direction that preserves intended semantics. “Prefer LEFT JOIN from fact tables to dimension tables so that facts without matching dimension records are not silently dropped.”
- Multi-fact resolution: Explain how to combine multiple fact tables. “To compare actuals versus forecast, join DAILY_SALES to MONTHLY_FORECAST by rolling up DAILY_SALES to the month level first, then join on month_key and store_id.”
- Spanning business definitions: “Net revenue = SALES_FACT.total_amount minus RETURNS_FACT.refund_amount. Always join on order_id to avoid double-counting.”
- Hierarchy navigation: “Product hierarchy: PRODUCT_DIM.product_id → PRODUCT_DIM.subcategory_id → PRODUCT_DIM.category_id. Roll up in this order for drill-down analysis.”
Example: Full topic-level instruction block (retail analytics)
The following example shows a production-ready topic-level instruction block for a retail analytics Topic containing five datasets:
Topic: Retail Analytics
Datasets in this Topic:
- SALES_FACT: daily order line items (grain: one line item per order)
- RETURNS_FACT: returned order line items (grain: one return per order line)
- CUSTOMER_DIM: customer master (grain: one row per customer)
- PRODUCT_DIM: product catalog (grain: one row per product SKU)
- DATE_DIM: date attributes (grain: one row per calendar day)
Disambiguation rules:
- "sales", "revenue", "orders" -> SALES_FACT
- "returns", "refunds", "credits" -> RETURNS_FACT
- "net sales", "net revenue" -> join SALES_FACT LEFT JOIN RETURNS_FACT on order_line_id
- "customer", "buyer", "shopper" -> CUSTOMER_DIM
- "product", "item", "SKU", "category" -> PRODUCT_DIM
Default join directions:
- SALES_FACT LEFT JOIN CUSTOMER_DIM on customer_id
- SALES_FACT LEFT JOIN PRODUCT_DIM on product_id
- SALES_FACT LEFT JOIN DATE_DIM on order_date_key = date_key
Cross-dataset definitions:
- Net Revenue = SUM(SALES_FACT.total_amount) - SUM(RETURNS_FACT.refund_amount)
- Return Rate = COUNT(RETURNS_FACT.order_line_id) / COUNT(SALES_FACT.order_line_id)
Grain alignment note:
- SALES_FACT and RETURNS_FACT are daily grain.
- For monthly aggregations, GROUP BY DATE_DIM.year_month_key.
Row-Level Security note:
- Each dataset enforces its own RLS. Do not attempt to circumvent RLS filters.Anti-pattern: Contradicting dataset-level instructions
If your SALES_FACT dataset-level instruction says “revenue = quantity * unit_price – discount_amount” and your topic-level instruction says “net revenue = total_amount”, the AI will receive contradictory definitions. Always make sure dataset-level and topic-level instructions are consistent. Topic-level instructions should ADD cross-dataset context, not redefine single-dataset semantics.
Best practice 3: Design synonyms for how users actually talk
Synonyms bridge the gap between how your users express questions and what your technical schema calls things. A business analyst says “revenue”, but your database column is total_amount. A marketing manager says “churn”, but your schema flags it as customer_status = 'churned'. Without synonyms, the AI must guess the mapping, and guesses produce inconsistent results.
Synonym coverage strategy
Organize your synonyms into four vocabulary tiers:
- Executive language (KPI names): The terms leadership uses in board decks. “Revenue”, “EBITDA”, “Market Share”, “NPS”.
- Analyst language (metric definitions): The terms your BI team uses. “Gross Margin”, “AOV” (average order value), “CAC” (customer acquisition cost).
- Domain jargon: Industry-specific terminology. For retail: “SKU”, “planogram”, “shrinkage”. For SaaS: “MRR”, “ARR”, “seats”.
- Abbreviations and acronyms: “YTD”, “QTD”, “MTD”, “LTM”, “TTM”.
Sample synonym mapping table
User Expression
Technical Field / Filter
Notes
Revenue, Sales, Income, Top Line
SALES_FACT.total_amount
Map all four terms to same column
Churn, Attrition, Lost Customers
CUSTOMER_DIM.status = ‘churned’
Synonym maps to filtered condition, not just column
AOV, Average Order Value, Avg Basket
SUM(total_amount)/COUNT(DISTINCT order_id)
Document the formula in field description too
Category, Department, Aisle
PRODUCT_DIM.category_name
Retail domain jargon mapping
Store, Location, Branch, Shop
STORE_DIM.store_name
Multiple business terms for same concept
YTD, Year to Date
DATE_DIM filter: year = current year AND date
Time-intelligence synonym
Guidelines for synonym quantity
Aim for 3 to 7 synonyms per commonly queried column. Fewer than 3 leaves common vocabulary gaps. More than 10 risks introducing ambiguous terms that match too many fields. For internal or rarely queried technical fields, 0–1 synonyms is appropriate, or exclude the field entirely.
Best practice 4: Enrich field descriptions and semantic types
Field descriptions give the AI a precise understanding of each column’s meaning, unit, constraints, and intended use. While synonyms handle vocabulary and instructions handle logic, descriptions handle data semantics: what the value actually represents.
Writing effective field descriptions
Write descriptions for an AI consumer, not a human
関連記事
ビジネスコンテキストを付与:Amazon QuickSight のレガシートピックからセマンティックデータセットへ移行
Amazon Quick のマルチデータセットトピック機能で、データセット横断の統一セマンティックレイヤーを構築
OpenAI、GPT-5.5 に深い推論を委譲する全二重音声モデル「GPT-Live」および「GPT-Live-1 mini」を発表
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み