Optimize Index Retrieval
Goal
Implement a strict, reusable optimization standard for complex index retrieval flows. Keep retrieval and decision semantics unchanged; optimize only response shaping, context budget control, and retry guidance.
Non-Goals
- Change scoring logic, thresholds, or label mapping.
- Redesign business workflow beyond retrieval context control.
- Replace domain datasets, schema, or storage models.
Workflow
- Freeze semantics first.
- Keep labels, thresholds, scoring weights, and ranking logic unchanged.
- Limit changes to response contract, payload control, and observability.
- Add context-control inputs.
- Add
response profilewith exactly two values:compact|full. - Default
compactfor heavy decision/intake commands. - Default
fullfor diagnostic and low-volume commands. - Add
payload budgetin KB, default20(20*1024UTF-8 bytes). - Clamp retrieval
limitto1..20; report both requested and effective values.
- Add oversize observability.
- Never silently truncate
fulloutput. - Always compute payload bytes with UTF-8 serialized output.
- After profile + field mask are applied, run oversize check.
- If oversized, keep output visible and append:
meta.contextControl.oversize=truemeta.contextControl.thresholdBytesmeta.contextControl.payloadBytesmeta.contextControl.oversizeStagemeta.contextControl.stageBreakdownmeta.contextControl.optimizationHintsmeta.contextControl.limitAdjusted.requested/effectivewhen limit applies.
- Provide explicit next-call hints.
- Generate at least 2 directly executable hint commands.
- Hints must prioritize:
- switch to compact profile,
- reduce
limit(for example 20 -> 10 -> 5), - narrow fields,
- split one heavy call into staged calls.
- For text mode, print an
OVERSIZE_HINTblock with copyable commands.
- Validate with contract + child-runner + perf benchmark.
- Add contract tests for profile defaults, limit clamp, payload budget, oversize metadata completeness.
- Add output tests for
json/text/ndjsonconsistency. - Add child-runner simulation: first call oversized, second call follows hint and payload decreases while key decision fields remain available.
- Run
scripts/benchmark_context_control.pyto compare profiles and report payload/latency deltas.
Required Contract
Load and apply references/context-control-standard.md as the authoritative output contract.
Performance Benchmark Capability
Use bundled script:
./scripts/benchmark_context_control.py
Example:
python ./scripts/benchmark_context_control.py `
--command-template "python skills/p1max-qa-playbook-workflow/workflow.py triage.decide --source internal --params @tmp/triage_input.json --payload-budget-kb 20 --response-profile {profile} --output json" `
--stdout-format auto `
--rounds 10 `
--profile-a full `
--profile-b compact `
--min-payload-drop-pct 50
Expected use:
- Confirm payload reduction is substantial.
- Confirm latency regression is controlled.
- Produce JSON summary for release notes or review comments.
- Set
--stdout-format ndjsonwhen the target command emits NDJSON.
Delivery Checklist
- Contract fields exist and are populated when oversized.
fieldskeeps highest priority and still triggers oversize evaluation.- No scoring/decision semantic change is introduced.
- Tests include child-runner guided retry.
- Benchmark script output is attached in review.