Mnemosyne.Pipeline.HopRefinement (mnemosyne v0.1.6)

Copy Markdown View Source

Per-hop query refinement for the retrieval pipeline.

Tracks retrieval quality across hops and triggers LLM-based tag refinement when score improvement plateaus. Budget-limited to avoid excessive LLM calls.

Summary

Functions

Initializes refinement state from config and the pipeline's max hop count. Budget is capped at max_hops to avoid exceeding the traversal depth.

Conditionally refines retrieval tags based on score plateau detection.

Functions

init(config, max_hops)

Initializes refinement state from config and the pipeline's max hop count. Budget is capped at max_hops to avoid exceeding the traversal depth.

maybe_refine(state, query, candidates, hop, ctx)

Conditionally refines retrieval tags based on score plateau detection.

Returns {:refined, tags, vectors, new_state} when refinement is triggered and succeeds, or {:skip, new_state} otherwise.

The ctx map must contain :llm, :embedding, :config, and :llm_opts.