Foresight.Evals.Labeling.PoolFusion (Foresight v0.1.0)

Copy Markdown View Source

Re-rank a recorded candidate pool under a trial fusion configuration, offline.

This is what makes D2's coordinate-ascent affordable: scoring a candidate weighting costs a pure re-fusion of an already-recorded pool instead of a live recall run over the corpus.

It deliberately calls Foresight.Recall.RRF.fuse/2 — the real fuser — rather than reimplementing the scoring. A reimplementation would be free to drift from production, and a tuner that optimises against a drifted model of the system produces weights that do not transfer. The only work here is reconstructing the strategy_results shape the fuser expects from what the pool recorded.

RANK FIDELITY. RRF.fuse/2 derives each arm's rank from list position via Enum.with_index/2, but a recorded pool is not dense: candidates are dropped when they lack a stable eval_id, and per_query_cap truncates. Handing it a compacted list would silently promote candidates — a candidate recorded at rank 9 would score as if it ranked

  1. So gaps are filled with placeholder entries that occupy the missing positions and are discarded from the result.

Summary

Functions

Rank one query pool's candidates under fusion_opts.

Rebuild the arm => ranked items map the live fuser consumes.

Functions

rank(query_pool, fusion_opts \\ [])

@spec rank(
  map(),
  keyword()
) :: [String.t()]

Rank one query pool's candidates under fusion_opts.

Returns memory_refs, most relevant first. fusion_opts is whatever Foresight.Recall.FusionConfig.resolve/2 produces.

strategy_results(query_pool)

@spec strategy_results(map()) :: %{required(String.t()) => [map()]}

Rebuild the arm => ranked items map the live fuser consumes.

Exposed so a test can assert the reconstruction itself, independently of ranking.