Definisci il contesto dell'agente di dati per le origini dati BigQuery

In questa pagina viene descritto come fornire un contesto creato per gli agenti per i dati che utilizzano origini dati BigQuery.

Il contesto creato è una guida che i Data Agent Owner possono fornire per modellare il comportamento di un agente per i dati e perfezionare le risposte dell'API. Un contesto creato in modo efficace fornisce agli agenti per i dati dell'API Analisi conversazionale un contesto utile per rispondere alle domande sulle origini dati.

Sebbene il contesto creato sia facoltativo, fornire un contesto solido consente all'agente di fornire risposte più accurate e pertinenti. L'agente per i dati incorpora questo contesto durante la creazione e il runtime per garantire che le sue azioni, query e risposte siano accurate, conformi e consapevoli dell'attività. Questo contesto viene importato, indicizzato e utilizzato per definire il comportamento dell'agente.

Opzioni per fornire il contesto creato

Per le origini dati BigQuery, puoi fornire un contesto creato tramite una combinazione di contesto strutturato e istruzioni di sistema. Se possibile, fornisci il contesto tramite campi di contesto strutturati. Poi, utilizza il parametro system_instruction per indicazioni supplementari non coperte dai campi strutturati, ad esempio per definire il tono o il comportamento generale di un agente.

Dopo aver definito i campi strutturati e le istruzioni di sistema che compongono il contesto creato, puoi fornirlo all'API in una delle seguenti chiamate:

Definisci i campi di contesto strutturati

Questa sezione descrive come fornire contesto a un agente per i dati utilizzando i campi di contesto strutturati. Puoi fornire le seguenti informazioni a un agente come contesto strutturato:

Contesto strutturato a livello di tabella

Utilizza la chiave tableReferences per fornire a un agente i dettagli sulle tabelle specifiche disponibili per rispondere alle domande. Per ogni riferimento alla tabella, puoi utilizzare i seguenti campi di contesto strutturato per definire lo schema di una tabella:

  • description: un riepilogo dei contenuti e dello scopo della tabella
  • synonyms: un elenco di termini alternativi che possono essere utilizzati per fare riferimento alla tabella
  • tags: un elenco di parole chiave o tag associati alla tabella

I seguenti esempi mostrano come fornire queste proprietà come contesto strutturato all'interno di richieste HTTP dirette e con l'SDK Python.

HTTP

In una richiesta HTTP diretta, fornisci queste proprietà a livello di tabella all'interno dell'oggetto schema per il riferimento alla tabella pertinente. Per un esempio completo di come strutturare il payload della richiesta completa, consulta Connettiti ai dati di 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"]
    }
  }
]

SDK Python

Quando utilizzi l'SDK Python, puoi definire queste proprietà a livello di tabella nella proprietà schema di un oggetto BigQueryTableReference. L'esempio seguente mostra come creare oggetti di riferimento della tabella che forniscono il contesto per le tabelle orders e users. Per un esempio completo di come creare e utilizzare gli oggetti di riferimento della tabella, consulta Connettiti ai dati di 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"]

Contesto strutturato a livello di colonna

La chiave fields, nidificata all'interno dell'oggetto schema di un riferimento alla tabella, accetta un elenco di oggetti field per descrivere le singole colonne. Non tutti i campi richiedono un contesto aggiuntivo, ma per i campi di uso comune l'inclusione di dettagli aggiuntivi può contribuire a migliorare le prestazioni dell'agente.

Per ogni oggetto field, puoi utilizzare i seguenti campi di contesto strutturato per definire le proprietà fondamentali di una colonna:

  • description: una breve descrizione dei contenuti e dello scopo della colonna
  • synonyms: un elenco di termini alternativi che possono essere utilizzati per fare riferimento alla colonna
  • tags: un elenco di parole chiave o tag associati alla colonna

Gli esempi seguenti mostrano come fornire queste proprietà come contesto strutturato per il campo status all'interno della tabella orders e per il campo first_name all'interno della tabella users con richieste HTTP dirette e con l'SDK Python.

HTTP

In una richiesta HTTP diretta, puoi definire queste proprietà a livello di colonna fornendo un elenco di oggetti fields all'interno dell'oggetto schema di un riferimento alla tabella.

"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",
      }]
    }
  }
]

SDK Python

Quando utilizzi l'SDK Python, puoi definire queste proprietà a livello di colonna assegnando un elenco di oggetti Field alla proprietà fields della proprietà schema di una tabella.

# 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"],
    )
]

Esempi di query

La chiave example_queries accetta un elenco di oggetti example_query che definiscono query in linguaggio naturale per aiutare l'agente a fornire risposte più accurate e pertinenti. Fornendo all'agente sia una domanda in linguaggio naturale sia la query SQL corrispondente, puoi guidarlo a fornire risultati di qualità superiore e più coerenti.

Se la domanda di un utente corrisponde semanticamente a una query di esempio definita, l'agente potrebbe eseguire direttamente la query anziché generarne una nuova. Quando un agente esegue una query esistente, la risposta dell'API include un oggetto matched_query per indicare che è stata utilizzata una query verificata. L'agente potrebbe anche citare la query nella sua risposta.

Esempi di query con parametri

Oltre alle query statiche, puoi definire query di esempio parametrizzate che consentono all'agente di sostituire i valori dinamici in un modello di query verificato. Includendo i parametri nelle query di esempio, puoi creare modelli flessibili che coprono una gamma più ampia di richieste degli utenti rispetto agli esempi statici. Quando la domanda di un utente corrisponde a un template, l'agente esegue la query corrispondente per fornire una risposta verificata.

Puoi definire una query con parametri nel seguente modo:

  1. Nel campo naturalLanguageQuestion, utilizza le parentesi graffe per i segnaposto, ad esempio {state}.
  2. Nel campo sqlQuery, utilizza la sintassi dei parametri denominati di BigQuery per la stessa variabile, ad esempio @state.
  3. Nel campo parameters, definisci il nome, il tipo di dati e la descrizione di ogni parametro.

Esempi

Gli esempi seguenti mostrano come definire query di esempio statiche e parametrizzate per il set di dati degli aeroporti della FAA.

HTTP

In una richiesta HTTP diretta, fornisci un elenco di oggetti example_query nel campo example_queries. Per ogni oggetto, fornisci la chiave naturalLanguageQuestion (la domanda che un utente potrebbe porre) e la chiave sqlQuery corrispondente. Per le query parametrizzate, devi anche fornire un elenco parameters che includa il nome, il tipo di dati e la descrizione di ogni parametro.

"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.",
      }
    ]
  }
]

SDK Python

Quando utilizzi l'SDK Python, fornisci un elenco di oggetti ExampleQuery. Per ogni oggetto, fornisci i valori per il parametro natural_language_question (la domanda che un utente potrebbe porre) e i parametri sql_query. Per le query parametrizzate, devi anche fornire un elenco di oggetti 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.",
            ),
        ],
    )
]

Funzioni definite dall'utente

Puoi fornire funzioni definite dall'utente (UDF) per BigQuery nel contesto dell'agente utilizzando il campo user_functions. Quando fornisci routine BigQuery personalizzate, l'agente può utilizzarle se sono necessarie per rispondere a una domanda.

Per ogni UDF, puoi fornire le seguenti proprietà:

  • routineReference: un riferimento alla routine BigQuery che include l'ID progetto, l'ID set di dati e l'ID routine. Per utilizzare una routine in una regione diversa da quella dell'endpoint API (ad esempio, se accedi a una tabella nella regione us-east4 dall'endpoint API multiregionale us), specifica la regione nel campo boundaryLocationId.
  • description: un riepilogo del comportamento della funzione utilizzato dall'agente per determinare quando la funzione è appropriata per una risposta.

I seguenti esempi mostrano come fornire funzioni definite dall'utente con richieste HTTP dirette e con l'SDK Python.

HTTP

In una richiesta HTTP diretta, fornisci un oggetto user_functions che contiene un elenco bqRoutines. Ogni oggetto nell'elenco deve contenere una proprietà routineReference e un campo description.

"user_functions": {
  "bqRoutines": [
    {
      "routineReference": {
        "projectId": "bigquery-public-data",
        "datasetId": "thelook_ecommerce",
        "routineId": "my_custom_function"
      },
      "description": "Calculates adjusted revenue by using custom logic."
    }
  ]
}

SDK Python

Quando utilizzi l'SDK Python, puoi definire queste routine assegnando un elenco di oggetti BigQueryRoutine alla proprietà bq_routines di un oggetto UserFunctions aggiunto al contesto dell'agente.

# 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

Definisci un contesto aggiuntivo nelle istruzioni di sistema

Puoi utilizzare il parametro system_instruction per fornire indicazioni aggiuntive per il contesto non supportato dai campi di contesto strutturati. Fornendo queste indicazioni aggiuntive, puoi aiutare l'agente a comprendere meglio il contesto dei tuoi dati e del tuo caso d'uso.

Le istruzioni di sistema sono costituite da una serie di componenti e oggetti chiave che forniscono all'agente per i dati dettagli sull'origine dati e indicazioni sul ruolo dell'agente quando risponde alle domande. Puoi fornire istruzioni di sistema all'agente per i dati nel parametro system_instruction come stringa in formato YAML.

Il seguente modello mostra una struttura YAML suggerita per la stringa, che puoi fornire al parametro system_instruction per un'origine dati BigQuery, incluse le chiavi disponibili e i tipi di dati previsti. Sebbene questo template fornisca una struttura suggerita con componenti importanti per la definizione delle istruzioni di sistema, non include tutti i possibili formati delle istruzioni di sistema.

- 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.

Le sezioni seguenti contengono esempi di componenti chiave delle istruzioni di sistema:

system_instruction

Utilizza la chiave system_instruction per definire il ruolo e la persona dell'agente. Questo set di istruzioni iniziale definisce il tono e lo stile delle risposte dell'API e aiuta l'agente a comprendere il suo scopo principale.

Ad esempio, puoi definire un agente come analista delle vendite per un negozio di e-commerce fittizio nel seguente modo:

-   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

Sebbene tu definisca le proprietà fondamentali di una tabella (come la descrizione e i sinonimi) come contesto strutturato, puoi anche utilizzare la chiave tables all'interno delle istruzioni di sistema per fornire una logica di business supplementare. Per le origini dati BigQuery, ciò include l'utilizzo della chiave fields per definire i aggregations predefiniti per colonne specifiche.

Il seguente blocco di codice YAML di esempio mostra come utilizzare la chiave tables all'interno delle istruzioni di sistema per nidificare i campi che forniscono indicazioni supplementari per la tabella 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

La chiave relationships nelle istruzioni di sistema contiene un elenco di relazioni di join tra le tabelle. Definendo le relazioni di join, puoi aiutare l'agente a capire come unire i dati di più tabelle quando risponde alle domande.

Ad esempio, puoi definire una relazione orders_to_user tra la tabella bigquery-public-data.thelook_ecommerce.orders e la tabella bigquery-public-data.thelook_ecommerce.users come segue:

-   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

La chiave glossaries nelle istruzioni di sistema elenca le definizioni di termini aziendali, gergo e abbreviazioni pertinenti ai tuoi dati e al tuo caso d'uso. Fornendo le definizioni del glossario, puoi aiutare l'agente a interpretare e rispondere con precisione alle domande che utilizzano un linguaggio aziendale specifico. Se un agente utilizza un termine del glossario per rispondere a una domanda, potrebbe citarlo nella risposta.

Ad esempio, puoi definire termini come stati aziendali comuni e "OMPF" in base al contesto aziendale specifico, come segue:

- 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

Utilizza la chiave additional_descriptions per fornire istruzioni generali o un contesto che non rientra in altri campi di contesto strutturato o di istruzioni di sistema. Fornendo descrizioni aggiuntive nelle istruzioni di sistema, puoi aiutare l'agente a comprendere meglio il contesto dei tuoi dati e del tuo caso d'uso.

Ad esempio, puoi utilizzare la chiave additional_descriptions per fornire informazioni sulla tua organizzazione come segue:

-   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.'

Esempio: contesto creato per un agente di vendita

L'esempio seguente di un agente di analisi delle vendite fittizio mostra come fornire un contesto creato utilizzando una combinazione di contesto strutturato e istruzioni di sistema.

Esempio: contesto strutturato

Puoi fornire un contesto strutturato con dettagli su tabelle, colonne e query di esempio per guidare l'agente, come mostrato nei seguenti esempi di SDK HTTP e Python.

HTTP

L'esempio seguente mostra come definire il contesto strutturato in una richiesta 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'"
    }
  ]
}

SDK Python

L'esempio seguente mostra come definire il contesto strutturato con l'SDK Python:

# 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'",
  )
]

Esempio: istruzioni di sistema

Le seguenti istruzioni di sistema integrano il contesto strutturato definendo la persona dell'agente e fornendo indicazioni non supportate dai campi strutturati, come definizioni delle relazioni, termini del glossario, descrizioni aggiuntive e dettagli supplementari della tabella orders. In questo esempio, poiché la tabella users è completamente definita con un contesto strutturato, non è necessario ridefinirla nelle istruzioni di sistema.

-   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.