HaystackHaystack 3.1 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
19 small wins to finish your pathNext lesson

SuperComponents: a pipeline as one component

SuperComponent wraps a whole pipeline with simple input and output names, so it can be used like a single component, tested alone, or placed inside another pipeline.

Example
policy_qa = SuperComponent(
    pipeline=rag,
    input_mapping={"question": ["retriever.query", "prompt.question", "answer.query"]},
    output_mapping={"answer.answers": "answers"},
)
result = policy_qa.run(question="Can I return a damaged item?")
print(result["answers"][0].data)

input_mapping sends one input, question, to the three sockets that needed it, so callers no longer pass the question three times. output_mapping exposes only answers. The pipeline inside is unchanged.

Example
outer = Pipeline()
outer.add_component("policy_qa", policy_qa)
print(outer.inputs())
print(outer.outputs())

Inside another pipeline, its sockets are the mapped names: one mandatory question in, answers out. Other components can connect to policy_qa.question, and ComponentTool can turn it into a tool for the agent from lesson 13.

Try it yourself
  • Map retriever.documents to an output named sources.
  • Add policy_qa to a pipeline after the router from lesson 4.
  • Wrap the indexing pipeline from lesson 6 with an input named files.

Little by little, you're building something great.