cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

ai_query issue

smpa01
New Contributor III

As per  the doc , one can execute an ai_query in python. But I am sot sure why I can't

Works in SQL

select 1 as colA, ai_query('databricks-llama-4-maverick', 'what is 2+2') as test

But not in spark

df = spark.sql("select 1 as colA")
df = df.selectExpr("""
ai_query('databricks-llama-4-maverick', 'what is 2+2') as result
                   """)

df.show()

I am getting

AnalysisException: [UNRESOLVED_ROUTINE] Cannot resolve function `ai_query` on search path [`system`.`builtin`, `system`.`session`, `catalog`.`default`].; line 1 pos 0

 

I have also converted the ai_query to a sql udf but even then it does not work.

1 ACCEPTED SOLUTION

Accepted Solutions

Vinay_M_R
Databricks Employee
Databricks Employee

Hello @smpa01,

I tried to reproduce this issue internally and it worked for me as expected in spark as well. I am sharing below screenshot for your reference:

Screenshot 2025-06-25 at 5.55.24โ€ฏPM.png

I used DBR 15.4 LTS and serverless it worked on both

View solution in original post

1 REPLY 1

Vinay_M_R
Databricks Employee
Databricks Employee

Hello @smpa01,

I tried to reproduce this issue internally and it worked for me as expected in spark as well. I am sharing below screenshot for your reference:

Screenshot 2025-06-25 at 5.55.24โ€ฏPM.png

I used DBR 15.4 LTS and serverless it worked on both

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now