From d7f32fd9cbd9325acc1b9ce577ae600cd41fbc97 Mon Sep 17 00:00:00 2001 From: Haystack Bot <73523382+HaystackBot@users.noreply.github.com> Date: Thu, 18 Dec 2025 11:04:01 +0100 Subject: [PATCH] Sync Haystack API reference on Docusaurus (#10266) Co-authored-by: vblagoje <458335+vblagoje@users.noreply.github.com> --- .../reference/haystack-api/routers_api.md | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/docs-website/reference/haystack-api/routers_api.md b/docs-website/reference/haystack-api/routers_api.md index 0542c46e5..7ca3b101c 100644 --- a/docs-website/reference/haystack-api/routers_api.md +++ b/docs-website/reference/haystack-api/routers_api.md @@ -79,26 +79,30 @@ from haystack.dataclasses import ByteStream from haystack.components.routers import ConditionalRouter routes = [ - { - "condition": "{{streams|length > 2}}", - "output": "{{streams}}", - "output_name": "enough_streams", - "output_type": list[ByteStream], + {"condition": "{{count > 5}}", + "output": "Processing many items", + "output_name": "many_items", + "output_type": str, }, - { - "condition": "{{streams|length <= 2}}", - "output": "{{streams}}", - "output_name": "insufficient_streams", - "output_type": list[ByteStream], + {"condition": "{{count <= 5}}", + "output": "Processing few items", + "output_name": "few_items", + "output_type": str, }, ] pipe = Pipeline() -pipe.add_component("router", router) -... -pipe.connect("router.enough_streams", "some_component_a.streams") -pipe.connect("router.insufficient_streams", "some_component_b.streams_or_some_other_input") -... +pipe.add_component("router", ConditionalRouter(routes)) + +# Run with count > 5 +result = pipe.run({"router": {"count": 10}}) +print(result) +# >> {'router': {'many_items': 'Processing many items'}} + +# Run with count <= 5 +result = pipe.run({"router": {"count": 3}}) +print(result) +# >> {'router': {'few_items': 'Processing few items'}} ```