Skip to content

Commit 9d9dc17

Browse files
Fix genie recipe (#47)
* fix(recipes): fix genie recipe deploy steps and remove genie_space_name variable Removes the broken genie_space_name variable from databricks.yml examples and fixes deploy steps to use bundle deploy + apps deploy sequence instead of the all-in-one apps deploy command. Adds .prettierignore to exclude dist/ and .databricks/ generated directories. * fix(genie-multi-space): clarify AppKit requirements, add prerequisites, improve deploy instructions Co-authored-by: Isaac
1 parent 2148322 commit 9d9dc17

3 files changed

Lines changed: 139 additions & 83 deletions

File tree

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dist/
2+
.databricks/
3+
**/dist/
4+
**/.databricks/
5+
**/node_modules/
6+
node_modules/

content/recipes/genie-conversational-analytics.md

Lines changed: 78 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,83 @@
22

33
Embed a Databricks AI/BI Genie chat interface so users can explore data through natural language. Configure a Genie space, wire up the server and client plugins, declare app resources, and deploy.
44

5-
### 1. Create a Genie space in your Databricks workspace
5+
:::info[Choose your path]
66

7-
Open your Databricks workspace, navigate to **AI/BI Genie**, and create a new Genie space connected to your data tables. Note the **space title** (display name) shown in the Genie list or space header.
7+
- **New app** — follow steps 1 → 2 → 8.
8+
- **Adding Genie to an existing AppKit app** — follow steps 1 → 3 → 4 → 5 → 6 → 7 → 8.
9+
:::
810

9-
To collect both the **title** and **space ID** in one step (for bundle variables and `DATABRICKS_GENIE_SPACE_ID`):
11+
### 1. Create a Genie space and set your profile
12+
13+
Open your Databricks workspace, navigate to **AI/BI Genie**, and create a new Genie space connected to your data tables.
14+
15+
List your spaces to get the `space_id`:
1016

1117
```bash
1218
databricks genie list-spaces -o json --profile <PROFILE>
1319
```
1420

15-
Use the `title` string as **Genie space name** and the `space_id` value wherever a space ID is required (scaffold `--set`, `.env`, and `databricks.yml`).
21+
Use the `space_id` value wherever a space ID is required (scaffold `--set`, `.env`, and `databricks.yml`).
22+
23+
:::tip[Avoid repeating `--profile` on every command]
24+
Add your profile to the bundle's `databricks.yml` under the target — then `bundle deploy` and `apps` commands pick it up automatically:
25+
26+
```yaml
27+
targets:
28+
default:
29+
workspace:
30+
profile: <PROFILE>
31+
```
32+
33+
This is more reliable than `export DATABRICKS_CONFIG_PROFILE` since it persists across shells and works for agents running commands in subshells.
34+
:::
1635

1736
### 2. New app: scaffold with the Genie feature
1837

1938
If you are starting a new app, scaffold it with the Genie feature flag. This generates all server, client, resource, and environment wiring automatically.
2039

40+
Run this from a neutral directory (not inside another app folder) — `apps init` creates the project folder in your current working directory:
41+
2142
```bash
2243
databricks apps init \
2344
--name <app-name> \
2445
--version latest \
2546
--features=genie \
2647
--set 'genie.genie-space.id=<your-space-id>' \
27-
--run none --profile <PROFILE>
48+
--run none
2849
```
2950

30-
Use the `space_id` from step 1 (or the **About** tab on the space) for `<your-space-id>`. The CLI maps this to `DATABRICKS_GENIE_SPACE_ID`.
51+
`--run none` skips launching the app locally after scaffolding. Use the `space_id` from step 1 for `<your-space-id>`.
3152

3253
**App name:** Use at most 26 characters, **lowercase letters, digits, and hyphens only** (no underscores). Example: `my-genie-app`, not `my_genie_app`.
3354

34-
After `init`, open `databricks.yml` and check **`targets.default.variables`**. Some templates set **`genie_space_id`** but omit **`genie_space_name`**. If **`genie_space_name`** is missing or empty, set it to the exact **space title** from step 1 (the same title shown in the Genie UI). Deploy requires both **name** and **space ID** in the bundle for the `genie_space` resource.
55+
:::warning[Fix generated `databricks.yml` before deploying]
56+
The scaffold generates a `genie_space_name` variable and references it as `name: ${var.genie_space_name}`, but never assigns a value. `bundle deploy` will fail with _no value assigned to required variable genie_space_name_.
57+
58+
Your `variables:` block should look like this after the fix — only `genie_space_id`, no `genie_space_name`:
59+
60+
```yaml
61+
variables:
62+
genie_space_id:
63+
description: Default Genie Space ID
64+
```
65+
66+
And the `genie_space` resource block should use a hardcoded label:
3567

36-
`apps init` creates a project folder in **kebab-case** matching `<app-name>`. For deploy and test (step 8), run all commands from **inside that folder** (the directory that contains `databricks.yml`).
68+
```yaml
69+
genie_space:
70+
name: genie-space
71+
space_id: ${var.genie_space_id}
72+
permission: CAN_RUN
73+
```
74+
75+
The `name: genie-space` is an internal label used by `app.yaml` (`valueFrom: genie-space`), not the Genie space display title.
76+
:::
3777

3878
Skip to step 8 to deploy.
3979

80+
---
81+
4082
### 3. Existing app: add Genie server plugin
4183

4284
The following steps match what `apps init --features=genie` generates. Apply them to an existing scaffolded AppKit app.
@@ -125,18 +167,10 @@ import { GeniePage } from "./pages/genie/GeniePage";
125167

126168
The Genie space must be declared as an app resource with the `dashboards.genie` API scope. Without the scope, on-behalf-of user execution fails at runtime.
127169

128-
For local development, add the space ID to `.env` (use the `space_id` from `databricks genie list-spaces` or the space **About** tab):
129-
130-
```bash
131-
DATABRICKS_GENIE_SPACE_ID=<your-space-id>
132-
```
133-
134-
Add the genie-space variables, the `user_api_scopes` and genie resource under your app, and the target variable values. The **name** is the Genie space **title**; **space ID** must match the same space:
170+
Add the `genie_space_id` variable, the `user_api_scopes`, and the genie resource under your app. The `name: genie-space` on the resource is the key that `app.yaml` references via `valueFrom`:
135171

136172
```yaml
137173
variables:
138-
genie_space_name:
139-
description: Genie space display title (as shown in the Genie UI)
140174
genie_space_id:
141175
description: Genie space ID (from list-spaces or About)
142176
@@ -149,19 +183,16 @@ resources:
149183
resources:
150184
- name: genie-space
151185
genie_space:
152-
name: ${var.genie_space_name}
186+
name: genie-space
153187
space_id: ${var.genie_space_id}
154188
permission: CAN_RUN
155189
156190
targets:
157191
default:
158192
variables:
159-
genie_space_name: "<your-space-title>"
160193
genie_space_id: <your-space-id>
161194
```
162195

163-
The `name: genie-space` on the resource is the key that `app.yaml` references via `valueFrom`.
164-
165196
### 7. Existing app: map the environment variable in `app.yaml`
166197

167198
Add the Genie space ID mapping so the deployed app receives the value at runtime:
@@ -180,49 +211,51 @@ For local development, add the space ID to `.env`:
180211
DATABRICKS_GENIE_SPACE_ID=<your-space-id>
181212
```
182213

214+
---
215+
183216
### 8. Deploy and verify
184217

185-
From the app project directory (the folder with `databricks.yml`), deploy and run in one step:
218+
From inside the app project folder (the directory containing `databricks.yml`):
186219

187220
```bash
188221
cd <app-name>
189-
databricks apps deploy --profile <PROFILE>
190-
```
191-
192-
When run from that directory **without** a trailing app name argument, the CLI runs the full pipeline: validate the project (for Node: install if needed, typecheck, lint, build), sync the bundle to the workspace, create an app deployment, and start the app.
193-
194-
:::tip[Multiple CLI profiles for the same workspace]
195222
196-
If the CLI reports that **multiple profiles matched** your workspace host, pass **`--profile <PROFILE>`** on each command, set **`DATABRICKS_CONFIG_PROFILE`** to one profile, or add **`workspace.profile`** under your bundle target in `databricks.yml` so the bundle resolves auth consistently.
197-
198-
:::
223+
# Build the client
224+
npm run build
199225
200-
:::tip[Bundle deploy vs apps deploy]
226+
# Deploy bundle resources and sync files to workspace
227+
# Copy the upload path printed in the output — you'll need it below
228+
databricks bundle deploy
201229
202-
`databricks bundle deploy` updates bundle state and synced files in the workspace, but it does **not** run the full Apps build-and-run pipeline. If you only run `bundle deploy`, the app can stay **UNAVAILABLE** with a message like _deploy source code_ while compute is active. Use `databricks apps deploy` from the app directory when you want the runnable app updated. You may still use `bundle deploy` when you are only changing bundle or workspace configuration and will run `apps deploy` afterward.
230+
# Put the app in RUNNING state and wait for compute to be ready
231+
# The loop polls every 5 seconds — press Ctrl+C if it hangs more than 2 minutes
232+
databricks apps start <app-name>
233+
until databricks apps get <app-name> -o json | grep -q '"ACTIVE"'; do sleep 5; done
203234
204-
:::
205-
206-
Optional flags:
235+
# First deploy requires --source-code-path: paste the path from bundle deploy output above
236+
databricks apps deploy <app-name> \
237+
--source-code-path <path-from-bundle-deploy-output>
238+
```
207239

208-
- `--target <target>` if you use a non-default bundle target.
209-
- `--skip-validation` to skip local build/typecheck/lint (use only when you accept skipping checks).
240+
`bundle deploy` prints the workspace upload path (`Uploading bundle files to ...`) — copy that value for `--source-code-path`. `apps start` puts the app into RUNNING state; the `until` loop waits for compute to be ACTIVE. `apps deploy` deploys the source and starts the app server.
210241

211-
Check app status, URL, and logs (replace `<app-name>` with the name from `databricks.yml`):
242+
For subsequent deploys, `--source-code-path` is not needed — the app remembers the path:
212243

213244
```bash
214-
databricks apps get <app-name> --profile <PROFILE>
215-
databricks apps list --profile <PROFILE>
216-
databricks apps logs <app-name> --profile <PROFILE>
245+
npm run build
246+
databricks bundle deploy
247+
databricks apps deploy <app-name>
217248
```
218249

219-
If the app is **UNAVAILABLE** with _deploy source code_, run `databricks apps deploy` from the app project directory again (not from a parent repo root). If **compute** is **STOPPED**, start it:
250+
Check app status and get the URL:
220251

221252
```bash
222-
databricks apps start <app-name> --profile <PROFILE>
253+
databricks apps get <app-name>
223254
```
224255

225-
Open the app URL from `databricks apps get` while signed in to Databricks, navigate to the Genie page, and ask a natural-language question about your data to verify the integration.
256+
Open `<app-url>/genie` while signed in to Databricks and ask a natural-language question about your data to verify the integration.
257+
258+
If compute is **STOPPED**, run `databricks apps start <app-name>` and wait for `compute_status.state: ACTIVE` before deploying.
226259

227260
### 9. Troubleshoot common issues
228261

0 commit comments

Comments
 (0)