
BigQuery AI Functions in Pandas via the .bigquery Accessor

BigQuery DataFrames adds a .bigquery accessor that exposes BigQuery AI functions inside the pandas API. Developers can call methods such as ai.predict(), ai.embed(), ai.forecast(), and ai.if_() on ordinary pandas Series and DataFrame objects, and receive ordinary pandas objects back while the actual computation runs in BigQuery. The post demonstrates this with a regression workflow: instead of pulling data locally, selecting features, and training a scikit-learn model, ai.predict() performs regression over two pandas DataFrames in a single call.
Under the hood, BigFrames translates the pandas operation into Google Standard SQL, executes the relevant foundation model on BigQuery, and formats the result as native pandas objects. To use the accessor, set up a Google Cloud project with BigQuery Job User and Agent Platform User roles, install pandas and bigframes in Jupyter, import bigframes, and provide the project ID.
On Series, ai.embed() computes vector embeddings for an entire text column and returns a native pandas Series of embedding lists; BigFrames handles temporary BigQuery conversions, model execution, and final formatting. ai.similarity() computes cosine similarity between each series element and either a scalar string or another Series, returning floating-point Series ready for downstream filtering and sorting.
On DataFrames, ai.forecast() runs grouped time-series forecasting after you specify the target metric, timestamp column, grouping key, and forecast horizon; the returned DataFrame includes forecast values, confidence levels, and prediction intervals. It uses TimesFM, and passing the model argument set to TimesFM 3.0 selects the newest version, currently in Preview in BigQuery and ranked #1 on GIFT-Eval, FEV-Bench, and TIME forecasting benchmarks. ai.if_() evaluates natural-language prompts built from literal strings and DataFrame columns, returning a boolean Series that can be used directly as a filter mask, for example df[df.bigquery.ai.if_(prompt)]. By default it runs in optimized mode, minimization of cost, where a local distilled model handles most rows and only the rest go to Gemini; setting the optimization mode to maximize quality sends every row to the LLM.
The post also lists currently supported functions. On Series: embed(), generate_embedding(), generate_table(), generate_text(), and similarity(). On DataFrames: classify(), forecast(), generate(), generate_bool(), generate_double(), generate_int(), if_(), predict(), and score(). predict() uses TabFM, and full details are in the official documentation.


