-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Conditional Routing in Haystack 2.x Pipelines #6109
Comments
Another use case where I needed such a |
This looks great and the code example really helped me understanding what we want to achieve here. I have two concerns with the solution, let me illustrate them.
components:
converter:
type: HTMLToDocument
fetcher:
init_parameters:
raise_on_failure: true
retry_attempts: 2
timeout: 3
user_agents:
- haystack/LinkContentFetcher/1.22.0rc0
type: LinkContentFetcher
router:
type: ConnectionRouter
# how do I express "register"?
connections:
- receiver: router.input
sender: fetcher.streams One alternative solution might be leveraging the new filters (see the proposal) so that we can express conditions in text format instead of Python code: ## Before:
# router = ConnectionRouter()
# router.register(lambda streams: len(streams) < 2, query_rewriter)
# router.register(lambda streams: len(streams) >= 2, converter)
# After
routes = {
query_rewriter: { "input": "streams", "operator": "<", "value": "2" },
converter: { "input": "streams", "operator": ">=", "value": "2" },
}
router = ConnectionRouter(routes=routes)
# ... rest stays the same which would be easy to express in Yaml: router:
type: ConnectionRouter
init_parameters:
routes:
query_rewriter: { "input": "streams", "operator": "<", "value": "2" }
converter: { "input": "streams", "operator": ">=", "value": "2" }
# ...
|
@masci I like in general the idea of using filters, but I'm not sure they're expressive enough. One may want to route objects (think |
I'm also a bit perplexed by the fact that in the examples, def register(self, input_name: str, input_type: Type, function: Callable, output_name: str, output_type: Type): while right now seems to be: def register(self, function: Callable, component_to_connect_to: Component): which I think Canals wouldn't support right now. |
True, still |
Description:
In the current state of Haystack 2.x pipelines, we can create pipelines by connecting output slots to input slots:
However, there isn't direct support for conditional routing based on user-specified boolean conditions. For example, when
LinkContentFetcher
returns too few streams (i.e. perhaps it got blocked) we want to make decisions based on the number of streams received. If we receive too few streams, we might want to reformulate the query in someQueryRewriter
component, and then rerun it viaLinkContentFetcher
etc etc.Describe the solution you'd like:
Introduce a well-known Haystack component, possibly named
ConnectionRouter
(or a similar fitting name), which supports registration of boolean expressions as keys and component input slots as values:By utilizing such a component, users will have the flexibility to implement custom branching logic in their pipelines based on the component result object boolean expressions and not only on output slots.
Describe alternatives you've considered
The alternative seems to be creating a custom component for each branching scenario (use case)
Additional context
Having such a generic
ConnectionRouter
would offer immediate benefits:The text was updated successfully, but these errors were encountered: