AI Functions on Databricks


This feature is in Public Preview.

This article describes Databricks AI Functions, built-in SQL functions that allow you to access and serve large language models (LLMs) directly from SQL.


The ai_query() function allows you to serve your machine learning models and large language models using Databricks Model Serving and query them using SQL. To do so, this function invokes an existing Databricks Model Serving endpoint and parses and returns its response. You can use ai_query() to query endpoints that serve custom models, foundation models made available using Foundation Model APIs, and external models.



The AI function, ai_generate_text() is deprecated. Databricks recommends using ai_query with external models.

The ai_generate_text() function calls an LLM selected by the user with the given prompt and returns the text generated by the model. Returns text generated by a selected large language model (LLM) given the prompt. Users can set additional parameters to control the behavior. Currently Databricks supports calling ChatGPT from OpenAI and Azure OpenAI Service.