Skip to content

Commit 48a4b06

Browse files
janniklasroseIsaac
andauthored
Capture UC dependencies for vector search indexes (#6655)
## What Extend the `CaptureUCDependencies` mutator to handle vector search indexes. A vector search index's `name` is a three-part `catalog.schema.index` UC identifier. When the catalog or schema is also defined in the same bundle, the mutator now rewrites those segments to `${resources.catalogs.<key>.name}` / `${resources.schemas.<key>.name}` references, so the deploy engine captures the deploy-time dependency and creates the catalog/schema before the index. This follows the existing compound-name handling for quality monitors (`OutputSchemaName`), just with three segments instead of two. ## Why Without this, a bundle that defines a schema and a vector search index living in that schema has no captured ordering dependency, so a deploy can attempt to create the index before its schema exists. ## Tests - Unit tests: wired the index into the combined `TestCaptureUCDependencies` and added `TestCaptureUCDependenciesVectorSearchIndexEdgeCases` (match / catalog-only / no-match / empty / two-part / nil), plus the nil-resources panic-safety case. - Acceptance test: `bundle/resource_deps/implicit_deps_vector_search_index` mirrors `implicit_deps_quality_monitor`; all EnvMatrix variants (terraform/direct × DMS) produce identical output. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 7498b24 commit 48a4b06

8 files changed

Lines changed: 115 additions & 5 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Capture the implicit dependency a vector search index has on a catalog or schema defined in the same bundle, so the catalog and schema are deployed first. ([#6655](https://github.com/databricks/cli/pull/6655))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
bundle:
2+
name: test-bundle
3+
4+
# Tests implicit dependency detection for vector search indexes:
5+
# - name (format "catalog.schema.index") should resolve the catalog and schema parts
6+
resources:
7+
catalogs:
8+
my_catalog:
9+
name: mycatalog
10+
schemas:
11+
my_schema:
12+
catalog_name: mycatalog
13+
name: myschema
14+
vector_search_indexes:
15+
my_index:
16+
name: mycatalog.myschema.myindex
17+
endpoint_name: my-endpoint
18+
primary_key: id
19+
index_type: DIRECT_ACCESS
20+
direct_access_index_spec:
21+
schema_json: '{"id":"integer","vector":"array<float>"}'
22+
23+
targets:
24+
dev:
25+
mode: development

‎acceptance/bundle/resource_deps/implicit_deps_vector_search_index/out.test.toml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
>>> [CLI] bundle validate -t dev -o json
3+
{
4+
"catalogs": {
5+
"my_catalog": {
6+
"name": "mycatalog"
7+
}
8+
},
9+
"schemas": {
10+
"my_schema": {
11+
"catalog_name": "${resources.catalogs.my_catalog.name}",
12+
"name": "dev_[USERNAME]_myschema"
13+
}
14+
},
15+
"vector_search_indexes": {
16+
"my_index": {
17+
"direct_access_index_spec": {
18+
"schema_json": "{\"id\":\"integer\",\"vector\":\"array<float>\"}"
19+
},
20+
"endpoint_name": "my-endpoint",
21+
"index_type": "DIRECT_ACCESS",
22+
"name": "${resources.catalogs.my_catalog.name}.${resources.schemas.my_schema.name}.myindex",
23+
"primary_key": "id"
24+
}
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI bundle validate -t dev -o json | jq .resources
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RecordRequests = false

‎bundle/config/mutator/resourcemutator/capture_uc_dependencies.go‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
type captureUCDependencies struct{}
1414

1515
// If a user defines a UC schema in the bundle, they can refer to it in SDP pipelines,
16-
// UC Volumes, Registered Models, Quality Monitors, or Model Serving Endpoints using the
17-
// `${resources.schemas.<schema_key>.name}` syntax. Using this syntax allows TF to capture
18-
// the deploy time dependency this resource has on the schema and deploy changes to the
19-
// schema before deploying the dependent resource.
16+
// UC Volumes, Registered Models, Quality Monitors, Model Serving Endpoints, or Vector Search
17+
// Indexes using the `${resources.schemas.<schema_key>.name}` syntax. Using this syntax allows
18+
// TF to capture the deploy time dependency this resource has on the schema and deploy changes
19+
// to the schema before deploying the dependent resource.
2020
//
2121
// Similarly, if a user defines a UC catalog in the bundle, they can refer to it in UC schemas,
22-
// UC Volumes, Registered Models, or Model Serving Endpoints using the
22+
// UC Volumes, Registered Models, Model Serving Endpoints, or Vector Search Indexes using the
2323
// `${resources.catalogs.<catalog_key>.name}` syntax. This captures the deploy time
2424
// dependency the resource has on the catalog.
2525
//
@@ -155,6 +155,18 @@ func (m *captureUCDependencies) Apply(ctx context.Context, b *bundle.Bundle) dia
155155
qm.OutputSchemaName = resolved
156156
}
157157
}
158+
for _, idx := range b.Config.Resources.VectorSearchIndexes {
159+
if idx == nil {
160+
continue
161+
}
162+
// Name is a three-part "catalog.schema.index" UC identifier.
163+
parts := strings.SplitN(idx.Name, ".", 3)
164+
if len(parts) != 3 {
165+
continue
166+
}
167+
catalogName, schemaName := parts[0], parts[1]
168+
idx.Name = resolveCatalog(b, catalogName) + "." + resolveSchema(b, catalogName, schemaName) + "." + parts[2]
169+
}
158170
for _, mse := range b.Config.Resources.ModelServingEndpoints {
159171
if mse == nil {
160172
continue

‎bundle/config/mutator/resourcemutator/capture_uc_dependencies_test.go‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/databricks/databricks-sdk-go/service/catalog"
1010
"github.com/databricks/databricks-sdk-go/service/pipelines"
1111
"github.com/databricks/databricks-sdk-go/service/serving"
12+
"github.com/databricks/databricks-sdk-go/service/vectorsearch"
1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415
)
@@ -136,6 +137,11 @@ func TestCaptureUCDependencies(t *testing.T) {
136137
Parent: "schemas/mycatalog.myschema", ModelServiceId: "myservice",
137138
}},
138139
},
140+
VectorSearchIndexes: map[string]*resources.VectorSearchIndex{
141+
"my_index": {CreateVectorIndexRequest: vectorsearch.CreateVectorIndexRequest{
142+
Name: "mycatalog.myschema.myindex",
143+
}},
144+
},
139145
},
140146
},
141147
}
@@ -171,6 +177,9 @@ func TestCaptureUCDependencies(t *testing.T) {
171177

172178
// Model service (compound "schemas/{catalog}.{schema}" parent field).
173179
assert.Equal(t, "schemas/"+catalogRef+"."+schemaRef, b.Config.Resources.ModelServices["my_model_service"].Parent)
180+
181+
// Vector search index (three-part "catalog.schema.index" name).
182+
assert.Equal(t, catalogRef+"."+schemaRef+".myindex", b.Config.Resources.VectorSearchIndexes["my_index"].Name)
174183
}
175184

176185
// Pipeline schema and target are mutually exclusive; only the populated field
@@ -287,6 +296,37 @@ func TestCaptureUCDependenciesModelServingEndpointEdgeCases(t *testing.T) {
287296
assert.Nil(t, b.Config.Resources.ModelServingEndpoints["nil_endpoint"])
288297
}
289298

299+
func TestCaptureUCDependenciesVectorSearchIndexEdgeCases(t *testing.T) {
300+
b := &bundle.Bundle{
301+
Config: config.Root{
302+
Resources: config.Resources{
303+
Catalogs: map[string]*resources.Catalog{
304+
"my_catalog": {CreateCatalog: catalog.CreateCatalog{Name: "mycatalog"}},
305+
},
306+
Schemas: map[string]*resources.Schema{
307+
"my_schema": {CreateSchema: catalog.CreateSchema{CatalogName: "mycatalog", Name: "myschema"}},
308+
},
309+
VectorSearchIndexes: map[string]*resources.VectorSearchIndex{
310+
"catalog_only": {CreateVectorIndexRequest: vectorsearch.CreateVectorIndexRequest{Name: "mycatalog.other.myindex"}},
311+
"no_match": {CreateVectorIndexRequest: vectorsearch.CreateVectorIndexRequest{Name: "other.other.myindex"}},
312+
"empty": {CreateVectorIndexRequest: vectorsearch.CreateVectorIndexRequest{Name: ""}},
313+
"two_part": {CreateVectorIndexRequest: vectorsearch.CreateVectorIndexRequest{Name: "mycatalog.myschema"}},
314+
"nil_index": nil,
315+
},
316+
},
317+
},
318+
}
319+
320+
d := bundle.Apply(t.Context(), b, CaptureUCDependencies())
321+
require.Nil(t, d)
322+
323+
assert.Equal(t, "${resources.catalogs.my_catalog.name}.other.myindex", b.Config.Resources.VectorSearchIndexes["catalog_only"].Name)
324+
assert.Equal(t, "other.other.myindex", b.Config.Resources.VectorSearchIndexes["no_match"].Name)
325+
assert.Empty(t, b.Config.Resources.VectorSearchIndexes["empty"].Name)
326+
assert.Equal(t, "mycatalog.myschema", b.Config.Resources.VectorSearchIndexes["two_part"].Name)
327+
assert.Nil(t, b.Config.Resources.VectorSearchIndexes["nil_index"])
328+
}
329+
290330
// Nil and empty resources should not panic.
291331
func TestCaptureUCDependenciesNilResources(t *testing.T) {
292332
b := &bundle.Bundle{
@@ -299,6 +339,7 @@ func TestCaptureUCDependenciesNilResources(t *testing.T) {
299339
Pipelines: map[string]*resources.Pipeline{"nil": nil, "empty": {}},
300340
QualityMonitors: map[string]*resources.QualityMonitor{"nil": nil, "empty": {}},
301341
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{"nil": nil, "empty": {}},
342+
VectorSearchIndexes: map[string]*resources.VectorSearchIndex{"nil": nil, "empty": {}},
302343
},
303344
},
304345
}

0 commit comments

Comments
 (0)