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

# AI Copilot

> AI Copilot helps users turn a plain-language analytics question into a working Databrain metric.

AI Copilot helps users turn a plain-language analytics question into a working Databrain metric. It is available inside the metric creation workflow and can generate SQL, execute the query, suggest a visualization, map dimensions and measures, and keep the conversation available through session history.

## Prerequisites

Before using AI Copilot, make sure the workspace has:

* A connected data source or datamart with schema access.
* At least one LLM configured in Databrain under **Settings > LLMs** **> +LLM**
* At least one model selected under **Workspace Settings > AI Copilot LLM**.
* Access to the metric creation page.
* Permission to update workspace settings, if you are configuring the feature.

The **LLM Settings** field is used for Chat Mode and Metric Summary. The **AI Copilot LLM** field is used for AI Copilot and the custom SQL editor.

## Steps to setup AI Copilot:

## 1. Enable AI Copilot

1. Open the workspace where you want to use AI Copilot.
2. Click the workspace settings icon.
3. In **Workspace Settings**, open the **General** tab.
4. Under **Creator Settings**, select **Power Mode**.
5. In **AI Copilot LLM**, select one or more LLMs.
6. Click **Save**.

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/MN8R7HS_YNqryNkP/images/guides/setup-llm.png?fit=max&auto=format&n=MN8R7HS_YNqryNkP&q=85&s=76f654896b72777ff6a2a79ef11a133c" alt="Workspace Settings showing the AI Copilot LLM model selection under Power Mode" width="2940" height="1660" data-path="images/guides/setup-llm.png" />
</Frame>

If no global LLM exists, Databrain prompts the user to configure one from **LLM Settings**. If a global LLM exists but no workspace model is selected for AI Copilot, Databrain prompts the user to update **Workspace Settings**.

## 2. Open AI Copilot

1. Go to the metric creation page.
2. Confirm the correct workspace, data source or datamart, and client context.
3. Click **AI Copilot** in the top-right of the metric builder.

AI Copilot opens as a right-side panel. The panel shows suggested questions when enough schema, history, memory, or example context is available.

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/93HRF6Yydm_89aBZ/images/guides/ai-copilot.png?fit=max&auto=format&n=93HRF6Yydm_89aBZ&q=85&s=4f4cdeb1ca7cbdee9b9ccd1939dff29a" alt="AI Copilot button in the top-right corner of the metric builder" width="2940" height="1662" data-path="images/guides/ai-copilot.png" />
</Frame>

## 3. Ask a question

Type a business question in natural language. For best results, include the metric, grouping, filter, and time period when relevant.

Examples:

* `Show total users by subscription type`
* `Trend of revenue by month for the last 6 months`
* `Top 5 customers by order value`
* `How is product demand segmented across different subscription models?`

If multiple AI Copilot LLMs are enabled for the workspace, use the model selector in the input area to choose the model for the request.

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/93HRF6Yydm_89aBZ/images/guides/ask-a-question-2.png?fit=max&auto=format&n=93HRF6Yydm_89aBZ&q=85&s=e6bcaec2112cb81612b6194af5d42232" alt="Entering a natural-language analytics question and selecting an LLM in AI Copilot" width="2940" height="1662" data-path="images/guides/ask-a-question-2.png" />
</Frame>

After you submit the question, AI Copilot:

1. Validates that the prompt is an analytics/data question.
2. Uses the workspace or datamart schema, table relationships, examples, memory, and prior conversation context.
3. Generates SQL through the selected LLM.
4. Executes the SQL through Databrain.
5. Returns a chart-ready response with SQL, metadata, reasoning, dimensions, and measures.

## 4. Review the result

AI Copilot displays the generated metric in the main chart area and shows the explanation in the Copilot panel.

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/MN8R7HS_YNqryNkP/images/guides/result.gif?s=e0787080ce8aa3600add3a379ee107e7" alt="AI Copilot generated metric with reasoning, tables, columns, measures, dimensions, and SQL details" width="1632" height="918" data-path="images/guides/result.gif" />
</Frame>

Review the following before saving:

* **Chart output**: Confirms whether the generated result answers the question.
* **Dimensions**: Shows the grouping fields used in the metric.
* **Measures**: Shows the aggregated values used in the metric.
* **Reasoning**: Explains why Copilot selected the tables, columns, and aggregation.
* **Tables Used**: Lists the source tables used by the generated SQL.
* **Columns Used**: Lists the source columns used by the generated SQL.
* **SQL Query**: Shows the generated SQL. Expand this section to inspect the query.

In the SQL section, use the edit icon to open the generated SQL in the editor. You can adjust the query before applying or saving the metric.

## Use the context window indicator

The context window indicator shows how much of the selected model's context window has been used in the current Copilot session.

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/databrainlabs-bef6850a/images/guides/context-window-indicator%202.png" alt="AI Copilot context window indicator showing input tokens, output tokens, and total model context" />
</Frame>

Hover over the indicator to view:

* **Input** tokens used by prompts and context.
* **Output** tokens used by model responses.
* The selected model's total context window.

If the context window becomes full, Databrain disables the Copilot input and asks you to start a new session. Use this when the conversation has become too long or when you want to switch to a different analysis topic.

## Use Copilot history

AI Copilot keeps session history so users can continue prior analysis without starting from scratch.

<Frame>
  <img src="https://mintcdn.com/databrainlabs-bef6850a/AEbdshbbAbrBaqqe/images/guides/history.gif?s=b187dac4c33a86736a3ba3b157a0fed1" alt="AI Copilot session history opened from the timer icon" width="1632" height="918" data-path="images/guides/history.gif" />
</Frame>

From the Copilot panel, you can:

* Start a new session using the plus icon.
* Open history using the timer icon.
* Reopen a previous session.
* Rename a session.
* Archive a session you no longer need.

Sessions are scoped to the user and workspace context. When reopened, Databrain restores the previous questions and responses so follow-up questions can continue from the same analytical thread.

## Best practices

* Use business-friendly but specific questions.
* Include dimensions, measures, filters, and date ranges when known.
* Review SQL before saving production metrics.
* Use separate sessions for unrelated analysis topics.

## Related resources

* [LLM Connectors](https://docs.usedatabrain.com/developer-docs/helpers/llm-connectors)
* [AI Copilot for Embedded Analytics](https://www.usedatabrain.com/blog/ai-copilot-for-embedded-analytics)
