# co_occurrence_score: the keyword scorer from Article 7, in the companion notebook. def route_question(line_df, primary, secondary, *, min_score=4, min_margin=3): """Decide, with no model call, whether the keyword path already answers.""" scores = [co_occurrence_score(t, primary, secondary) for t in line_df["text"]] top, second = sorted(scores, reverse=True)[:2] # The signal is the retrieval brick's own output: a high top score with a # clear margin means one line answered; a flat score means it did not. confident = top >= min_score and (top - second) >= min_margin # "fast" skips the model. "full" runs the arbiter and generation. return "fast" if confident else "full"