<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ai-query Execution in Generative AI</title>
    <link>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177631#M2310</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/193958"&gt;@IM_01&lt;/a&gt;&amp;nbsp;,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Short answer:&lt;/STRONG&gt; yes, ai_query works in parallel, but partitions aren't really the lever. Parallelism happens at two levels, and Databricks manages the important one for you.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1. Spark side (your DataFrame)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ai_query&lt;/STRONG&gt; is evaluated like any other Spark SQL expression, so rows are processed by Spark tasks, and partitions are processed in parallel across the cluster's cores. In most cases Spark sizes the partitions adaptively, so you don't need to tune anything.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2. Model-serving side (where the optimised batch inference happens)&lt;/STRONG&gt;&lt;BR /&gt;This is usually the real bottleneck, and AI Functions "automatically handle paralleliation, retries, and scaling" for it. With a batch-optimised Databricks-hosted model, the batch backend scales capacity up for your query automatically. You don't provision or configure endpoint compute.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Should I repartition?&lt;/STRONG&gt;&lt;BR /&gt;Usually no. The docs advise submitting your full dataset in a single query and warn that "manually splitting data into small batches can reduce throughput." The exception is input that is clearly under-partitioned, such as a small CSV read into one or two partitions on classic compute with idle cores. There, a modest repartition(n) with n roughly equal to the available cores can help. Benchmark it: too many partitions gives diminishing returns, and repartitioning doesn't change cost.&lt;/P&gt;
&lt;P&gt;How to get the optimised batch path:First, make sure:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Run on DBR 15.4 LTS+ (18.2+ recommended, and note the announced move to 17.3 LTS as the minimum). Not available on Classic SQL warehouses.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Then follow the steps that were mentioned in the previous comments:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use a &lt;STRONG&gt;system.ai (Databricks-hosted) model&lt;/STRONG&gt; from the batch-optimised list, not a provisioned-throughput or custom endpoint.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;Send the whole dataset in one query&lt;BR /&gt;&lt;LI-CODE lang="python"&gt;CREATE OR REPLACE TABLE results AS
SELECT id, ai_query('databricks-…', prompt, failOnError =&amp;gt; false) AS ai
FROM source;​&lt;/LI-CODE&gt;&lt;STRONG&gt;Use one ai_query session per model&lt;/STRONG&gt; rather than several running side by side. Persist the results to a table instead of re-running inference in later queries.&lt;/LI&gt;
&lt;LI&gt;Set&lt;EM&gt;&lt;STRONG&gt; failOnError =&amp;gt; false&lt;/STRONG&gt;&lt;/EM&gt; for large workloads. You get a &lt;STRONG&gt;STRUCT&lt;/STRONG&gt; with response and errorMessage, so failed rows don't fail the job.&lt;/LI&gt;
&lt;LI&gt;Monitor progress in the query profile.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Docs:&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://docs.databricks.com/aws/en/large-language-models/ai-query" target="_self"&gt;https://docs.databricks.com/aws/en/large-language-models/ai-query&lt;/A&gt; and&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://docs.databricks.com/aws/en/large-language-models/ai-functions" target="_self"&gt;https://docs.databricks.com/aws/en/large-language-models/ai-functions&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Good luck&lt;/P&gt;</description>
    <pubDate>Wed, 25 Nov 2026 17:43:42 GMT</pubDate>
    <dc:creator>Valeria_Koz_DBX</dc:creator>
    <dc:date>2026-11-25T17:43:42Z</dc:date>
    <item>
      <title>ai-query Execution</title>
      <link>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177469#M2293</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I see that ai-query supports parallelization. Is it executed in parallel across each partition of the dataframe.&lt;BR /&gt;could any one explain how it supports optimized batch inference&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2026 17:30:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177469#M2293</guid>
      <dc:creator>IM_01</dc:creator>
      <dc:date>2026-11-24T17:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: ai-query Execution</title>
      <link>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177489#M2295</link>
      <description>&lt;PRE&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/193958"&gt;@IM_01&lt;/a&gt;,

ai_query is built for batch inference, but the docs do not say that it runs one call per DataFrame partition, and they do not describe the internal batching. They say the platform manages it. The AI Functions page says: "AI Functions automatically manage parallelization, retries, and scaling. It is advised to submit your full dataset in a single query rather than manually splitting it into small batches."

The same page says "your query runs on the compute you submit it from, such as a SQL warehouse, notebook, cluster, or pipeline", and that "the model inference may run on separate Databricks-managed infrastructure". So the docs do not link the number of partitions to the number of parallel model calls, and I would not tune partitions for this.

For optimised batch inference, the best practices on the "Use ai_query" page are:
1) Use Databricks-hosted system.ai model services, not provisioned throughput endpoints.
2) Pick a model from the batch-optimised list on that page. A non-optimised model "can result in reduced throughput and longer job completion times."
3) Submit your full dataset in a single query. "Manually splitting data into small batches can reduce throughput."
4) Set failOnError to false for large workloads, so failed rows return an error message and you keep the successful results.
&lt;BR /&gt;[&lt;A href="https://docs.databricks.com/aws/en/large-language-models/ai-query]" target="_blank" rel="noopener"&gt;https://docs.databricks.com/aws/en/large-language-models/ai-query]&lt;/A&gt;&lt;BR /&gt;
To see what happened in a run, open the query profile in the SQL editor and click AI Query. It shows the completed and failed inferences and the total time.&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Nov 2026 02:33:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177489#M2295</guid>
      <dc:creator>sundar-sg</dc:creator>
      <dc:date>2026-11-25T02:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: ai-query Execution</title>
      <link>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177490#M2296</link>
      <description>&lt;PRE&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/193958"&gt;@IM_01&lt;/a&gt;,

ai_query is built for batch inference, but the docs do not say that it runs one call per DataFrame partition, and they do not describe the internal batching. They say the platform manages it. The AI Functions page says: "AI Functions automatically manage parallelization, retries, and scaling. It is advised to submit your full dataset in a single query rather than manually splitting it into small batches."

The same page says "your query runs on the compute you submit it from, such as a SQL warehouse, notebook, cluster, or pipeline", and that "the model inference may run on separate Databricks-managed infrastructure". So the docs do not link the number of partitions to the number of parallel model calls, and I would not tune partitions for this.

For optimised batch inference, the best practices on the "Use ai_query" page are:
1) Use Databricks-hosted system.ai model services, not provisioned throughput endpoints.
2) Pick a model from the batch-optimised list on that page. A non-optimised model "can result in reduced throughput and longer job completion times."
3) Submit your full dataset in a single query. "Manually splitting data into small batches can reduce throughput."
4) Set failOnError to false for large workloads, so failed rows return an error message and you keep the successful results.
&lt;BR /&gt;[&lt;A href="https://docs.databricks.com/aws/en/large-language-models/ai-query]" rel="noopener" target="_blank"&gt;https://docs.databricks.com/aws/en/large-language-models/ai-query]&lt;/A&gt;&lt;BR /&gt;
To see what happened in a run, open the query profile in the SQL editor and click AI Query. It shows the completed and failed inferences and the total time.&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Nov 2026 02:35:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177490#M2296</guid>
      <dc:creator>Yougasundar</dc:creator>
      <dc:date>2026-11-25T02:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: ai-query Execution</title>
      <link>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177631#M2310</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/193958"&gt;@IM_01&lt;/a&gt;&amp;nbsp;,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Short answer:&lt;/STRONG&gt; yes, ai_query works in parallel, but partitions aren't really the lever. Parallelism happens at two levels, and Databricks manages the important one for you.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1. Spark side (your DataFrame)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ai_query&lt;/STRONG&gt; is evaluated like any other Spark SQL expression, so rows are processed by Spark tasks, and partitions are processed in parallel across the cluster's cores. In most cases Spark sizes the partitions adaptively, so you don't need to tune anything.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2. Model-serving side (where the optimised batch inference happens)&lt;/STRONG&gt;&lt;BR /&gt;This is usually the real bottleneck, and AI Functions "automatically handle paralleliation, retries, and scaling" for it. With a batch-optimised Databricks-hosted model, the batch backend scales capacity up for your query automatically. You don't provision or configure endpoint compute.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Should I repartition?&lt;/STRONG&gt;&lt;BR /&gt;Usually no. The docs advise submitting your full dataset in a single query and warn that "manually splitting data into small batches can reduce throughput." The exception is input that is clearly under-partitioned, such as a small CSV read into one or two partitions on classic compute with idle cores. There, a modest repartition(n) with n roughly equal to the available cores can help. Benchmark it: too many partitions gives diminishing returns, and repartitioning doesn't change cost.&lt;/P&gt;
&lt;P&gt;How to get the optimised batch path:First, make sure:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Run on DBR 15.4 LTS+ (18.2+ recommended, and note the announced move to 17.3 LTS as the minimum). Not available on Classic SQL warehouses.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Then follow the steps that were mentioned in the previous comments:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use a &lt;STRONG&gt;system.ai (Databricks-hosted) model&lt;/STRONG&gt; from the batch-optimised list, not a provisioned-throughput or custom endpoint.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;Send the whole dataset in one query&lt;BR /&gt;&lt;LI-CODE lang="python"&gt;CREATE OR REPLACE TABLE results AS
SELECT id, ai_query('databricks-…', prompt, failOnError =&amp;gt; false) AS ai
FROM source;​&lt;/LI-CODE&gt;&lt;STRONG&gt;Use one ai_query session per model&lt;/STRONG&gt; rather than several running side by side. Persist the results to a table instead of re-running inference in later queries.&lt;/LI&gt;
&lt;LI&gt;Set&lt;EM&gt;&lt;STRONG&gt; failOnError =&amp;gt; false&lt;/STRONG&gt;&lt;/EM&gt; for large workloads. You get a &lt;STRONG&gt;STRUCT&lt;/STRONG&gt; with response and errorMessage, so failed rows don't fail the job.&lt;/LI&gt;
&lt;LI&gt;Monitor progress in the query profile.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Docs:&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://docs.databricks.com/aws/en/large-language-models/ai-query" target="_self"&gt;https://docs.databricks.com/aws/en/large-language-models/ai-query&lt;/A&gt; and&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://docs.databricks.com/aws/en/large-language-models/ai-functions" target="_self"&gt;https://docs.databricks.com/aws/en/large-language-models/ai-functions&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Good luck&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2026 17:43:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177631#M2310</guid>
      <dc:creator>Valeria_Koz_DBX</dc:creator>
      <dc:date>2026-11-25T17:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: ai-query Execution</title>
      <link>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177633#M2311</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/221494"&gt;@Valeria_Koz_DBX&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;could u please elaborate on second level i.e; model serving side&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2026 17:52:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/ai-query-execution/m-p/177633#M2311</guid>
      <dc:creator>IM_01</dc:creator>
      <dc:date>2026-11-25T17:52:41Z</dc:date>
    </item>
  </channel>
</rss>

