Expand description
QUBO context-selection spike (#10) — research only, never the default.
Context selection under a token budget is a quadratic optimization: maximize total salience while penalizing redundancy between co-selected items and staying within budget. That is naturally a QUBO (quadratic unconstrained binary optimization):
minimize E(x) = -Σ φ_i x_i + α Σ_{i<j} sim_ij x_i x_j + β·overflow(x)
over x ∈ {0,1}^nwhere overflow is the budget violation. QUBO is the form solved by quantum
annealers and their classical analogues (simulated annealing / simulated
bifurcation). This module provides a deterministic simulated-annealing
solver (seeded PRNG — no getrandom) plus a benchmark harness comparing it to
the production greedy knapsack on quality (φ captured) and tokens.
IMPORTANT: this is a benchmark spike gated behind LEAN_CTX_EXPERIMENTAL_QUBO.
It never changes selection defaults; the greedy compiler remains in charge.
Promotion is conditional on a measurable win from the harness below.
Structs§
- Bench
Report - Result of a QUBO-vs-greedy benchmark run.
- Qubo
Item - A candidate item for QUBO selection.
Functions§
- benchmark
- Run the QUBO-vs-greedy benchmark on a problem. Pure and deterministic.
- is_
enabled truewhen the experimental QUBO spike is enabled. Off by default — the greedy selector stays the default selection path regardless.- select
- Solve the selection QUBO with deterministic simulated annealing. Returns the
indices of selected items. Seeded by a stable hash of the problem so the
result is reproducible. Registers activity for
introspect cognition. - synthetic_
problem - A deterministic synthetic problem for the CLI harness: clusters of redundant items plus unique high-φ items, so QUBO’s redundancy awareness can show.