Skip to content

Commit

Permalink
document 2 ways to invoke pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Jan 16, 2025
1 parent 20a9efa commit 709ea7d
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions docs/guide/pipeline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ The convenience methods are equivalent to the following pipeline code:
# allow candidate items to be optionally specified
items = pipe.create_input('items', ItemList, None)
# look up a user's history in the training data
history = pipe.add_component('history-lookup', LookupTrainingHistory(), query=query)
history = pipe.add_component('history-lookup', LookupTrainingHistory, query=query)
# find candidates from the training data
default_candidates = pipe.add_component(
'candidate-selector',
UnratedTrainingItemsCandidateSelector(),
UnratedTrainingItemsCandidateSelector,
query=history,
)
# if the client provided items as a pipeline input, use those; otherwise
Expand All @@ -339,7 +339,7 @@ The convenience methods are equivalent to the following pipeline code:
# score the candidate items using the specified scorer
score = pipe.add_component('scorer', scorer, query=query, items=candidates)
# rank the items by score
recommend = pipe.add_component('ranker', TopNRanker(50), items=score)
recommend = pipe.add_component('ranker', TopNRanker, {'n': 50}, items=score)
pipe.alias('recommender', recommend)
pipe.default_component('recommender')
pipe = pipe.build()
Expand Down Expand Up @@ -464,6 +464,32 @@ Finally, you can directly pass configuration parameters to the component constru

See :ref:`conventions` for more conventions for component design.

Adding Components to the Pipeline
---------------------------------

You can add components to the pipeline in two ways:

* Instantiate the component with its configuration options and pass it to
:meth:`PipelineBuilder.add_component`::

builder.add_component('component-name', MyComponent(option='value'))

When you convert the pipeline into
a configuration or clone it, the component will be re-instantiated from its
configuration.

* Pass the component class and configuration separately to
:meth:`PipelineBuilder.add_component`::

builder.add_component('component-name', MyComponent, MyConfig(option='value'))

Alternatively::

builder.add_component('component-name', MyComponent, {'option': 'value'}))

When you use the second approach, :meth:`PipelineBuilder.build` instantiates the
component from the provided configuration.

POPROX and Other Integrators
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 709ea7d

Please sign in to comment.