Troubleshoot optimized functions

This document describes errors you might encounter when you use optimized AI functions. Examples of errors and recommended fixes are also provided.

Reduced performance expected. Optimized AI function is not available

Description

This warning indicates that the query fell back to using the LLM. This occurs when the optimized function is still training, was never prepared, failed the runtime accuracy validation check, or if the content and embedding columns referenced in the ai.if() function don't belong to the same table. For smaller tables, the proxy model might not generalize well, and accuracy is generally less than 95%, so AlloyDB uses the LLM by default.

Sample query that causes the error

EXECUTE positive_reviews_query;
  • Wait for the optimized function training to complete.
  • Make sure that the query is correctly prepared using the PREPARE statement.
  • Verify that the content and embedding columns referenced in the ai.if() function belong to the same table.
  • Optimized functions (Preview) are better suited for larger tables. You can also use array-based AI functions to improve performance.
  • If you want to bypass the runtime accuracy check (for example, in development environments), set google_ml_integration.runtime_accuracy_check to off for the entire database environment.

    ALTER DATABASE DATABASE_NAME SET google_ml_integration.runtime_accuracy_check = off;
    

    Replace DATABASE_NAME with the name of your database.

Query is not processing any rows or model preparation is failing

Description

If the query isn't processing any rows, the primary reason is that the embeddings aren't generated or when the entire embedding column has NULL values. This causes the query preparation to fail, because it doesn't sample any rows that have NULL embeddings.

  • Generate embeddings for your data before you use optimized functions.
  • Make sure that the embedding column doesn't contain NULL values.
  • Queries that differ only in constant values in the WHERE clause might still use an existing trained model.

Slow performance despite using optimized AI functions

Description

Ensure that you aren't exceeding your Vertex AI quota. Even with optimized AI functions, the initial runtime accuracy check requires calling the remote LLM for a sample of rows. An insufficient quota can cause this initial check to be slow or to fail.

Check your Vertex AI quota and request an increase if necessary to ensure that the initial runtime accuracy check can proceed without delays.

ERROR: function ai.if(prompt => text, embedding => vector) does not exist

Description

If you pass the model_id parameter along with the embedding column when calling the ai.if() function, AlloyDB doesn't use the trained proxy model, and generates an error similar to the following:

testdb=# select ai.if('Is the rating positive?' || review, review_embedding, 'gemini-2.5-pro') from restaurant_reviews;
ERROR:  function ai.if(text, vector, unknown) does not exist
LINE 1: select ai.if('Is the rating positive?' || review, review_embe...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Ensure that you aren't passing the model_id value when you call the ai.if() function. This ensures that AlloyDB uses the trained proxy model to process the query.