Skip to content

Commit e275eec

Browse files
Add AI context page to data modeling (cube-js#10605)
* Add AI context page to data modeling section Generated-By: mintlify-agent * fix --------- Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> Co-authored-by: Artyom Keydunov <artyom.keydunov@gmail.com>
1 parent 94a2175 commit e275eec

6 files changed

Lines changed: 329 additions & 4 deletions

File tree

docs-mintlify/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"docs/data-modeling/concepts/data-blending"
8686
]
8787
},
88+
"docs/data-modeling/ai-context",
8889
{
8990
"group": "Access Control",
9091
"pages": [
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
---
2+
title: AI context
3+
description: Optimize your data model for AI by using descriptions and the meta ai_context property to provide additional context.
4+
---
5+
6+
When using [Analytics Chat][ref-analytics-chat] or other AI-powered features,
7+
the AI agent relies on your data model to understand your data. You can
8+
optimize your data model to help the AI generate more accurate queries and
9+
provide better insights.
10+
11+
There are two ways to provide additional context to the AI:
12+
13+
- **Descriptions** — visible to both end users and the AI agent.
14+
- **AI context via `meta`** — only visible to the AI agent, not exposed in the
15+
user interface.
16+
17+
## Using descriptions
18+
19+
The [`description`][ref-cube-description] parameter on cubes, views, measures,
20+
dimensions, and segments provides human-readable context that is displayed in
21+
the UI and also consumed by the AI agent.
22+
23+
Use descriptions to clarify the meaning of a member for both your team and
24+
end users:
25+
26+
<CodeGroup>
27+
28+
```yaml title="YAML"
29+
cubes:
30+
- name: orders
31+
sql_table: orders
32+
description: All orders including pending, shipped, and completed
33+
34+
measures:
35+
- name: total_revenue
36+
sql: amount
37+
type: sum
38+
description: Total revenue from completed orders only
39+
filters:
40+
- sql: "{CUBE}.status = 'completed'"
41+
42+
dimensions:
43+
- name: status
44+
sql: status
45+
type: string
46+
description: "Current order status: pending, shipped, or completed"
47+
```
48+
49+
```javascript title="JavaScript"
50+
cube(`orders`, {
51+
sql_table: `orders`,
52+
description: `All orders including pending, shipped, and completed`,
53+
54+
measures: {
55+
total_revenue: {
56+
sql: `amount`,
57+
type: `sum`,
58+
description: `Total revenue from completed orders only`,
59+
filters: [{ sql: `${CUBE}.status = 'completed'` }]
60+
}
61+
},
62+
63+
dimensions: {
64+
status: {
65+
sql: `status`,
66+
type: `string`,
67+
description: `Current order status: pending, shipped, or completed`
68+
}
69+
}
70+
})
71+
```
72+
73+
</CodeGroup>
74+
75+
Descriptions are a good starting point because they serve double duty — they
76+
help end users understand the data and also give the AI agent context for
77+
query generation.
78+
79+
## Using AI context
80+
81+
If you want to provide context to the AI agent **without exposing it in the
82+
user interface**, use the `ai_context` key inside the
83+
[`meta`][ref-cube-meta] parameter. The `meta` parameter accepts custom
84+
metadata on cubes, views, measures, and dimensions.
85+
86+
<CodeGroup>
87+
88+
```yaml title="YAML"
89+
cubes:
90+
- name: orders
91+
sql_table: orders
92+
description: All orders
93+
meta:
94+
ai_context: >
95+
This cube contains all e-commerce orders. When users ask about
96+
revenue, prefer the total_revenue measure which filters for
97+
completed orders only. The amount column includes tax.
98+
99+
measures:
100+
- name: total_revenue
101+
sql: amount
102+
type: sum
103+
filters:
104+
- sql: "{CUBE}.status = 'completed'"
105+
meta:
106+
ai_context: >
107+
Use this measure for any revenue-related questions.
108+
This excludes pending and cancelled orders.
109+
110+
dimensions:
111+
- name: created_at
112+
sql: created_at
113+
type: time
114+
meta:
115+
ai_context: >
116+
This is the order creation timestamp in UTC.
117+
For fiscal year reporting, use the completed_at
118+
dimension instead.
119+
```
120+
121+
```javascript title="JavaScript"
122+
cube(`orders`, {
123+
sql_table: `orders`,
124+
description: `All orders`,
125+
meta: {
126+
ai_context: `This cube contains all e-commerce orders. When users ask
127+
about revenue, prefer the total_revenue measure which filters for
128+
completed orders only. The amount column includes tax.`
129+
},
130+
131+
measures: {
132+
total_revenue: {
133+
sql: `amount`,
134+
type: `sum`,
135+
filters: [{ sql: `${CUBE}.status = 'completed'` }],
136+
meta: {
137+
ai_context: `Use this measure for any revenue-related questions.
138+
This excludes pending and cancelled orders.`
139+
}
140+
}
141+
},
142+
143+
dimensions: {
144+
created_at: {
145+
sql: `created_at`,
146+
type: `time`,
147+
meta: {
148+
ai_context: `This is the order creation timestamp in UTC.
149+
For fiscal year reporting, use the completed_at
150+
dimension instead.`
151+
}
152+
}
153+
}
154+
})
155+
```
156+
157+
</CodeGroup>
158+
159+
You can also use `ai_context` on [views][ref-view-meta]:
160+
161+
<CodeGroup>
162+
163+
```yaml title="YAML"
164+
views:
165+
- name: revenue_overview
166+
description: Revenue metrics and breakdowns
167+
meta:
168+
ai_context: >
169+
This is the primary view for revenue analysis. It combines
170+
order and product data. Use this view when users ask about
171+
sales, revenue, or product performance.
172+
173+
cubes:
174+
- join_path: orders
175+
includes:
176+
- total_revenue
177+
- created_at
178+
- status
179+
```
180+
181+
```javascript title="JavaScript"
182+
view(`revenue_overview`, {
183+
description: `Revenue metrics and breakdowns`,
184+
meta: {
185+
ai_context: `This is the primary view for revenue analysis. It combines
186+
order and product data. Use this view when users ask about
187+
sales, revenue, or product performance.`
188+
},
189+
190+
cubes: [
191+
{
192+
join_path: orders,
193+
includes: [
194+
`total_revenue`,
195+
`created_at`,
196+
`status`
197+
]
198+
}
199+
]
200+
})
201+
```
202+
203+
</CodeGroup>
204+
205+
## Descriptions vs. AI context
206+
207+
| | `description` | `meta.ai_context` |
208+
| --- | --- | --- |
209+
| Visible in the UI | Yes | No |
210+
| Used by the AI agent | Yes | Yes |
211+
| Supported on | Cubes, views, measures, dimensions, segments | Cubes, views, measures, dimensions |
212+
213+
Use `description` when the context is useful to both end users and the AI
214+
agent. Use `ai_context` when you want to provide additional instructions or
215+
context that is only relevant to the AI agent — for example, guidance on
216+
which measures to prefer, nuances about data quality, or business logic that
217+
would be confusing in a user-facing description.
218+
219+
You can use both together. The AI agent reads both the `description` and
220+
`ai_context` when generating queries:
221+
222+
<CodeGroup>
223+
224+
```yaml title="YAML"
225+
cubes:
226+
- name: orders
227+
sql_table: orders
228+
description: All customer orders
229+
meta:
230+
ai_context: >
231+
When users ask about "sales", they usually mean completed
232+
orders only. Prefer total_revenue over raw amount sums.
233+
234+
measures:
235+
- name: total_revenue
236+
sql: amount
237+
type: sum
238+
description: Total revenue from completed orders
239+
filters:
240+
- sql: "{CUBE}.status = 'completed'"
241+
meta:
242+
ai_context: >
243+
This is the primary revenue metric. Always use this
244+
instead of summing the amount dimension directly.
245+
```
246+
247+
```javascript title="JavaScript"
248+
cube(`orders`, {
249+
sql_table: `orders`,
250+
description: `All customer orders`,
251+
meta: {
252+
ai_context: `When users ask about "sales", they usually mean completed
253+
orders only. Prefer total_revenue over raw amount sums.`
254+
},
255+
256+
measures: {
257+
total_revenue: {
258+
sql: `amount`,
259+
type: `sum`,
260+
description: `Total revenue from completed orders`,
261+
filters: [{ sql: `${CUBE}.status = 'completed'` }],
262+
meta: {
263+
ai_context: `This is the primary revenue metric. Always use this
264+
instead of summing the amount dimension directly.`
265+
}
266+
}
267+
}
268+
})
269+
```
270+
271+
</CodeGroup>
272+
273+
## Best practices
274+
275+
- **Add descriptions to all public members.** Descriptions help both end users
276+
and the AI agent understand your data model.
277+
- **Use AI context for agent-specific guidance.** If you need to tell the AI
278+
agent which measure to prefer or how to interpret ambiguous terms, use
279+
`ai_context`.
280+
- **Be specific.** Vague context like "important metric" is less helpful than
281+
"use this measure when users ask about monthly recurring revenue."
282+
- **Document relationships.** Use AI context to explain how cubes relate to each
283+
other and which views to prefer for common questions.
284+
- **Keep it up to date.** As your data model evolves, update descriptions and AI
285+
context to reflect the current state.
286+
287+
[ref-analytics-chat]: /docs/explore-analyze/analytics-chat
288+
[ref-cube-description]: /reference/data-modeling/cube#description
289+
[ref-cube-meta]: /reference/data-modeling/cube#meta
290+
[ref-view-meta]: /reference/data-modeling/view#meta

docs-mintlify/reference/data-modeling/cube.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ SELECT FLOOR(EXTRACT(EPOCH FROM NOW()) / 5)
585585

586586
Custom metadata. Can be used to pass any information to the frontend.
587587

588+
You can also use the `ai_context` key to provide context to the
589+
[AI agent][ref-ai-context] without exposing it in the user interface.
590+
588591
<CodeGroup>
589592

590593
```yaml title="YAML"
@@ -594,6 +597,9 @@ cubes:
594597
title: Product Orders
595598
meta:
596599
any: value
600+
ai_context: >
601+
This cube contains all e-commerce orders. When users ask
602+
about revenue, prefer the total_revenue measure.
597603
598604
```
599605
@@ -602,7 +608,9 @@ cube(`orders`, {
602608
sql_table: `orders`,
603609
title: `Product Orders`,
604610
meta: {
605-
any: `value`
611+
any: `value`,
612+
ai_context: `This cube contains all e-commerce orders. When users ask
613+
about revenue, prefer the total_revenue measure.`
606614
}
607615
})
608616
```
@@ -648,6 +656,7 @@ The `measures` parameter is used to configure [measures][ref-ref-measures].
648656
The `access_policy` parameter is used to configure [access policies][ref-ref-dap].
649657

650658

659+
[ref-ai-context]: /docs/data-modeling/ai-context
651660
[ref-config-driverfactory]: /reference/configuration/config#driverfactory
652661
[ref-recipe-control-access-cubes-views]: /docs/data-modeling/access-control/recipes/controlling-access-to-cubes-and-views
653662
[ref-naming]: /docs/data-modeling/syntax#naming

docs-mintlify/reference/data-modeling/dimensions.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ Using it with other dimension types will result in a validation error.
430430

431431
Custom metadata. Can be used to pass any information to the frontend.
432432

433+
You can also use the `ai_context` key to provide context to the
434+
[AI agent][ref-ai-context] without exposing it in the user interface.
435+
433436
<CodeGroup>
434437

435438
```yaml title="YAML"
@@ -443,6 +446,9 @@ cubes:
443446
type: number
444447
meta:
445448
any: value
449+
ai_context: >
450+
This is a subquery dimension. Use it to get the
451+
number of users associated with each product.
446452
```
447453
448454
```javascript title="JavaScript"
@@ -454,7 +460,9 @@ cube(`products`, {
454460
sql: `${users.count}`,
455461
type: `number`,
456462
meta: {
457-
any: "value"
463+
any: "value",
464+
ai_context: `This is a subquery dimension. Use it to get the
465+
number of users associated with each product.`
458466
}
459467
}
460468
}
@@ -1187,6 +1195,7 @@ cube(`fiscal_calendar`, {
11871195
</CodeGroup>
11881196

11891197

1198+
[ref-ai-context]: /docs/data-modeling/ai-context
11901199
[ref-ref-cubes]: /reference/data-modeling/cube
11911200
[ref-schema-ref-joins]: /reference/data-modeling/joins
11921201
[ref-subquery]: /docs/data-modeling/concepts/calculated-members#subquery-dimensions

0 commit comments

Comments
 (0)