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:
Generative AI: Use
bigframes.bigquery.ai.generate()(Gemini) to perform text analysis, translation, or content generation. Specialized versions likegenerate_bool(),generate_int(), andgenerate_double()are available for structured outputs.Embeddings: Generate vector embeddings for text using
generate_embedding(), which are essential for semantic search and retrieval-augmented generation (RAG) workflows.Classification and Scoring: Apply machine learning models to your data for predictive tasks with
classify()andscore().Forecasting: Predict future values in time-series data using
forecast().
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