Important
이 기능은 비공개 프리뷰. 이를 시도하려면 Azure Databricks 연락처에 문의하세요.
선언적 자동화 번들(이전 명칭: Databricks Asset Bundles)은 기능 뷰와 이를 지원하는 엔드포인트와 같은 Azure Databricks 리소스를 프로그래밍 방식으로 검증, 배포 및 실행할 수 있게 해줍니다. 선언적 자동화 번들이란 무엇인가?를 참조하세요.
이 튜토리얼은 두 개의 스트리밍 기능 뷰를 선언하고, 이를 온라인 스토어에 구체화한 뒤, FeatureSpec 및 Feature Serving 엔드포인트를 통해 제공하는 번들을 만듭니다. 그 후 엔드포인트를 쿼리하고, 어떤 기능을 제공하는지 바꾸고, 모든 리소스를 정리합니다.
특징 뷰와 그 머티리얼라이제이션은 선언적 자동화 번들로 특징 뷰 관리를 따르며, 여기에서 자세히 설명합니다. 대신 Python API로 FeatureSpec 및 엔드포인트를 생성하려면 '기능 보기 제공'을 참조하세요.
각 단계마다 YAML과 Python의 구성이 표시됩니다. 언어를 선택하면 페이지가 그 선택에 따라 바뀝니다.
Requirements
이 자습서를 완료하려면 다음이 필요합니다.
- Databricks CLI 버전 1.26.0 이상입니다. 실행
databricks --version하여 확인합니다. Databricks CLI 설치 또는 업데이트를 참조하세요. - Unity 카탈로그 사용 작업 영역입니다. 요구 사항을 참조하세요.
- 피처를 생성하고 구체화할 수 있는 권한. 사용 권한을 참조하세요.
- 모델 서비스 엔드포인트를 생성할 수 있는 권한. ID 및 액세스를 참조하세요.
- 기존 온라인 스토어. 온라인 상점 만들기를 참조하세요.
- 기존의 스트림. 스트림은 번들 리소스가 아니므로, 먼저 생성하고 번들 내에서 이름으로 참조하세요. 스트림 만들기를 확인하세요.
- Python에서 리소스를 선언하려면 Python 3.10 이상
번들 내 리소스 제공
번들은 두 가지 리소스 유형을 통해 기능 뷰를 제공합니다:
-
FeatureSpec: 제공할 기능을 나열하는 Unity 카탈로그 함수입니다. 특징 값은 갖지 않습니다. 이를 제공하는 엔드포인트는 Feature View가 물리화된 온라인 테이블에서 해당 데이터를 읽습니다.FeatureSpec로 기능 제공하기를 참조하고, 구성 참조는 feature_spec입니다. -
기능 서빙 엔드포인트: 모델 대신 기능
FeatureSpec을 제공하는 모델 엔드포인트입니다. 번들은 이를model_serving_endpoints리소스로 선언합니다. 구성 참조는 model_serving_endpoint을 참조하세요.
번들에서 Feature Views 제공하기
다음 단계에서는 번들을 빌드 및 배포하고, 엔드포인트를 쿼리하며, 제공하는 내용을 변경하고, 정리합니다.
인증 설정
먼저, 개발 머신의 Databricks CLI와 Azure Databricks 작업 공간 간의 인증을 설정하세요. 이 페이지에서는 OAuth U2M(사용자-컴퓨터) 인증 및 인증을 위해 명명된 DEFAULT 해당 Azure Databricks 구성 프로필을 사용하려는 것으로 가정합니다.
Note
U2M 인증은 이러한 단계를 실시간으로 시도하는 데 적합합니다. 완전히 자동화된 워크플로의 경우 Databricks는 OAuth M2M(컴퓨터 간) 인증을 대신 사용하는 것이 좋습니다. OAuth를 사용하여 Azure Databricks에 대한 서비스 주체 액세스 권한 부여의 M2M 인증 설정 지침을 참조하세요.
Databricks CLI를 사용하여 각 대상 작업 영역에 대해 다음 명령을 실행하여 OAuth 토큰 관리를 로컬로 시작합니다.
다음 명령에서
<workspace-url>를 Azure Databricks 작업공간별 URL로 바꾸십시오. 예를 들면 다음과 같습니다https://adb-1234567890123456.7.azuredatabricks.net.databricks auth login --host <workspace-url>Databricks CLI는 Azure Databricks 구성 프로필로 입력한 정보를 저장하라는 메시지를 표시합니다.
Enter를 눌러 제안된 프로필 이름을 수락하거나 새 프로필 또는 기존 프로필의 이름을 입력합니다. 이름이 같은 기존 프로필은 입력한 정보로 덮어쓰여집니다. 프로필을 사용하여 여러 작업 영역에서 인증 컨텍스트를 빠르게 전환할 수 있습니다.기존 프로필 목록을 얻으려면 별도의 터미널 또는 명령 프롬프트에서 Databricks CLI를 사용하여
databricks auth profiles명령을 실행합니다. 특정 프로필의 기존 설정을 보려면 명령을databricks auth env --profile <profile-name>실행합니다.웹 브라우저에서 화면상의 지침을 완료하여 Azure Databricks 작업 영역에 로그인합니다.
프로필의 현재 OAuth 토큰 값과 토큰의 예정된 만료 타임스탬프를 보려면 다음 명령 중 하나를 실행합니다.
databricks auth token --host <workspace-url>databricks auth token -p <profile-name>databricks auth token --host <workspace-url> -p <profile-name>
동일한
--host값을 가진 프로필이 여러 개 있는 경우, Databricks CLI가 올바르게 일치하는 OAuth 토큰 정보를 찾을 수 있도록--host및-p옵션을 함께 지정해야 할 수 있습니다.
번들 만들기
번들을 위한 빈 디렉터리를 만들고, 루트에 databricks.yml 파일을 두고 그 옆에 resources 디렉터리를 둡니다.
YAML
다음 각 단계는 resources/ 아래에 파일을 하나씩 추가합니다:
databricks.yml
resources/
streaming_features.yml
feature_spec.yml
serving_endpoint.yml
databricks.yml에는 번들 이름, resources/ 아래의 모든 파일을 로드하는 include 항목, 그리고 리소스가 참조하는 변수들이 들어 있습니다:
bundle:
name: feature-serving-quickstart
include:
- resources/*.yml
variables:
catalog:
description: The catalog that the Feature Views and the FeatureSpec are written to.
default: main
schema:
description: The schema that the Feature Views and the FeatureSpec are written to.
default: features_demo
stream:
description: The three-level name of a Stream registered in Unity Catalog.
default: main.features_demo.events
online_store:
description: The online store that serves the features.
default: my_online_store
endpoint_name:
description: The name of the Feature Serving endpoint.
default: event-features
Python
Python으로 선언된 리소스는 databricks.yml의 python 매핑을 통해서만 찾을 수 있습니다. 이것이 없으면 번들은 검증 및 배포에 성공하지만 리소스는 포함하지 않으므로 지금 추가하세요:
bundle:
name: feature-serving-quickstart
python:
venv_path: .venv
resources:
- 'resources:load_resources'
variables:
catalog:
description: The catalog that the Feature Views and the FeatureSpec are written to.
default: main
schema:
description: The schema that the Feature Views and the FeatureSpec are written to.
default: features_demo
stream:
description: The three-level name of a Stream registered in Unity Catalog.
default: main.features_demo.events
online_store:
description: The online store that serves the features.
default: my_online_store
endpoint_name:
description: The name of the Feature Serving endpoint.
default: event-features
프로젝트와 가상 환경을 생성하고, 패키지를 추가합니다:
uv init --bare
uv venv .venv
uv add databricks-bundles
resources/__init__.py에서 이름을 지정한 함수를 사용해 databricks.yml을(를) 생성하세요:
from databricks.bundles.core import Bundle, Resources
def load_resources(bundle: Bundle) -> Resources:
resources = Resources()
# The following steps add resources here.
return resources
기능 뷰와 그 구체화를 선언하세요
두 기능 뷰는 동일한 스트림을 읽고 키별로 최근 90분간 집계합니다.
events_90m이벤트를 세고, amount_sum_90m이 value.amount를 합산합니다. 하나의 물질화 세트가 스트리밍 모드로 온라인 스토어에 두 가지를 모두 쓰는 역할을 합니다. 각 구성 키가 의미하는 바에 대해서는 기능 보기 튜토리얼의 4단계를 참조하세요.
스트리밍 기능 보기는 입력 열을 스트림 레코드 내부의 경로로 참조하므로, 예시에서 value.*가 표시된 곳마다 스트림 스키마가 사용하는 이름으로 대체하세요.
YAML
resources/streaming_features.yml을 만듭니다.
resources:
features:
events_90m:
full_name: ${var.catalog}.${var.schema}.events_90m
description: Events per key over a trailing 90 minutes
source:
stream_source:
full_name: ${var.stream}
function:
aggregation_function:
count_function:
input: value.amount
time_window:
rolling:
window_duration: 5400s
entities:
- name: value.key
timeseries_column:
name: value.event_timestamp
amount_sum_90m:
full_name: ${var.catalog}.${var.schema}.amount_sum_90m
description: Sum of amount per key over a trailing 90 minutes
source:
stream_source:
full_name: ${var.stream}
function:
aggregation_function:
sum:
input: value.amount
time_window:
rolling:
window_duration: 5400s
entities:
- name: value.key
timeseries_column:
name: value.event_timestamp
materialization_sets:
serving_online:
materialized_features:
- feature_name: ${resources.features.events_90m.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: serving_online
streaming_mode:
mode: STREAMING_MODE_TYPE_RTM
- feature_name: ${resources.features.amount_sum_90m.full_name}
online_store_config:
online_store_name: ${var.online_store}
catalog_name: ${var.catalog}
schema_name: ${var.schema}
table_name_prefix: serving_online
streaming_mode:
mode: STREAMING_MODE_TYPE_RTM
Python
resources/__init__.py에 가져오기를 추가합니다:
from databricks.bundles.features import (
AggregationFunction,
CountFunction,
DataSource,
EntityColumn,
Feature,
Function,
RollingWindow,
StreamSource,
SumFunction,
TimeseriesColumn,
TimeWindow,
)
from databricks.bundles.materialization_sets import (
MaterializationSet,
MaterializedFeature,
OnlineStoreConfig,
StreamingMode,
StreamingModeStreamingModeType,
)
그런 다음 load_resources의 본문에 다음을 추가합니다:
resources.add_feature(
'events_90m',
Feature(
full_name='${var.catalog}.${var.schema}.events_90m',
description='Events per key over a trailing 90 minutes',
source=DataSource(stream_source=StreamSource(full_name='${var.stream}')),
function=Function(
aggregation_function=AggregationFunction(
count_function=CountFunction(input='value.amount'),
time_window=TimeWindow(rolling=RollingWindow(window_duration='5400s')),
)
),
entities=[EntityColumn(name='value.key')],
timeseries_column=TimeseriesColumn(name='value.event_timestamp'),
),
)
resources.add_feature(
'amount_sum_90m',
Feature(
full_name='${var.catalog}.${var.schema}.amount_sum_90m',
description='Sum of amount per key over a trailing 90 minutes',
source=DataSource(stream_source=StreamSource(full_name='${var.stream}')),
function=Function(
aggregation_function=AggregationFunction(
sum=SumFunction(input='value.amount'),
time_window=TimeWindow(rolling=RollingWindow(window_duration='5400s')),
)
),
entities=[EntityColumn(name='value.key')],
timeseries_column=TimeseriesColumn(name='value.event_timestamp'),
),
)
resources.add_materialization_set(
'serving_online',
MaterializationSet(
materialized_features=[
MaterializedFeature(
feature_name='${resources.features.events_90m.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='serving_online',
),
streaming_mode=StreamingMode(
mode=StreamingModeStreamingModeType.STREAMING_MODE_TYPE_RTM
),
),
MaterializedFeature(
feature_name='${resources.features.amount_sum_90m.full_name}',
online_store_config=OnlineStoreConfig(
online_store_name='${var.online_store}',
catalog_name='${var.catalog}',
schema_name='${var.schema}',
table_name_prefix='serving_online',
),
streaming_mode=StreamingMode(
mode=StreamingModeStreamingModeType.STREAMING_MODE_TYPE_RTM
),
),
]
),
)
FeatureSpec 추가
FeatureSpec에는 엔드포인트가 제공하는 기능이 나열됩니다. 각 항목은 features에서 declarative_feature이 있는 하나의 기능 보기를 명시합니다.
A FeatureSpec 는 각 피처 뷰가 온라인 스토어에 구현된 후에만 생성할 수 있습니다.
${resources.features...}의 참조 declarative_feature는 명세가 피처 뷰 events_90m와 amount_sum_90m에 의존하게 하며, lifecycle.depends_on가 어떤 참조도 표현하지 않는 의존성을 물질화 집합 serving_online에 추가합니다. 번들은 세 가지 모두가 끝난 후 스펙을 생성하고 그들보다 먼저 삭제합니다.
FeatureSpec이 충족해야 하는 규칙을 참조하세요.
YAML
resources/feature_spec.yml을 만듭니다.
resources:
feature_specs:
event_features:
name: ${var.catalog}.${var.schema}.event_features
features:
- declarative_feature:
feature: ${resources.features.events_90m.full_name}
- declarative_feature:
feature: ${resources.features.amount_sum_90m.full_name}
lifecycle:
depends_on:
- resource: materialization_sets.serving_online
Python
resources/__init__.py에 가져오기를 추가합니다:
from databricks.bundles.feature_specs import (
DeclarativeFeature,
DependsOn,
FeatureSpec,
Features,
Lifecycle,
)
그런 다음 load_resources의 본문에 다음을 추가합니다:
resources.add_feature_spec(
'event_features',
FeatureSpec(
name='${var.catalog}.${var.schema}.event_features',
features=[
Features(
declarative_feature=DeclarativeFeature(
feature='${resources.features.events_90m.full_name}'
)
),
Features(
declarative_feature=DeclarativeFeature(
feature='${resources.features.amount_sum_90m.full_name}'
)
),
],
lifecycle=Lifecycle(depends_on=[DependsOn(resource='materialization_sets.serving_online')]),
),
)
기능 제공 엔드포인트 추가
엔드포인트는 FeatureSpec에서 지정한 entity_name를 제공합니다.
name가 명세의 entity_name를 참조하므로, 번들은 Deploy의 출력에서 보듯이 명세 다음에 엔드포인트를 생성하고 명세 전에 엔드포인트를 삭제합니다. scale_to_zero_enabled를 사용하면 엔드포인트는 요청을 받지 않을 때 컴퓨팅 리소스를 0으로 줄입니다.
YAML
resources/serving_endpoint.yml을 만듭니다.
resources:
model_serving_endpoints:
event_endpoint:
name: ${var.endpoint_name}
config:
served_entities:
- entity_name: ${resources.feature_specs.event_features.name}
workload_size: Small
scale_to_zero_enabled: true
Python
resources/__init__.py에 가져오기를 추가합니다:
from databricks.bundles.model_serving_endpoints import (
EndpointCoreConfigInput,
ModelServingEndpoint,
ServedEntityInput,
)
그런 다음 load_resources의 본문에 다음을 추가합니다:
resources.add_model_serving_endpoint(
'event_endpoint',
ModelServingEndpoint(
name='${var.endpoint_name}',
config=EndpointCoreConfigInput(
served_entities=[
ServedEntityInput(
entity_name='${resources.feature_specs.event_features.name}',
workload_size='Small',
scale_to_zero_enabled=True,
)
]
),
),
)
Deploy
구성을 확인한 후 배포가 수행하는 작업을 검토하십시오:
databricks bundle validate
databricks bundle plan
첫 배치 시 다섯 자원 모두 다음을 보고합니다 create:
create feature_specs.event_features
create features.amount_sum_90m
create features.events_90m
create materialization_sets.serving_online
create model_serving_endpoints.event_endpoint
Plan: 5 to add, 0 to change, 0 to delete, 0 unchanged
작업 공간에 번들을 배포하세요.
databricks bundle deploy
배포는 의존성 순서대로 리소스를 생성하고 엔드포인트가 준비되면 반환하며, 이 과정에는 몇 분이 소요됩니다:
Uploading bundle files to /Workspace/Users/someone@example.com/.bundle/feature-serving-quickstart/default/files...
Created features.events_90m
Created features.amount_sum_90m
Created materialization_sets.serving_online
Created feature_specs.event_features
Created model_serving_endpoints.event_endpoint
Files: 4 uploaded, 0 deleted
Resources: 5 created, 0 changed, 0 deleted, 0 unchanged
엔드포인트 쿼리
조회할 키를 dataframe_records로 보내세요. 레코드는 각 키를 피처 뷰의 엔티티 경로의 마지막 구간으로 지정하므로, value.key는 key가 됩니다:
databricks serving-endpoints query event-features --json '{"dataframe_records": [{"key": 1280}, {"key": 1188}, {"key": 42}, {"key": 10001}]}'
응답은 요청 순서대로 각 레코드마다 하나의 객체를 보유합니다. 각 객체는 각 기능 뷰에 대해 하나의 값을 가지며, 이는 카탈로그와 스키마를 제외한 기능 뷰 이름을 키로 하여 지정됩니다:
{
"outputs": [
{
"events_90m": 10,
"amount_sum_90m": 10
},
{
"events_90m": 11,
"amount_sum_90m": 11
},
{
"events_90m": 9,
"amount_sum_90m": 10
},
{
"events_90m": 0,
"amount_sum_90m": null
}
]
}
창에 이벤트가 없는 키는 키 0와 마찬가지로 카운트에 대해 10001를, 합계에 대해 null를 반환합니다. 각 키는 머티리얼라이제이션 파이프라인이 첫 번째 행을 쓸 때까지 이러한 값을 반환하며, 이는 databricks bundle deploy가 반환된 후 몇 분이 지난 뒤일 수 있습니다. 엔드포인트를 쿼리하는 다른 방법은 엔드포인트 쿼리하기를 참조하세요.
FeatureSpec에서 피처 뷰 제거
FeatureSpec에 변경이 있으면 삭제되고 다시 생성됩니다. 실행 중인 엔드포인트는 빌드에 사용된 FeatureSpec에 있던 기능을 계속 제공하므로, spec의 이름을 유지하는 변경은 엔드포인트에 영향을 주지 않습니다.
라이브 기능 제공 엔드포인트의 종속성 업데이트 문서를 참조하세요.
이를 확인하려면 사양에서 amount_sum_90m를 제거하고 이름을 유지하세요:
YAML
feature_specs:
event_features:
name: ${var.catalog}.${var.schema}.event_features
features:
- declarative_feature:
feature: ${resources.features.events_90m.full_name}
- - declarative_feature:
- feature: ${resources.features.amount_sum_90m.full_name}
lifecycle:
Python
features=[
Features(
declarative_feature=DeclarativeFeature(
feature='${resources.features.events_90m.full_name}'
)
),
- Features(
- declarative_feature=DeclarativeFeature(
- feature='${resources.features.amount_sum_90m.full_name}'
- )
- ),
],
databricks bundle plan 사양을 다시 생성한다는 사실만 보고합니다:
recreate feature_specs.event_features
Plan: 1 to add, 0 to change, 1 to delete, 4 unchanged
databricks bundle deploy 사양을 다시 생성하기 전에 확인 메시지를 표시합니다:
Uploading bundle files to /Workspace/Users/someone@example.com/.bundle/feature-serving-quickstart/default/files...
This action will result in the deletion or recreation of the following feature specs.
Grants on them that are not declared in the bundle are lost:
recreate resources.feature_specs.event_features
Would you like to proceed? [y/N]: y
Recreated feature_specs.event_features
Files: 1 uploaded, 0 deleted
Resources: 1 created, 0 changed, 1 deleted, 4 unchanged
엔드포인트는 여전히 두 가지 기능을 모두 반환합니다:
databricks serving-endpoints query event-features --json '{"dataframe_records": [{"key": 1188}, {"key": 42}]}'
{
"outputs": [
{
"events_90m": 16,
"amount_sum_90m": 20
},
{
"events_90m": 12,
"amount_sum_90m": 11
}
]
}
FeatureSpec 이름 변경
엔드포인트가 제공하는 내용을 변경하려면 FeatureSpec에 새 이름을 지정하세요. 엔드포인트는 entity_name 이름을 참조하므로 배포가 엔드포인트도 업데이트하고, 엔드포인트는 업데이트가 완료될 때까지 원래 FeatureSpec 의 기능으로 요청에 계속 응답합니다.
YAML
feature_specs:
event_features:
- name: ${var.catalog}.${var.schema}.event_features
+ name: ${var.catalog}.${var.schema}.event_features_v2
Python
FeatureSpec(
- name='${var.catalog}.${var.schema}.event_features',
+ name='${var.catalog}.${var.schema}.event_features_v2',
databricks bundle plan 사양 재생성과 엔드포인트 업데이트를 보고합니다:
recreate feature_specs.event_features
update model_serving_endpoints.event_endpoint
Plan: 1 to add, 1 to change, 1 to delete, 3 unchanged
databricks bundle deploy 확인을 요청하고, 사양을 다시 생성하며, 엔드포인트가 업데이트되면 다음을 반환합니다:
Uploading bundle files to /Workspace/Users/someone@example.com/.bundle/feature-serving-quickstart/default/files...
This action will result in the deletion or recreation of the following feature specs.
Grants on them that are not declared in the bundle are lost:
recreate resources.feature_specs.event_features
Would you like to proceed? [y/N]: y
Recreated feature_specs.event_features
Updated model_serving_endpoints.event_endpoint
Files: 1 uploaded, 0 deleted
Resources: 1 created, 1 changed, 1 deleted, 3 unchanged
이제 엔드포인트는 events_90m만 반환합니다:
databricks serving-endpoints query event-features --json '{"dataframe_records": [{"key": 1188}]}'
{
"outputs": [
{
"events_90m": 68
}
]
}
정리 작업
마티리얼라이제이션 파이프라인은 계속 실행되고 엔드포인트는 삭제할 때까지 계속 서비스를 제공합니다. 다 끝나면 번들을 해제하세요:
databricks bundle destroy
databricks bundle destroy 삭제하는 내용을 나열하고 확인을 요청합니다:
The following resources will be deleted:
delete resources.feature_specs.event_features
delete resources.features.amount_sum_90m
delete resources.features.events_90m
delete resources.materialization_sets.serving_online
delete resources.model_serving_endpoints.event_endpoint
This action will result in the deletion of the following Feature Views.
Deleting a Feature View that a FeatureSpec serves is not blocked, and leaves the FeatureSpec stale:
delete resources.features.amount_sum_90m
delete resources.features.events_90m
This action will result in the deletion of the following feature specs.
Feature Serving endpoints and training code that use them can no longer load them:
delete resources.feature_specs.event_features
All files and directories at the following location will be deleted: /Workspace/Users/someone@example.com/.bundle/feature-serving-quickstart/default
Would you like to proceed? [y/N]: y
Destroy: 5 deleted
구체화된 기능을 생성한 사용자만 삭제할 수 있으므로, 번들을 배포한 동일한 ID로 databricks bundle destroy를 실행하십시오.
delete_materialized_feature()을(를) 참조하세요.
Limitations
- Feature View가 배치 모드로 구체화될 때, 해당 온라인 테이블은 구체화 세트의 첫 실행 이후에만 존재하므로, 같은
databricks bundle deploy모드에 배포된 엔드포인트는 실패합니다. 첫 번째 실행 후에databricks bundle deploy를 다시 실행하세요. -
FeatureSpec가 제공하는 Feature View를 삭제하는 것은 차단되지 않으며, 그 결과FeatureSpec는 오래된 상태로 남습니다.
다음 단계
- 전체 구성 참조는 feature_spec 및 model_serving_endpoint를 참조하십시오.
- 엔드포인트가 제공하는 기능에 다른 주체에게 접근 권한을 부여하려면 권한(Permissions)을 참조하세요.
- Feature Serving 엔드포인트를 모니터링, 업데이트 및 삭제하려면 Feature 테이블 제공을 참조하세요.
- 피처 뷰와 해당 머티리얼라이제이션을 변경하려면 선언적 자동화 번들을 사용하여 피처 뷰 관리하기를 참조하세요.