> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maia.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Query

export const ComponentMetadata = ({warehouses, unsupportedWarehouses = [], componentType, connectionInputs, connectionOutputs}) => {
  const allWarehouses = [...warehouses.map(w => ({
    name: w,
    supported: true
  })), ...unsupportedWarehouses.map(w => ({
    name: w,
    supported: false
  }))];
  return <div style={{
    background: 'var(--colors-background-light, #f9fafb)',
    border: '1px solid var(--colors-border-default, #e5e7eb)',
    borderRadius: '12px',
    padding: '20px 28px',
    marginBottom: '28px',
    boxShadow: '0 1px 4px rgba(0,0,0,0.10)'
  }}>
      <table style={{
    width: '100%',
    borderCollapse: 'collapse'
  }}>
        <tbody>
          <tr>
            <td style={{
    fontWeight: '600',
    paddingRight: '32px',
    paddingBottom: '14px',
    whiteSpace: 'nowrap',
    verticalAlign: 'middle',
    width: '180px'
  }}>Project Availability</td>
            <td style={{
    paddingBottom: '14px',
    verticalAlign: 'middle'
  }}>
              <div style={{
    display: 'flex',
    flexWrap: 'wrap',
    gap: '8px'
  }}>
                {allWarehouses.map((w, i) => <span key={i} style={{
    background: w.supported ? '#dcfce7' : '#fee2e2',
    color: w.supported ? '#15803d' : '#b91c1c',
    border: `1px solid ${w.supported ? '#bbf7d0' : '#fca5a5'}`,
    borderRadius: '9999px',
    padding: '3px 12px',
    fontSize: '0.85rem',
    fontWeight: '500',
    whiteSpace: 'nowrap'
  }}>
                    {w.name} {w.supported ? '✅' : '❌'}
                  </span>)}
              </div>
            </td>
          </tr>
          <tr>
            <td style={{
    fontWeight: '600',
    paddingRight: '32px',
    paddingBottom: '14px',
    whiteSpace: 'nowrap',
    verticalAlign: 'middle'
  }}>Component Type</td>
            <td style={{
    paddingBottom: '14px',
    verticalAlign: 'middle'
  }}>{componentType}</td>
          </tr>
          <tr>
            <td style={{
    fontWeight: '600',
    paddingRight: '32px',
    paddingBottom: '14px',
    whiteSpace: 'nowrap',
    verticalAlign: 'middle'
  }}>Connection Inputs</td>
            <td style={{
    paddingBottom: '14px',
    verticalAlign: 'middle'
  }}>{connectionInputs}</td>
          </tr>
          <tr>
            <td style={{
    fontWeight: '600',
    paddingRight: '32px',
    whiteSpace: 'nowrap',
    verticalAlign: 'middle'
  }}>Connection Outputs</td>
            <td style={{
    verticalAlign: 'middle'
  }}>{connectionOutputs}</td>
          </tr>
        </tbody>
      </table>
    </div>;
};

<ComponentMetadata warehouses={["Databricks"]} unsupportedWarehouses={["Snowflake", "Amazon Redshift", "BigQuery"]} componentType="Transformation" connectionInputs="One" connectionOutputs="Unlimited" />

<Info>
  Production use of this feature is available for specific editions only. [Contact our sales team](https://www.matillion.com/contact) for more information.
</Info>

The **AI Query** transformation component uses the Databricks [ai\_query()](https://docs.databricks.com/en/sql/language-manual/functions/ai_query.html) function to obtain an answer to a natural-language question. This function uses a Databricks chat model serving endpoint made available by [Databricks Foundation Model APIs](https://docs.databricks.com/en/machine-learning/foundation-models/index.html).

The component takes one or more input columns from your source table, combines the inputs with a user prompt, and sends this data to the Databricks chat model for processing.

The output is a string containing the chat model's response to the question.

<Note>
  * Make sure you have read and understand the [Requirements](https://docs.databricks.com/en/sql/language-manual/functions/ai_query.html#requirements) set out by Databricks before using this component.
  * For Databricks Runtime 14.2 and above, this function is supported in notebook environments including Databricks notebooks and workflows.
  * For Databricks Runtime 14.1 and below, this function is not supported in notebook environments, including Databricks notebooks.
</Note>

### Use case

You can use the AI Query component to ask questions of a source text in plain English. A typical use case might be analyzing a table of sales data with questions such as:

* What were the total sales last quarter?
* Show me the top 5 products by revenue in 2024.
* How many users signed up each month in 2023?
* Show orders from California over \$1000 in the last 30 days.

***

## Properties

<ResponseField name="Name" type="string" required>
  A human-readable name for the component.
</ResponseField>

{/* <!-- param-start:[model] | warehouses: [databricks] --> */}

<ResponseField name="Model" type="drop-down" required>
  Select the Databricks model serving endpoint that will be used to answer the query. The following models are currently supported:

  * DBRX Instruct
  * Meta-Llama-3-70B-Instruct
  * Meta-Llama-2-70B-Chat
  * Mixtral-8x7B Instruct
</ResponseField>

{/* <!-- param-start:[userPrompt] | warehouses: [databricks] --> */}

<ResponseField name="User Prompt" type="text editor" required>
  Use the text editor to write a question for the chat model to respond to.

  To use variables in this field, type the name of the variable prefixed by the dollar symbol and surrounded by \{ } brackets, as follows: `${variable}`. Once you type `${`, a drop-down list of autocompleted suggested variables will appear. This list updates as you type; for example, if you type `${date`, functions and variables containing `date` will be listed.
</ResponseField>

{/* <!-- param-start:[columns] | warehouses: [databricks] --> */}

<ResponseField name="Columns" type="column editor">
  Select the source columns to feed as input to the chat model.

  * **Column Name:** A column from the input table.
  * **Descriptive Name:** An alternate descriptive name to better contextualize the column. Recommended if your column names are low-context.
</ResponseField>

{/* <!-- param-start:[includeInputColumns] | warehouses: [databricks] --> */}

<ResponseField name="Include Input Columns" type="boolean" required>
  * **Yes:** Outputs both your source input columns *and* the query response. This will also include those input columns *not* selected in **Columns**.
  * **No:** Only includes the query response.
</ResponseField>
