Skip to content

feat(retrieval): EXPLAIN and FUSE for retrieval, shared budgets, review fixes - #123

Merged
venkat1701 merged 2 commits into
mainfrom
feature/retrieval-planner
Nov 23, 2026
Merged

venkat1701 merged 2 commits into
mainfrom
feature/retrieval-planner

Conversation

@venkat1701

Copy link
Copy Markdown
Collaborator

Stacked on #122. Merge #121 and #122 first, then retarget this to main.

This finishes the retrieval work. It adds the planner layer for the new statements, closes every finding that earlier reviews left open, and fixes what a fresh re-review of the whole retrieval surface found.

Planner (docs/database/planner.md#retrieval-statements)

  • EXPLAIN on any retrieval statement. It prints the family, whether the answer is exact, approximate with a certificate, or may fail, the plan, and the rule that chose it. It checks atoms and types as the statement would, without running it.
  • FUSE runs 2 to 8 retrieval statements on one snapshot and merges them by reciprocal rank fusion (k = 60). It keeps each item's provenance, names parts that ran out of budget, and says when a LIMIT leaves out results of an exact list.
  • DIFFUSE … READS r sets epsilon from the walk's work bound and caps the row budget at r.
  • HYPERMATCH refusal: a pattern whose first scan alone exceeds the row budget is refused before any read. A one-hyperedge COUNT, answered from the signature count, is exempt.
  • One budget per statement. It is passed down to every operator. FUSE and SELECT EVIDENCE split it instead of starting fresh ones.
explain = "EXPLAIN" ( match | hypermatch | retrieval ) ;
fuse    = "FUSE" "(" part ")" "," "(" part ")" { "," "(" part ")" } [ "LIMIT" integer ] ;
diffuse = … [ "EPSILON" number | "READS" integer ] … ;

Earlier leftovers, now fixed

  • Tenant isolation: other tenants' members no longer shape DIFFUSE and EXPAND FROM values.
  • Branches: the snapshot route reports changed atom records. Branch statements refuse AT GENERATION/AS OF and show type names.
  • TRANSITIONS: falls back to the feed when a snapshot is released mid-diff.
  • Validity index: reads check type privileges.
  • Parallel matching: siblings stop when one search task fails.
  • REFINE: caps levels at the depth budget and accepts quoted type names. Tied paths come out in the same order in both directions, pinned by a test.
  • THROUGH: takes WEIGHT or FACTOR in both DIFFUSE and EXPAND FROM.

Re-review. Two independent reviewers looked at this branch and at the whole retrieval surface. Neither found a critical issue. Their important findings are all fixed:

  • budgets stacking across FUSE and SELECT EVIDENCE parts
  • DIFFUSE cost estimates doing unmetered work
  • REFINE FROM TYPE loading every root up front
  • another tenant's write volume charged to TRANSITIONS
  • FUSE hiding parts that were cut short
  • the one-edge COUNT blocked by the first-scan rule
  • EXPLAIN not checking atoms

Each has a test. The tests for the COUNT, EXPLAIN and READS fixes fail on the previous commit. HYPERMATCH LIMIT still finds every tuple before cutting, because results are globally sorted; this is now documented rather than changed.

Testing

  • Full build: engine 269, database 290, server 41, all passing.
  • Live, over the wire, two tenants, after the fixes:
    • Every check agrees with a Python brute force: motifs 107/107 and 106/106, SIMILAR TO 50/50 per tenant, HYPERMATCH counts and BRANCH DELTA.
    • All 11 families explain, and FUSE scores match their parts.
    • DIFFUSE, EXPAND FROM, SELECT EVIDENCE, REFINE and MOTIF outputs are identical after a SIGKILL and recovery (350 commits replayed).
    • All 14 cross-tenant probes are refused, including through FUSE and EXPLAIN.
    • A deliberately wrong reference makes the run fail.

Not done here

  • Learned plan choice and latency budgets; the design defers both until observations exist.
  • Merging by score when every FUSE part is the same RANK query.

…iew leftovers

EXPLAIN now takes any retrieval statement and prints its family, whether
its answer is exact, approximate with a certificate, or may fail, and the
plan with the rule and counts that chose it, without running it. FUSE
runs two to eight retrieval statements on one snapshot and merges them by
reciprocal rank fusion, keeping the provenance of every item and saying
when a LIMIT leaves out results of an exact list. DIFFUSE takes READS r
and derives epsilon from its work bound. A HYPERMATCH whose first scan
alone exceeds the row budget is refused before it starts.

Leftovers from earlier reviews: other tenants' members no longer shape
DIFFUSE thresholds and pushes or EXPAND FROM weights and damping; the
branch snapshot route reports changes to an atom's record; branch
statements refuse AT GENERATION and AS OF and show type names; a snapshot
released during TRANSITIONS falls back to the feed; validity index reads
check type privileges and the feed scan behind wall-clock instants is
metered; COUNT of a one-hyperedge pattern reads the signature count, and
parallel matching stops siblings after a failure; REFINE caps levels at
the depth budget, accepts quoted type names and labels its paths; THROUGH
takes WEIGHT or FACTOR in both DIFFUSE and EXPAND FROM; MOTIF accepts a
quoted type after HAS ANY. EXPLAIN and FUSE need the same privileges as
the statements they contain.

No issue tracks this work.
A statement now has one budget, passed down through a scoped value. FUSE
splits it in equal shares and shares one page trace across its parts, and
SELECT EVIDENCE splits it in thirds. DIFFUSE cost estimates use constant
time counts in the default tenant and charge the budget for visible counts
otherwise, and READS also caps the row budget. REFINE FROM TYPE streams
its roots. TRANSITIONS charges only the reader's own changes, so another
tenant's writes cannot use up its budget, and falls back to the feed only
when a snapshot was really released. FUSE names parts that ran out of
budget and counts them approximate, ranks the atoms and hyperedges of a
DIFFUSE part separately, and sums reciprocal ranks in a fixed order. A
one-hyperedge HYPERMATCH COUNT is no longer refused by the first-scan
rule. EXPLAIN checks atoms and types like the statement, follows SINCE and
the common ancestor for branches, and nested EXPLAIN, FUSE or AT
GENERATION is refused before parsing recurses. SIMILAR TO charges
container sizes, SELECT EVIDENCE keeps expansion order and reports
skipped large edges, MOTIFS phases stop at ten seconds each, and the docs
now say where an exact statement returns a prefix and that a HYPERMATCH
LIMIT does not bound the search.

No issue tracks this work.
@venkat1701
venkat1701 changed the base branch from feature/similarity-search to main November 23, 2026 19:08
@venkat1701
venkat1701 merged commit 02c9302 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