このページでは、BigQuery データソースを使用するデータ エージェントの作成済みコンテキストを指定する方法について説明します。
作成されたコンテキストは、データ エージェントのオーナーがデータ エージェントの動作を形成し、API の回答を絞り込むために提供できるガイダンスです。効果的な作成済みコンテキストにより、Conversational Analytics API データ エージェントは、データソースに関する質問に回答するための有用なコンテキストを取得できます。
作成されたコンテキストは省略可能ですが、強力なコンテキストを提供することで、エージェントはより正確で関連性の高い回答を提供できます。データ エージェントは、作成時と実行時にこのコンテキストを組み込んで、アクション、クエリ、レスポンスが正確で、コンプライアンスに準拠し、ビジネスを認識していることを確認します。このコンテキストは取り込まれてインデックス登録され、エージェントの動作を形成するために使用されます。
作成されたコンテキストを提供するオプション
BigQuery データソースの場合、構造化されたコンテキストとシステム指示を組み合わせて作成されたコンテキストを提供できます。可能な場合は、構造化されたコンテキスト フィールドを使用してコンテキストを提供します。構造化フィールドでカバーされていない補足的なガイダンス(エージェントのトーンや全体的な動作の定義など)には、system_instruction パラメータを使用します。
作成したコンテキストを構成する構造化フィールドとシステム指示を定義したら、次のいずれかの呼び出しで API にコンテキストを提供できます。
- 永続データ エージェントの作成: 作成されたコンテキストをリクエスト本文の
published_contextオブジェクト内に含めて、複数の会話にわたって持続するエージェントの動作を構成します。詳細については、データ エージェントを作成する(HTTP)またはステートフルまたはステートレス チャットのコンテキストを設定する(Python SDK)をご覧ください。 - ステートレス リクエストの送信: チャット リクエストの
inline_contextオブジェクト内で作成されたコンテキストを指定して、特定の API 呼び出しにおけるエージェントの動作を定義します。詳細については、ステートレス マルチターンの会話を作成する(HTTP)またはインライン コンテキストを含むステートレス チャット リクエストを送信する(Python SDK)をご覧ください。 - クエリデータ リクエストを送信する: データベース データソースの場合は、クエリデータ リクエストの
agent_context_referenceオブジェクト内で、作成されたコンテキストのコンテキスト セット ID を指定します。詳細については、データベースのデータソースのデータ エージェント コンテキストを定義するをご覧ください。
構造化コンテキスト フィールドを定義する
このセクションでは、構造化されたコンテキスト フィールドを使用してデータ エージェントにコンテキストを提供する方法について説明します。次の情報を構造化コンテキストとしてエージェントに提供できます。
- テーブルの説明、同義語、タグなどのテーブルレベルの構造化コンテキスト
- テーブルの列の説明、同義語、タグ、サンプル値などの列レベルの構造化されたコンテキスト
- クエリの例: エージェントが質問に回答し、回答で引用するために使用できる自然言語の質問とそれに対応する SQL クエリを指定できます。
- ユーザー定義関数。エージェントが SQL クエリで使用できるカスタム BigQuery ルーチンを指定できます。
テーブルレベルの構造化コンテキスト
tableReferences キーを使用して、質問への回答に利用できる特定のテーブルに関する詳細をエージェントに提供します。テーブル参照ごとに、次の構造化コンテキスト フィールドを使用してテーブルのスキーマを定義できます。
description: テーブルの内容と目的の概要synonyms: テーブルを参照するために使用できる代替用語のリストtags: テーブルに関連付けられているキーワードまたはタグのリスト
次の例は、これらのプロパティを直接 HTTP リクエスト内で構造化されたコンテキストと Python SDK で構造化されたコンテキストとして提供する方法を示しています。
HTTP
直接 HTTP リクエストでは、関連するテーブル参照の schema オブジェクト内にこれらのテーブルレベルのプロパティを指定します。リクエスト ペイロード全体の構造化方法の完全な例については、BigQuery データに接続するをご覧ください。
"tableReferences": [
{
"projectId": "bigquery-public-data",
"datasetId": "thelook_ecommerce",
"tableId": "orders",
"schema": {
"description": "Data for orders in The Look, a fictitious ecommerce store.",
"synonyms": ["sales"],
"tags": ["sale", "order", "sales_order"]
}
},
{
"projectId": "bigquery-public-data",
"datasetId": "thelook_ecommerce",
"tableId": "users",
"schema": {
"description": "Data for users in The Look, a fictitious ecommerce store.",
"synonyms": ["customers"],
"tags": ["user", "customer", "buyer"]
}
}
]
Python SDK
Python SDK を使用する場合は、BigQueryTableReference オブジェクトの schema プロパティでこれらのテーブルレベルのプロパティを定義できます。次の例は、orders テーブルと users テーブルのコンテキストを提供するテーブル参照オブジェクトを作成する方法を示しています。テーブル参照オブジェクトを作成して使用する方法の完全な例については、BigQuery データに接続するをご覧ください。
# Define context for the 'orders' table
bigquery_table_reference_1 = geminidataanalytics.BigQueryTableReference()
bigquery_table_reference_1.project_id = "bigquery-public-data"
bigquery_table_reference_1.dataset_id = "thelook_ecommerce"
bigquery_table_reference_1.table_id = "orders"
bigquery_table_reference_1.schema = geminidataanalytics.Schema()
bigquery_table_reference_1.schema.description = "Data for orders in The Look, a fictitious ecommerce store."
bigquery_table_reference_1.schema.synonyms = ["sales"]
bigquery_table_reference_1.schema.tags = ["sale", "order", "sales_order"]
# Define context for the 'users' table
bigquery_table_reference_2 = geminidataanalytics.BigQueryTableReference()
bigquery_table_reference_2.project_id = "bigquery-public-data"
bigquery_table_reference_2.dataset_id = "thelook_ecommerce"
bigquery_table_reference_2.table_id = "users"
bigquery_table_reference_2.schema = geminidataanalytics.Schema()
bigquery_table_reference_2.schema.description = "Data for users in The Look, a fictitious ecommerce store."
bigquery_table_reference_2.schema.synonyms = ["customers"]
bigquery_table_reference_2.schema.tags = ["user", "customer", "buyer"]
列レベルの構造化コンテキスト
テーブル参照の schema オブジェクト内にネストされている fields キーには、個々の列を記述する field オブジェクトのリストを指定します。すべてのフィールドに追加のコンテキストが必要なわけではありませんが、よく使用されるフィールドに追加の詳細を含めると、エージェントのパフォーマンスを向上させることができます。
field オブジェクトごとに、次の構造化コンテキスト フィールドを使用して、列の基本プロパティを定義できます。
description: 列の内容と目的の簡単な説明synonyms: 列を参照するために使用できる代替用語のリストtags: 列に関連付けられているキーワードまたはタグのリスト
次の例は、直接 HTTP リクエストと Python SDK を使用して、orders テーブル内の status フィールドと users テーブル内の first_name フィールドの構造化コンテキストとしてこれらのプロパティを指定する方法を示しています。
HTTP
直接 HTTP リクエストでは、テーブル参照の schema オブジェクト内に fields オブジェクトのリストを指定することで、これらの列レベルのプロパティを定義できます。
"tableReferences": [
{
"projectId": "bigquery-public-data",
"datasetId": "thelook_ecommerce",
"tableId": "orders",
"schema": {
"fields": [{
"name": "status",
"description": "The current status of the order.",
}]
}
},
{
"projectId": "bigquery-public-data",
"datasetId": "thelook_ecommerce",
"tableId": "users",
"schema": {
"fields": [{
"name": "first_name",
"description": "The first name of the user.",
"tags": "person",
}]
}
}
]
Python SDK
Python SDK を使用する場合は、テーブルの schema プロパティの fields プロパティに Field オブジェクトのリストを割り当てることで、これらの列レベルのプロパティを定義できます。
# Define column context for the 'orders' table
bigquery_table_reference_1.schema.fields = [
geminidataanalytics.Field(
name="status",
description="The current status of the order.",
)
]
# Define column context for the 'users' table
bigquery_table_reference_2.schema.fields = [
geminidataanalytics.Field(
name="first_name",
description="The first name of the user.",
tags=["person"],
)
]
クエリの例
example_queries キーは、エージェントがより正確で関連性の高い回答を提供できるようにする自然言語クエリを定義する example_query オブジェクトのリストを受け取ります。自然言語の質問とそれに対応する SQL クエリの両方をエージェントに提供することで、エージェントがより高品質で一貫性のある結果を提供できるようにガイドできます。
ユーザーの質問が定義済みのサンプルクエリと意味的に一致する場合、エージェントは新しいクエリを生成するのではなく、そのクエリを直接実行することがあります。エージェントが既存のクエリを実行すると、API レスポンスに matched_query オブジェクトが含まれ、検証済みクエリが使用されたことが示されます。エージェントは、回答の中でそのクエリを引用することもあります。
パラメータ化されたクエリの例
静的クエリに加えて、パラメータ化されたサンプルクエリを定義して、エージェントが検証済みのクエリ テンプレートに動的な値を代入できるようにすることもできます。サンプルクエリにパラメータを含めることで、静的な例よりも幅広いユーザーの問い合わせに対応できる柔軟なテンプレートを作成できます。ユーザーの質問がテンプレートと一致すると、エージェントは対応するクエリを実行して、検証済みの回答を提供します。
パラメータ化されたクエリは次のように定義できます。
naturalLanguageQuestionフィールドで、プレースホルダに中かっこ({state}など)を使用します。sqlQueryフィールドで、同じ変数(@stateなど)に BigQuery の名前付きパラメータ構文を使用します。parametersフィールドで、各パラメータの名前、データ型、説明を定義します。
例
次の例は、FAA 空港データセットの静的クエリとパラメータ化クエリの両方を定義する方法を示しています。
HTTP
直接 HTTP リクエストでは、example_queries フィールドに example_query オブジェクトのリストを指定します。各オブジェクトについて、naturalLanguageQuestion キー(ユーザーが質問する可能性のある質問)と対応する sqlQuery キーを指定します。パラメータ化されたクエリの場合は、各パラメータの名前、データ型、説明を含む parameters リストも指定する必要があります。
"example_queries": [
{
"naturalLanguageQuestion": "How many airports are there?",
"sqlQuery": "SELECT COUNT(*) FROM `bigquery-public-data.faa.us_airports`"
},
{
"naturalLanguageQuestion": "How many airports are in {state} with an elevation that is greater than {elevation}?",
"sqlQuery": "SELECT COUNT(*) FROM `bigquery-public-data.faa.us_airports` WHERE LOWER(state_abbreviation) = @state AND elevation > @elevation",
"parameters": [
{
"name": "state",
"dataType": "STRING",
"description": "The state abbreviation in lowercase.",
},
{
"name": "elevation",
"dataType": "FLOAT64",
"description": "The elevation in feet.",
}
]
}
]
Python SDK
Python SDK を使用する場合は、ExampleQuery オブジェクトのリストを指定します。各オブジェクトの natural_language_question パラメータ(ユーザーが尋ねる可能性のある質問)と sql_query パラメータに値を指定します。パラメータ化されたクエリの場合は、QueryParameter オブジェクトのリストも指定する必要があります。
example_queries = [
geminidataanalytics.ExampleQuery(
natural_language_question="How many airports are there?",
sql_query="SELECT COUNT(*) FROM `bigquery-public-data.faa.us_airports`"
),
geminidataanalytics.ExampleQuery(
natural_language_question="How many airports are in {state} with an elevation that is greater than {elevation}?",
sql_query="SELECT COUNT(*) FROM `bigquery-public-data.faa.us_airports` WHERE LOWER(state_abbreviation) = @state AND elevation > @elevation",
parameters=[
geminidataanalytics.QueryParameter(
name="state",
data_type="STRING",
description="The state abbreviation in lowercase.",
),
geminidataanalytics.QueryParameter(
name="elevation",
data_type="FLOAT64",
description="The elevation in feet.",
),
],
)
]
ユーザー定義の関数
user_functions フィールドを使用して、エージェント コンテキストで BigQuery のユーザー定義関数(UDF)を指定できます。カスタムの BigQuery ルーチンを指定すると、エージェントは質問に回答するために必要に応じてそれらを使用できます。
各 UDF には、次のプロパティを指定できます。
routineReference: プロジェクト ID、データセット ID、ルーティン ID を含む BigQuery ルーティンへの参照。API エンドポイントとは異なるリージョンでルーティンを使用するには(たとえば、usマルチリージョン API エンドポイントからus-east4リージョンのテーブルにアクセスする場合)、boundaryLocationIdフィールドでそのリージョンを指定します。description: 関数の動作の概要。エージェントが関数を回答に適したタイミングを判断するために使用します。
次の例は、直接 HTTP リクエストと Python SDK を使用してユーザー定義関数を指定する方法を示しています。
HTTP
直接 HTTP リクエストでは、bqRoutines リストを含む user_functions オブジェクトを指定します。リスト内の各オブジェクトには、routineReference プロパティと description フィールドが含まれている必要があります。
"user_functions": {
"bqRoutines": [
{
"routineReference": {
"projectId": "bigquery-public-data",
"datasetId": "thelook_ecommerce",
"routineId": "my_custom_function"
},
"description": "Calculates adjusted revenue by using custom logic."
}
]
}
Python SDK
Python SDK を使用する場合は、エージェントのコンテキストに追加された UserFunctions オブジェクトの bq_routines プロパティに BigQueryRoutine オブジェクトのリストを割り当てることで、これらのルーティンを定義できます。
# Define a BigQuery routine (UDF)
bq_routine = geminidataanalytics.BigQueryRoutine()
bq_routine.routine_reference.project_id = "bigquery-public-data"
bq_routine.routine_reference.dataset_id = "thelook_ecommerce"
bq_routine.routine_reference.routine_id = "my_custom_function"
bq_routine.description = "Calculates adjusted revenue by using custom logic."
# Add the routine to the agent's context
user_functions = geminidataanalytics.UserFunctions()
user_functions.bq_routines = [bq_routine]
# Assign to context
context.user_functions = user_functions
システム指示で追加のコンテキストを定義する
system_instruction パラメータを使用すると、構造化コンテキスト フィールドでサポートされていないコンテキストの補足ガイダンスを指定できます。この追加のガイダンスを提供することで、エージェントがデータとユースケースのコンテキストをより深く理解できるようになります。
システム指示は、データ エージェントにデータソースの詳細と、質問に回答する際のエージェントのロールに関するガイダンスを提供する一連の主要コンポーネントとオブジェクトで構成されます。system_instruction パラメータで、YAML 形式の文字列としてデータ エージェントへのシステム指示を指定できます。
次のテンプレートは、BigQuery データソースの system_instruction パラメータに指定できる文字列の推奨の YAML 構造を示しています。使用可能なキーと想定されるデータ型が含まれています。このテンプレートは、システム指示を定義するための重要なコンポーネントを含む推奨構造を提供しますが、考えられるすべてのシステム指示の形式が含まれているわけではありません。
- system_instruction: str # A description of the expected behavior of the agent. For example: You are a sales agent.
- tables: # A list of tables to describe for the agent.
- table: # Details about a single table that is relevant for the agent.
- name: str # The name of the table.
- fields: # Details about columns (fields) within the table.
- field: # Details about a single column within the current table.
- name: str # The name of the column.
- aggregations: list[str] # Commonly used or default aggregations for the column.
- relationships: # A list of join relationships between tables.
- relationship: # Details about a single join relationship.
- name: str # The name of this join relationship.
- description: str # A description of the relationship.
- relationship_type: str # The join relationship type: one-to-one, one-to-many, many-to-one, or many-to-many.
- join_type: str # The join type: inner, outer, left, right, or full.
- left_table: str # The name of the left table in the join.
- right_table: str # The name of the right table in the join.
- relationship_columns: # A list of columns that are used for the join.
- left_column: str # The join column from the left table.
- right_column: str # The join column from the right table.
- glossaries: # A list of definitions for glossary business terms, jargon, and abbreviations.
- glossary: # The definition for a single glossary item.
- term: str # The term, phrase, or abbreviation to define.
- description: str # A description or definition of the term.
- synonyms: list[str] # Alternative terms for the glossary entry.
- additional_descriptions: # A list of any other general instructions or content.
- text: str # Any additional general instructions or context not covered elsewhere.
以降のセクションでは、システム指示のキー コンポーネントの例を示します。
system_instruction
system_instruction キーを使用して、エージェントのロールとペルソナを定義します。この最初の指示は、API の回答のトーンとスタイルを設定し、エージェントがその主な目的を理解するのに役立ちます。
たとえば、次のように、架空の e コマースストアのセールス アナリストとしてエージェントを定義できます。
- system_instruction: You are an expert sales analyst for a fictitious
ecommerce store. You will answer questions about sales, orders, and customer
data. Your responses should be concise and data-driven.
tables
テーブルの基本プロパティ(説明や類義語など)は構造化コンテキストとして定義しますが、システム指示内の tables キーを使用して、補足的なビジネス ロジックを提供することもできます。BigQuery データソースの場合、これには fields キーを使用して特定の列のデフォルトの aggregations を定義することが含まれます。
次の YAML コードブロックの例は、システム指示内で tables キーを使用して、テーブル bigquery-public-data.thelook_ecommerce.orders の補足ガイダンスを提供するフィールドをネストする方法を示しています。
- tables:
- table:
- name: bigquery-public-data.thelook_ecommerce.orders
- fields:
- field:
- name: num_of_items
- aggregations: 'sum, avg'
relationships
システム指示の relationships キーには、テーブル間の結合関係のリストが含まれます。結合関係を定義することで、エージェントが回答する際に複数のテーブルのデータを結合する方法を理解できるようになります。
たとえば、bigquery-public-data.thelook_ecommerce.orders テーブルと bigquery-public-data.thelook_ecommerce.users テーブルの間に、orders_to_user のリレーションシップを次のように定義できます。
- relationships:
- relationship:
- name: orders_to_user
- description: >-
Connects customer order data to user information with the user_id and id fields to allow an aggregated view of sales by customer demographics.
- relationship_type: many-to-one
- join_type: left
- left_table: bigquery-public-data.thelook_ecommerce.orders
- right_table: bigquery-public-data.thelook_ecommerce.users
- relationship_columns:
- left_column: user_id
- right_column: id
glossaries
システム指示の glossaries キーには、データとユースケースに関連するビジネス用語、専門用語、略語の定義のリストが表示されます。用語集の定義を指定することで、エージェントが特定のビジネス用語を使用した質問を正確に解釈して回答できるようになります。エージェントが質問への回答に用語集の用語を使用する場合、回答でその用語を引用することがあります。
たとえば、特定のビジネス コンテキストに従って、一般的なビジネス ステータスや「OMPF」などの用語を次のように定義できます。
- glossaries:
- glossary:
- term: complete
- description: Represents an order status where the order has been completed.
- synonyms: 'finish, done, fulfilled'
- glossary:
- term: shipped
- description: Represents an order status where the order has been shipped to the customer.
- glossary:
- term: returned
- description: Represents an order status where the customer has returned the order.
- glossary:
- term: OMPF
- description: Order Management and Product Fulfillment
additional_descriptions
additional_descriptions キーを使用して、他の構造化されたコンテキストやシステム指示のフィールドに当てはまらない一般的な指示やコンテキストを指定します。システム指示に追加の説明を提供することで、エージェントがデータとユースケースのコンテキストをより深く理解できるようになります。
たとえば、additional_descriptions キーを使用して、組織に関する情報を次のように提供できます。
- additional_descriptions:
- text: All the sales data pertains to The Look, a fictitious ecommerce store.
- text: 'Orders can be of three categories: food, clothes, and electronics.'
例: 営業担当者向けの作成済みコンテキスト
架空のセールス アナリスト エージェントの次の例は、構造化コンテキストとシステム指示の組み合わせを使用して、作成されたコンテキストを提供する方法を示しています。
例: 構造化されたコンテキスト
次の HTTP と Python SDK の例に示すように、テーブル、列、クエリの例に関する詳細を含む構造化されたコンテキストを指定して、エージェントをガイドできます。
HTTP
次の例は、HTTP リクエストで構造化コンテキストを定義する方法を示しています。
{
"bq": {
"tableReferences": [
{
"projectId": "bigquery-public-data",
"datasetId": "thelook_ecommerce",
"tableId": "orders",
"schema": {
"description": "Data for orders in The Look, a fictitious ecommerce store.",
"synonyms": ["sales"],
"tags": ["sale", "order", "sales_order"],
"fields": [
{
"name": "status",
"description": "The current status of the order."
},
{
"name": "num_of_items",
"description": "The number of items in the order."
}
]
}
},
{
"projectId": "bigquery-public-data",
"datasetId": "thelook_ecommerce",
"tableId": "users",
"schema": {
"description": "Data for users in The Look, a fictitious ecommerce store.",
"synonyms": ["customers"],
"tags": ["user", "customer", "buyer"],
"fields": [
{
"name": "first_name",
"description": "The first name of the user.",
"tags": ["person"]
},
{
"name": "last_name",
"description": "The last name of the user.",
"tags": ["person"]
},
{
"name": "age_group",
"description": "The age demographic group of the user."
},
{
"name": "email",
"description": "The email address of the user.",
"tags": ["contact"]
}
]
}
}
]
},
"example_queries": [
{
"naturalLanguageQuestion": "How many orders are there?",
"sqlQuery": "SELECT COUNT(*) FROM `bigquery-public-data.thelook_ecommerce.orders`"
},
{
"naturalLanguageQuestion": "How many orders were shipped?",
"sqlQuery": "SELECT COUNT(*) FROM `bigquery-public-data.thelook_ecommerce.orders` WHERE status = 'shipped'"
},
{
"naturalLanguageQuestion": "How many unique customers are there?",
"sqlQuery": "SELECT COUNT(DISTINCT id) FROM `bigquery-public-data.thelook_ecommerce.users`"
},
{
"naturalLanguageQuestion": "How many users in the 25-34 age group have a cymbalgroup email address?",
"sqlQuery": "SELECT COUNT(DISTINCT id) FROM `bigquery-public-data.thelook_ecommerce.users` WHERE users.age_group = '25-34' AND users.email LIKE '%@cymbalgroup.com'"
}
]
}
Python SDK
次の例は、Python SDK で構造化コンテキストを定義する方法を示しています。
# Define context for the 'orders' table
bigquery_table_reference_1 = geminidataanalytics.BigQueryTableReference()
bigquery_table_reference_1.project_id = "bigquery-public-data"
bigquery_table_reference_1.dataset_id = "thelook_ecommerce"
bigquery_table_reference_1.table_id = "orders"
bigquery_table_reference_1.schema = geminidataanalytics.Schema()
bigquery_table_reference_1.schema.description = "Data for orders in The Look, a fictitious ecommerce store."
bigquery_table_reference_1.schema.synonyms = ["sales"]
bigquery_table_reference_1.schema.tags = ["sale", "order", "sales_order"]
bigquery_table_reference_1.schema.fields = [
geminidataanalytics.Field(
name="status",
description="The current status of the order.",
),
geminidataanalytics.Field(
name="num_of_items",
description="The number of items in the order."
)
]
# Define context for the 'users' table
bigquery_table_reference_2 = geminidataanalytics.BigQueryTableReference()
bigquery_table_reference_2.project_id = "bigquery-public-data"
bigquery_table_reference_2.dataset_id = "thelook_ecommerce"
bigquery_table_reference_2.table_id = "users"
bigquery_table_reference_2.schema = geminidataanalytics.Schema()
bigquery_table_reference_2.schema.description = "Data for users in The Look, a fictitious ecommerce store."
bigquery_table_reference_2.schema.synonyms = ["customers"]
bigquery_table_reference_2.schema.tags = ["user", "customer", "buyer"]
bigquery_table_reference_2.schema.fields = [
geminidataanalytics.Field(
name="first_name",
description="The first name of the user.",
tags=["person"],
),
geminidataanalytics.Field(
name="last_name",
description="The last name of the user.",
tags=["person"],
),
geminidataanalytics.Field(
name="age_group",
description="The age demographic group of the user.",
),
geminidataanalytics.Field(
name="email",
description="The email address of the user.",
tags=["contact"],
)
]
# Define example queries
example_queries = [
geminidataanalytics.ExampleQuery(
natural_language_question="How many orders are there?",
sql_query="SELECT COUNT(*) FROM `bigquery-public-data.thelook_ecommerce.orders`",
),
geminidataanalytics.ExampleQuery(
natural_language_question="How many orders were shipped?",
sql_query="SELECT COUNT(*) FROM `bigquery-public-data.thelook_ecommerce.orders` WHERE status = 'shipped'",
),
geminidataanalytics.ExampleQuery(
natural_language_question="How many unique customers are there?",
sql_query="SELECT COUNT(DISTINCT id) FROM `bigquery-public-data.thelook_ecommerce.users`",
),
geminidataanalytics.ExampleQuery(
natural_language_question="How many users in the 25-34 age group have a cymbalgroup email address?",
sql_query="SELECT COUNT(DISTINCT id) FROM `bigquery-public-data.thelook_ecommerce.users` WHERE users.age_group = '25-34' AND users.email LIKE '%@cymbalgroup.com'",
)
]
例: システム指示
次のシステム指示は、エージェントのペルソナを定義し、構造化フィールドでサポートされていないガイダンス(関係の定義、用語集の用語、追加の説明、補足の orders テーブルの詳細など)を提供することで、構造化されたコンテキストを補完します。この例では、users テーブルは構造化されたコンテキストで完全に定義されているため、システム指示で再定義する必要はありません。
- system_instruction: >-
You are an expert sales analyst for a fictitious ecommerce store. You will answer questions about sales, orders, and customer data. Your responses should be concise and data-driven.
- tables:
- table:
- name: bigquery-public-data.thelook_ecommerce.orders
- fields:
- field:
- name: num_of_items
- aggregations: 'sum, avg'
- relationships:
- relationship:
- name: orders_to_user
- description: >-
Connects customer order data to user information with the user_id and id fields.
- relationship_type: many-to-one
- join_type: left
- left_table: bigquery-public-data.thelook_ecommerce.orders
- right_table: bigquery-public-data.thelook_ecommerce.users
- relationship_columns:
- left_column: user_id
- right_column: id
- glossaries:
- glossary:
- term: complete
- description: Represents an order status where the order has been completed.
- synonyms: 'finish, done, fulfilled'
- glossary:
- term: OMPF
- description: Order Management and Product Fulfillment
- additional_descriptions:
- text: All the sales data pertains to The Look, a fictitious ecommerce store.