haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Lazy Run/Evaluation of components based on downstream necessity

Open bglearning opened this issue 1 year ago • 2 comments

Came up in #6836

Wondering if there is a way to setup a component to only run if there is a downstream component needing its output.

E.g. Possible usage: the FilterRetriever (which simply runs a preset filter on a document-store) is in one of many optional branches. And we would only want to run it if the branch is followed (e.g. for a certain type of query). I guess this can be generalized to any "inputless" component.

One such setup could be:

filter_branch

Here we'd want the FilterRetriever to run only when necessary (LookupReader needs its output).

Describe alternatives you've considered

  • Could set up the component (here FilterRetriever) to take some "trigger" input.
  • Or just ignore components being run unnecessarily.

bglearning avatar Jan 29 '24 13:01 bglearning

@bglearning can you try to run this code with the main branch? The new run algorithm should behave like you expect.

masci avatar Feb 05 '24 08:02 masci

@masci Seems like it still runs the unnecessary component (here FilterRetriever for the SemanticReader branch).

Setup on Colab

afaict, components with no inputs are immediately added into to_run in the run algorithm.

bglearning avatar Feb 08 '24 15:02 bglearning