raglab.bench#
Cross-run benchmark: the instrument for purpose-indexed memory (raglab#15, item 4).
The follow-ups of the memory design (CONSOLIDATE, SUPERSEDE, purpose transfer, DECAY)
are each gated on an observed trigger. This module is what observes: it replays a
workload of purposes through an agent twice, once cold (no memory) and once warm (with
a PurposeStore), counting the source calls of each, and reports
sweeps_cold/sweeps_warm: retriever calls without and with memory (what memory saves),recall: the share of the cold run’s hits the warm run also returned (what memory costs in answer quality:1.0means nothing was lost),extractions: units kept per purpose after the warm run (the CONSOLIDATE trigger is “this exceeds a threshold”).
Cold and warm calls interleave on the same sources, purpose by purpose, so a source
that changes over time shows as lost recall: that is the SUPERSEDE trigger, but so is
plain non-determinism (an approximate index, a live API). Run the benchmark on a
deterministic snapshot to read recall as what memory alone lost.
Hermetic and offline: pass any sources; nothing here calls an LLM:
report = cross_run_benchmark(sources, ["invoices 2023", "2023 invoices"])
report.sweeps_saved, report.recall
Functions
|
Replay |
|
|
|
Run each question through the agent loop and through a single discover; compare. |
Classes
|
Totals over a workload, with the per-purpose |
|
Totals over the questions, with the per-question |
|
One purpose of the workload: its source calls cold and warm, and its recall. |
|
One question: source calls and hits of the loop and of a single discover. |
- class raglab.bench.CrossRunReport(rows, extractions=dict())[source]#
Bases:
objectTotals over a workload, with the per-purpose
rowsandextractions.
- class raglab.bench.LoopVsSingleReport(rows)[source]#
Bases:
objectTotals over the questions, with the per-question
rows.
- class raglab.bench.PurposeRow(purpose, sweeps_cold, sweeps_warm, recall)[source]#
Bases:
objectOne purpose of the workload: its source calls cold and warm, and its recall.
- class raglab.bench.QuestionRow(question, calls_loop, calls_single, hits_loop, hits_single, single_recall_of_loop, recall_loop=None, recall_single=None)[source]#
Bases:
objectOne question: source calls and hits of the loop and of a single discover.
- raglab.bench.cross_run_benchmark(sources, workload, *, agent_factory=<function make_search_agent>, memory_factory=<class 'raglab.memory.PurposeStore'>, **agent_kwargs)[source]#
Replay
workload(purposes, in order, repeats and paraphrases welcome) cold and warm, and report what memory saved and what it lost.agent_factory(sources, memory=..., **agent_kwargs)builds the agent (defaultmake_search_agent()); the cold agent getsmemory=None. The warm agent shares onememory_factory()store across the whole workload.- Return type:
- raglab.bench.extraction_counts(store)[source]#
{purpose: number of units kept}(each purpose under its own statement).>>> from raglab.memory import ExtractionUnit >>> s = PurposeStore() >>> s["q"] = [ExtractionUnit("q", {"artifact_id": "a"}, 0.0)] >>> extraction_counts(s) {'q': 1}
- raglab.bench.loop_vs_single_benchmark(sources, questions, *, relevant=None, agent_factory=<function make_search_agent>, single_budget=None, **loop_kwargs)[source]#
Run each question through the agent loop and through a single discover; compare.
The single run is the same agent with
single_budget(default one round, one pass over the sources) and none ofloop_kwargs: no LLM roles, so no rewriting and no back-edge. The loop run getsloop_kwargs(formulator,evaluator,planner,budget…). Both count their retriever calls.relevantmaps a question to the artifact ids that answer it, and adds recall against that ground truth; without it the report says how much of the loop’s answer a single discover already had, and what the loop costs in extra source calls. Offline when the roles are: pass fakes, or live sources for a real measurement.- Return type: