Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/apps-module-migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@
"src/inferrsi/apps/cli/__init__.py",
"tests/repository/check_installed.py",
"tests/apps/test_apps_module_migrations.py",
"tests/benchmark/test_benchmark_compare.py"
"tests/benchmark/test_benchmark_compare.py",
"tests/benchmark/test_benchmark_compare_indexer.py"
],
"status": "retired",
"first_removal_version": "0.3.4"
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ See [round decisions](knowledge/knowledge-retrieval-trace.md#round-decisions).

| Intent | Entry | Effect class | Boundary |
| --- | --- | --- | --- |
| Verify whether RSI knowledge improves optimization efficiency | CLI `benchmarks compare`; [comparison workflow](../benchmarks/benchmark-comparison.md) | Local experiment records / explicit native handoff / report-generating | Apps freezes two-task on/off plans, returns host actions, verifies retained finals and reports Benchmark comparisons; no hidden Agent launch |
| Verify whether RSI knowledge or an Indexer policy improves optimization efficiency | CLI `benchmarks compare [--focus knowledge|indexer]`; [comparison workflow](../benchmarks/benchmark-comparison.md) | Local experiment records / explicit native handoff / report-generating | Apps freezes paired plans (knowledge on/off, or Indexer baseline vs candidate `--candidate-ranking-policy-file` with optional `--evolution-report` overhead), returns host actions, verifies retained finals and `#509` delivery preconditions, and reports Benchmark comparisons; no hidden Agent launch |
| Compare two Indexer ranking rules on CPU | CLI `benchmarks indexer-compare`; Python `apps.workflows.indexer_comparison.compare_indexer_policies` | Read-only (optional new JSON report via `--output`) | Deterministic CPU retrieval and byte-budgeted delivery comparison over a pinned corpus and frozen query suite; enforces split isolation and optional `RankingSpace` checks; descriptive offline retrieval only, never a task or service `PASS` |
| Run a bounded P1 Indexer evolution loop on CPU | CLI `benchmarks indexer-evolve`; Python `apps.workflows.indexer_evolution.run_indexer_evolution` | Local evolution records (`--output` directory) | Evolves only the six `RankingPolicy` weights inside a frozen `RankingSpace` using deterministic coordinate search or an external provider routed through Harness `_agent_sessions.py`; enforces verified delivery-boundary citations, budget reservation on interrupted calls, mandatory rerun and single-use held-out gate; offline CPU retrieval only, never a task or service `PASS` |
| Complete a task optimization in the current Agent | CLI `session start benchmark/round/status/final/recover`, `find --session` / `read` | Experiment-executing / local records | Frozen budget, actual candidates and independent task outcomes. The current Agent drives edits. Real usage is imported explicitly. Recovery collects an existing execution using its [pinned runtime](optimization-workflow-unification.md#release-boundary-recovery) |
Expand Down
30 changes: 28 additions & 2 deletions src/inferrsi/apps/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,37 @@ def parser(*, parser_class=argparse.ArgumentParser, historical=False,
"unsuccessful attempt opens a fresh one and retains the earlier attempt; "
"retries are never automatic. No dedicated skill is required."),
)
compare.add_argument("--focus", choices=("knowledge",), default="knowledge")
from ...knowledge.ranking_policy import MANAGED_RANKING_POLICIES

compare.add_argument(
"--focus", choices=("knowledge", "indexer"), default="knowledge",
help="Comparison focus: knowledge on/off (default) or indexer candidate vs baseline policy",
)
compare.add_argument("--action", choices=("prepare", "status", "dispatch", "bind", "record",
"collect", "retry", "report"), default="prepare",
help="Prepare a new experiment; use its --output for later operations")
compare_base = compare.add_mutually_exclusive_group()
compare_base.add_argument(
"--baseline-ranking-policy", choices=tuple(MANAGED_RANKING_POLICIES),
help="Registered baseline H0 ranking policy for --focus indexer (default: default)",
)
compare_base.add_argument(
"--baseline-ranking-policy-file", type=Path,
help="Baseline H0 ranking configuration JSON for --focus indexer",
)
compare_cand = compare.add_mutually_exclusive_group()
compare_cand.add_argument(
"--candidate-ranking-policy", choices=tuple(MANAGED_RANKING_POLICIES),
help="Registered candidate H1 ranking policy for --focus indexer",
)
compare_cand.add_argument(
"--candidate-ranking-policy-file", type=Path,
help="Candidate H1 ranking configuration JSON for --focus indexer",
)
compare.add_argument(
"--evolution-report", type=Path,
help="Optional indexer_evolution_report JSON to record Evolver search overhead separately",
)
compare.add_argument("--config", type=Path, help="Non-secret project configuration JSON")
compare.add_argument("--output", type=Path,
help="New comparison directory, or existing to resume")
Expand All @@ -699,7 +726,6 @@ def parser(*, parser_class=argparse.ArgumentParser, historical=False,
compare.add_argument("--session-id")
compare.add_argument("--receipt", type=Path, help="Original host creation receipt for bind")
compare.add_argument("--observation", type=Path, help="Native host observation JSON")
from ...knowledge.ranking_policy import MANAGED_RANKING_POLICIES

indexer_compare = actions.add_parser(
"indexer-compare",
Expand Down
73 changes: 57 additions & 16 deletions src/inferrsi/apps/views/comparison_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ def _html_table(headers, rows):
+ "</tr>" for row in rows) + "</tbody></table></div>")


def _task_rows(assessment):
def _task_rows(assessment, *, arms=("on", "off")):
treatment, reference = arms
rows = []
for task in assessment["tasks"]:
for name, label in _METRICS.items():
metric = task["metrics"][name]
rows.append((task["task"], label, metric["selected"],
_metric_value(name, metric["on_median"]),
_metric_value(name, metric["off_median"]),
_metric_value(name, metric[f"{treatment}_median"]),
_metric_value(name, metric[f"{reference}_median"]),
_metric_value("speedup", metric["paired_factor"]), metric["pair_count"],
_LABELS[task["conclusion"]["kind"]]))
return rows
Expand Down Expand Up @@ -283,8 +284,11 @@ def _documents(report, json_digest):
repeats = report["repeats"]
repeat_label = "repeat" if repeats == 1 else "repeats"
scope = ", ".join(report["tasks"]) + f" · {repeats} {repeat_label} per task"
md = ["# Knowledge comparison", ""]
html = ["<h1>Knowledge comparison</h1>"]
is_indexer = report.get("focus") == "indexer"
arms = ("candidate", "baseline") if is_indexer else ("on", "off")
title = "Indexer ranking comparison" if is_indexer else "Knowledge comparison"
md = [f"# {title}", ""]
html = [f"<h1>{title}</h1>"]

def heading(title, level=2):
md.extend(["#" * level + " " + _md(title), ""])
Expand Down Expand Up @@ -316,8 +320,9 @@ def table(headers, rows):
table(("Task", "Arm", "Repeat", "Final speedup", "Step acceptance",
"Token consumption", "Coverage / source"), basic)
derived = []
labels = {"performance_benefit_ratio": "Performance benefit (on/off)",
"token_consumption_ratio": "Token consumption (on/off)",
ratio_tag = "candidate/baseline" if is_indexer else "on/off"
labels = {"performance_benefit_ratio": f"Performance benefit ({ratio_tag})",
"token_consumption_ratio": f"Token consumption ({ratio_tag})",
"acceptance_rate_delta_pp": "Acceptance difference (pp)"}
for task in report["benchmark_metrics"]["tasks"]:
for field, metric_label in labels.items():
Expand All @@ -330,9 +335,10 @@ def table(headers, rows):
"; ".join(metric["missing_reasons"])))
table(("Task", "Comparison metric", "Value", "Observed only", "Valid pairs",
"Missing reasons"), derived)
favored = "candidate" if is_indexer else "on"
paragraph("Final speedup uses an independent final; acceptance counts actual best "
"promotions. Token consumption below 1 favors on. Unknown costs remain unknown; "
"these metrics do not change the frozen comparison verdict below.")
f"promotions. Token consumption below 1 favors {favored}. Unknown costs remain "
"unknown; these metrics do not change the frozen comparison verdict below.")

md.extend(["**" + label + "**", "", _md(conclusion["text"]), "",
_md(conclusion["limitation"]), "", _md(scope), ""])
Expand All @@ -342,10 +348,44 @@ def table(headers, rows):
f"<p>{escape(scope)}</p>"])

heading("Task comparisons")
table(("Task", "Metric", "Used in verdict", "On median", "Off median",
"Paired benefit factor", "Valid pairs", "Task conclusion"), _task_rows(assessment))
paragraph("A benefit factor above 1 favors knowledge on. Speedup uses on/off, while time "
"and tokens use off/on. Medians use eligible matched pairs.")
arm_headers = (
("Candidate median", "Baseline median") if is_indexer else ("On median", "Off median")
)
table(("Task", "Metric", "Used in verdict", *arm_headers,
"Paired benefit factor", "Valid pairs", "Task conclusion"),
_task_rows(assessment, arms=arms))
if is_indexer:
paragraph("A benefit factor above 1 favors the candidate ranking policy. Speedup uses "
"candidate/baseline, while time and tokens use baseline/candidate. "
"Medians use eligible matched pairs.")
overhead = report.get("evolution_overhead")
if isinstance(overhead, dict):
budget = overhead.get("budget")
if not isinstance(budget, dict):
budget = {}
tokens_known = budget.get("usage_tokens_known") is True
in_tokens = budget.get("total_input_tokens")
out_tokens = budget.get("total_output_tokens")
search_tokens = (
in_tokens + out_tokens
if (
tokens_known
and type(in_tokens) is int and in_tokens >= 0
and type(out_tokens) is int and out_tokens >= 0
)
else None
)
heading("Evolver search overhead (reported separately)", 3)
table(
("Evolver mode", "Rounds attempted", "Calls submitted", "Spent units",
"Reserved units", "Search tokens (known only)"),
[(overhead.get("evolver_mode"), overhead.get("rounds_attempted"),
budget.get("evolver_calls_submitted"), budget.get("spent_units"),
budget.get("reserved_units"), _metric_value("tokens", search_tokens))],
)
else:
paragraph("A benefit factor above 1 favors knowledge on. Speedup uses on/off, while time "
"and tokens use off/on. Medians use eligible matched pairs.")
table(("Completed trials", "Eligible trials", "Eligible pairs", "Running", "Pending",
"Failed", "Blocked", "Missing"),
[(f"{counts['statuses']['completed']} / {counts['planned_trials']}",
Expand Down Expand Up @@ -460,7 +500,7 @@ def table(headers, rows):
'<meta name="viewport" content="width=device-width,initial-scale=1">'
'<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; '
'style-src \'unsafe-inline\'; base-uri \'none\'; form-action \'none\'">'
'<title>Knowledge comparison</title><style>'
f'<title>{escape(title)}</title><style>'
'body{font:15px/1.55 system-ui,sans-serif;max-width:1200px;margin:32px auto;'
'padding:0 20px;color:#172033;background:#fff}h1,h2,h3{line-height:1.2}'
'h2{margin-top:32px}.conclusion{font-size:22px;font-weight:650}.note{color:#526078}'
Expand All @@ -481,8 +521,9 @@ def write_comparison_report(report: dict, directory: Path) -> dict:
documents identify the exact JSON digest; no source experiment is modified.
"""
if (not isinstance(report, dict) or type(report.get("schema_version")) is not int
or report["schema_version"] != 1 or report.get("focus") != "knowledge"):
raise ValueError("Expected a version 1 knowledge comparison report")
or report["schema_version"] != 1
or report.get("focus") not in ("knowledge", "indexer")):
raise ValueError("Expected a version 1 knowledge or indexer comparison report")
raw = (json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2, allow_nan=False)
+ "\n").encode("utf-8")
markdown, html = _documents(report, hashlib.sha256(raw).hexdigest())
Expand Down
Loading
Loading