haystack
haystack copied to clipboard
Add custom filter support to ConditionalRouter component
Is your feature request related to a problem? Please describe.*
Currently, the ConditionalRouter
component doesn't support custom filters in the 'condition' and 'output' fields of a route. This limitation restricts users from applying complex logic or data transformations within these fields, forcing them to pre-process data before it reaches the router or to create additional components for simple transformations. This can lead to less efficient pipelines and reduced flexibility in routing logic.
Describe the solution you'd like
We propose adding support for custom filters in the ConditionalRouter
, similar to how they are implemented in the OutputAdapter
component. Specifically:
- Add a 'custom_filters' parameter to the ConditionalRouter's init method, accepting a dictionary of custom filter functions.
- Allow these custom filters to be used in both the 'condition' and 'output' fields of each route.
- Implement the necessary logic to apply these filters during the evaluation of conditions and generation of outputs.
This would allow users to write more expressive and powerful routing logic directly within the ConditionalRouter, enhancing its capabilities and flexibility.
Describe alternatives you've considered
- Pre-processing data: Users could transform data before it reaches the
ConditionalRouter
, but this can be cumbersome and less efficient for complex pipelines. - Additional components: Creating separate components for data transformation before routing, which can make pipelines more complex and harder to manage.
Additional context
This feature would align the ConditionalRouter
more closely with the OutputAdapter
in terms of functionality, providing a consistent experience across Haystack components. It would be particularly useful for scenarios involving complex data transformations or when integrating external libraries for specific computations within the routing logic.