bigframes.bigquery.ai.if_#

bigframes.bigquery.ai.if_(prompt: str | Series | Series | List[str | Series | Series] | Tuple[str | Series | Series, ...], *, connection_id: str | None = None, endpoint: str | None = None, optimization_mode: Literal['minimize_cost', 'maximize_quality'] | None = None, max_error_ratio: float | None = None) Series[source]#

Evaluates the prompt to True or False. Compared to ai.generate_bool(), this function provides optimization such that not all rows are evaluated with the LLM.

Examples:

>>> import bigframes.pandas as bpd
>>> import bigframes.bigquery as bbq
>>> us_state = bpd.Series(["Massachusetts", "Illinois", "Hawaii"])
>>> bbq.ai.if_((us_state, " has a city called Springfield"))
0     True
1     True
2    False
dtype: boolean
>>> us_state[bbq.ai.if_((us_state, " has a city called Springfield"))]
0    Massachusetts
1         Illinois
dtype: string
Parameters:
  • prompt (str | Series | List[str|Series] | Tuple[str|Series, ...]) – A mixture of Series and string literals that specifies the prompt to send to the model. The Series can be BigFrames Series or pandas Series.

  • connection_id (str, optional) – Specifies the connection to use to communicate with the model. For example, myproject.us.myconnection. If not provided, the query uses your end-user credential.

  • endpoint (str, optional) – Specifies the Vertex AI endpoint to use for the model. For example "gemini-2.5-flash". You can specify any generally available or preview Gemini model. If you specify the model name, BigQuery ML automatically identifies and uses the full endpoint of the model. If you don’t specify an ENDPOINT value, BigQuery ML dynamically chooses a model based on your query to have the best cost to quality tradeoff for the task.

  • optimization_mode (Literal["minimize_cost", "maximize_quality"]) – Specifies the optimization strategy to use. Supported values are: * “minimize_cost” (default): uses a local, distilled model to process the majority of rows, reducing latency and cost. * “maximize_quality”: always uses the remote LLM for inference.

  • max_error_ratio (float) – A float value between 0.0 and 1.0 that contains the maximum acceptable ratio of row-level inference failures to rows processed on this function. If this value is exceeded, then the query fails. The default value is 1.0. This argument isn’t supported when optimization_mode is set to “minimize_cost”.

Returns:

A new series of bools.

Return type:

bigframes.series.Series