Skip to content

feat(retrieval): SELECT EVIDENCE, budgeted covering selection - #120

Merged
venkat1701 merged 4 commits into
mainfrom
feature/budgeted-retrieval
Nov 23, 2026
Merged

venkat1701 merged 4 commits into
mainfrom
feature/budgeted-retrieval

Conversation

@venkat1701

Copy link
Copy Markdown
Collaborator

Stacked on #119 because it uses EXPAND FROM to find connected candidates. Merge #115 and #119 first, then retarget this to main.

SELECT EVIDENCE picks a small set of hyperedges that together answer a RANK query, sized for handing to an agent. You give it a limit on the number of hyperedges (TOP), on their total member count (BUDGET), or both.

select_evidence = "SELECT" "EVIDENCE" "FOR" "(" rank ")" [ "FROM" ref { "," ref } ] [ "CONNECTED" ]
                  ( "BUDGET" integer [ "TOP" integer ] | "TOP" integer ) [ "KAPPA" number ] [ "LAMBDA" number ] [ "CANDIDATES" integer ] ;

The syntax is open for renaming before merge.

What a set is worth (retrieve/Selection.java). Each hyperedge's RANK score is spread over its members and capped per atom at KAPPA. On top of that, each query slot counts once, weighted, as soon as some chosen hyperedge fills it. A near duplicate therefore adds little, and an exact copy adds nothing once its members are capped. The value is monotone and submodular.

How it chooses

  • With TOP only, lazy greedy, which is within 1 - 1/e of the best set.
  • With BUDGET, greedy by gain per member, compared with the best single candidate. That is within (1 - 1/e) / 2.
  • With both, greedy also runs by count alone and keeps the better set. I know of no proven ratio for this case, and the docs claim none. Over 3,000 random cases it never fell below 0.75 of the optimum.
  • The message always gives an upper bound on the best value these candidates could reach, so objective / bound is a certified quality figure for the query.
  • With FROM … CONNECTED, each chosen hyperedge brings its expansion chain back to a seed, so the set stays connected. That mode has no ratio, but the bound still holds.

Candidates

  • The RANK top list, plus up to CANDIDATES hyperedges reached from the seeds.
  • Reached hyperedges of another type can only serve as connectors.
  • Only members the reader can see count.

Budget. Ranking, expansion and selection each get their own share of the budget. If selection runs out, it returns what it has chosen so far and says so.

Testing

  • Full build: engine 269, database 211, server 41, all passing.
  • SelectionTest:
    • Compares against the exhaustive optimum on 450 random small instances, checking feasibility, the objective against an independent formula, the bound against the optimum, and both guarantees.
    • Checks that lazy greedy matches an eager greedy on 300 instances, and that both limits together never lose to count-only greedy.
    • Covers the singleton rescue, unit pricing, running out of budget, and duplicates.
  • Mutation checks: each of these breaks a test:
    • accepting stale lazy keys
    • dropping the singleton pass
    • ignoring unit size
    • dropping the count-only pass
  • SelectEvidenceTest: the statement end to end: duplicates skipped, connected selections, other-type hyperedges left out, invalid clauses refused.
  • Security: SecurityTest#evidenceSelectionCountsOnlyTheTenantsMembers injects another tenant's member into an edge. The edge must still cost 1 and the hidden member must not appear.

Independent review. No critical issues. All five important ones are fixed, each with a test that failed before the fix:

  • expansion edges skipping the RANK type filter
  • no guarantee with both limits
  • connected units priced without their size
  • budget exhaustion throwing instead of returning the greedy prefix
  • unbounded work in gains, member loading and the bound pass

Not done here

  • The per-hyperedge cost is its member count. There is no token-based cost yet.
  • No Greedy+ variant.
  • In CONNECTED mode, a RANK candidate the expansion did not reach cannot be chosen.

…redges

SELECT EVIDENCE FOR (RANK ...) chooses a small set of hyperedges that
together answer a RANK query, under a limit on the number of hyperedges,
on their total member count, or both. A set's value spreads each
hyperedge's relevance over its members, caps what any atom contributes,
and adds the weighted coverage of the query's slots, so a near duplicate
adds little. The value is monotone and submodular: a lazy greedy is
within 1 - 1/e under a count limit, and cost-benefit greedy with the best
single candidate within (1 - 1/e) / 2 under a budget. The message reports
an upper bound on the best value from the candidates. With FROM and
CONNECTED, candidates come with their expansion chains back to the seeds
and a set stays connected.

No issue tracks this work.
Hyperedges reached by the expansion that are not of the RANK type now
have no relevance and cover no slot, so they are only chosen to connect
others. With both TOP and BUDGET, greedy prices a hyperedge by the larger
share of either limit it uses and is compared with a count-only greedy.
Connected units are priced by how many hyperedges they add. Ranking,
expansion and selection each get their own share of the budget; when
selection runs out it returns the set chosen so far and says it has no
bound. Gains are computed from the unit's own members, member loading is
metered and capped at 10,000, and only members the reader can see count.
CANDIDATES without FROM is refused.

No issue tracks this work.
@venkat1701
venkat1701 changed the base branch from feature/hypergraph-diffusion to main November 23, 2026 11:17
…ieval

# Conflicts:
#	docs/database/hql.md
#	server/src/main/java/io/hstore/server/StatementLogger.java
@venkat1701
venkat1701 merged commit d81fe0c into main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant