Imp.Predict.MultiChainComparison (Imp v0.5.0)

Copy Markdown View Source

Compare several candidate completions and ask a predictor for the final output.

MultiChainComparison is a composition primitive for self-consistency style workflows. You generate m candidate predictions elsewhere, pass them under :completions or "completions", and this module builds a comparison prompt with one :reasoning_attempt_N input per candidate.

Completions may be maps with atom or string keys, or %Imp.Prediction{} values. Imp reads :rationale/:reasoning plus the signature's final output field and sends those attempt summaries to the wrapped predictor.

Example

iex> lm = Imp.LM.Static.new(handler: fn _messages, _opts -> %{rationale: "two attempts agree", answer: "Paris"} end)
iex> program = Imp.Predict.MultiChainComparison.new("question -> answer", lm: lm, m: 2)
iex> {:ok, prediction} =
...>   Imp.Predict.MultiChainComparison.call(program, %{
...>     "question" => "Capital of France?",
...>     "completions" => [
...>       %{"reasoning" => "geography", "answer" => "Paris"},
...>       Imp.Prediction.new(reasoning: "landmark clue", answer: "Paris")
...>     ]
...>   })
iex> Imp.Prediction.get(prediction, :answer)
"Paris"

Summary

Functions

Runs the comparison over a map or keyword list containing completions.

Builds a multi-chain comparison program.

Functions

call(mcc, inputs)

Runs the comparison over a map or keyword list containing completions.

Returns {:error, {:wrong_completion_count, expected: m, got: count}} when the completion count does not match the configured m, and {:error, {:invalid_completions, value}} when the completions field is not a list.

new(signature, opts \\ [])

Builds a multi-chain comparison program.

:m (or uppercase :M) is the exact number of completions expected at call time and must be a positive integer.