def _intermediate_reward(self, step: int) -> float:
    """Computes an 'intermediate' reward after each step.

    r_t = S(d_t | q) - S(d_t-1 | q).
    Intermediate rewards (which  make up the bulk of our reward scheme) get
    computed after each step and, usually, quantify the "goodness" of local
    change.  For example, the improvement (or decrease) in a metric such as
    answer F1, relevant document recall, ... between the previous step and
    the current step.

    Args:
      step:  The step for which we want to compute the intermediate reward.

    Returns:
      The intermediate reward, as defined by the configuration.
    """

    assert step >= 2, (f'Intermediate reward computation requires at least 2 '
                       f'history entries. Requested was "{step}".')
    current_documents_list = self._get_current_documents_list(step)
    previous_documents_list = self._get_previous_documents_list(step)

    if common_flags.REWARD.value == 'curiosity+dcg':
      curiosity = len(
          set([d.content for d in current_documents_list]) -
          set([d.content for d in previous_documents_list])) / float(
              common_flags.NUM_DOCUMENTS_TO_RETRIEVE.value)
      dcg_current = self.state.score(
          identifier='dcg',
          documents_list=current_documents_list,
          k=common_flags.K.value)
      dcg_previous = self.state.score(
          identifier='dcg',
          documents_list=previous_documents_list,
          k=common_flags.K.value)
      ideal_dcg = utils.dcg_score(relevances=[1.] * common_flags.K.value)
      ndcg_improvement = (dcg_current - dcg_previous) / ideal_dcg
      return common_flags.REWARD_INTERPOLATION_VALUE.value * curiosity + (
          1 -
          common_flags.REWARD_INTERPOLATION_VALUE.value) * ndcg_improvement

    else:
      reward = common_flags.REWARD.value
      raise NotImplementedError(
          f'Intermediate episode reward for type {reward} is not implemented.')
Computes an 'intermediate' reward after each step.

    r_t = S(d_t | q) - S(d_t-1 | q).
    Intermediate rewards (which  make up the bulk of our reward scheme) get
    computed after each step and, usually, quantify the "goodness" of local
    change.  For example, the improvement (or decrease) in a metric such as
    answer F1, relevant document recall, ... between the previous step and
    the current step.

    Args:
      step:  The step for which we want to compute the intermediate reward.

    Returns:
      The intermediate reward, as defined by the configuration.
    
language/search_agents/muzero/env.py