A data scientist wants to define a lightweight Python function component in Vertex AI Pipelines using Kubeflow Pipelines SDK v2. Which decorator should be applied to the function to make it a pipeline component?
The @dsl.component decorator converts a plain Python function into a lightweight KFP v2 component, with the function's signature defining its inputs and outputs. This is the specific mechanism the stem requests for authoring a Python function component in Kubeflow Pipelines SDK v2.
Why this answer
In Kubeflow Pipelines SDK v2, the @dsl.component decorator converts a lightweight Python function into a pipeline component. This is the standard v2 approach for defining function-based components. @dsl.pipeline is used to define the pipeline itself, not individual components.
Exam trap
PMLE often tests the distinction between @dsl.component (defines a component) and @dsl.pipeline (defines the pipeline), and includes legacy v1 decorators like func_to_component to confuse candidates about SDK v2 syntax.
How to eliminate wrong answers
Option A is wrong because @dsl.pipeline decorates the pipeline function that orchestrates components, not the component function itself. Option B is wrong because @kfp.v2.components.func_to_component is the older v1-style API for converting functions to components; in SDK v2 the canonical decorator is @dsl.component. Option D is wrong because @kfp.dsl.component is not the correct v2 decorator syntax; the v2 SDK uses @dsl.component from the kfp.dsl module.