bigframes.bigquery.ai#

Integrate BigQuery built-in AI functions into your BigQuery DataFrames workflow.

The bigframes.bigquery.ai module provides a Pythonic interface to leverage BigQuery ML’s generative AI and predictive functions directly on BigQuery DataFrames and Series objects. These functions enable you to perform advanced AI tasks at scale without moving data out of BigQuery.

Key capabilities include:

Example usage:

>>> import bigframes.pandas as bpd
>>> import bigframes.bigquery as bbq
>>> df = bpd.DataFrame({
...     "text_input": [
...         "Is this a positive review? The food was terrible.",
...     ],
... })
>>> # Assuming a Gemini model has been created in BigQuery as 'my_gemini_model'
>>> result = bq.ai.generate_text("my_gemini_model", df["text_input"])

For more information on the underlying BigQuery ML syntax, see: https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-generate-bool

Functions

classify(input, categories, *[, connection_id])

Classifies a given input into one of the specified categories.

forecast(df, *, data_col, timestamp_col[, ...])

Forecast time series at future horizon.

generate(prompt, *[, connection_id, ...])

Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data.

generate_bool(prompt, *[, connection_id, ...])

Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data.

generate_double(prompt, *[, connection_id, ...])

Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data.

generate_embedding(model, data, *[, ...])

Creates embeddings that describe an entity—for example, a piece of text or an image.

generate_int(prompt, *[, connection_id, ...])

Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data.

generate_table(model, data, *, output_schema)

Generates a table using a BigQuery ML model.

generate_text(model, data, *[, temperature, ...])

Generates text using a BigQuery ML model.

if_(prompt, *[, connection_id])

Evaluates the prompt to True or False.

score(prompt, *[, connection_id])

Computes a score based on rubrics described in natural language.