Skip to content

feat(retrieval): REFINE best paths through nested hyperedges - #118

Merged
venkat1701 merged 5 commits into
mainfrom
feature/hierarchical-retrieval
Nov 23, 2026
Merged

venkat1701 merged 5 commits into
mainfrom
feature/hierarchical-retrieval

Conversation

@venkat1701

Copy link
Copy Markdown
Collaborator

Stacked on #115: it reads the child-edge index (slot 56) that #115 adds. Merge #115 first, then retarget this to main.

REFINE walks down nested hyperedges from root hyperedges, through a fixed sequence of child hyperedge types, to leaf members. It returns the best paths, scored by the product of the membership weights along each path.

refine = "REFINE" "FROM" ( ref { "," ref } | "TYPE" identifier )
         { "THROUGH" identifier [ "AS" identifier { "OR" identifier } ] }
         "TO" [ identifier ] [ "AS" identifier { "OR" identifier } ] [ "=" ref ]
         [ "VALID" "AT" additive ] [ "WEIGHT" "BETWEEN" number "AND" number ] [ "DISTINCT" ] "TOP" integer ;

The syntax is open for renaming before merge. Refinement.on(reader).run(spec, meter) is the Java entry point.

How it works

  • Top-down search: best-first over path bounds. An edge's bound is tightened by its largest member weight when it is first taken from the heap. Every later factor is at most 1, so results come out in exact order and the search stops after TOP k.
  • Children: read from the child-edge index, and leaves from the member tree. Both are pruned by role, validity and weight summaries.
  • Anchored leaf (TO … = @leaf): the search climbs the reverse index instead.
  • DISTINCT: keeps the best path per leaf.
  • Paths: a path never revisits a hyperedge, and children and leaves of another tenant are skipped.

Testing

  • Full build: engine 269, database 191, server 41, all passing.
  • Brute force: results are compared with an enumeration of every path. There are 200 random top-down queries over up to three levels with cycles and shared children, and 150 anchored bottom-up queries, plus the design's worked example, a cycle case, the statement, and a tenant test.
  • Mutation checks: a bound that is too low, no cycle check, and bottom-up ignoring roles each make a test fail.
  • A real bug caught this way: the randomized test first found a re-queued bound being reused as the path prefix.

Independent review. It found four important issues, fixed here with tests that failed first:

  • On budget exhaustion, bottom-up returned an arbitrary subset as if it were a prefix.
  • Weight checks were wrong both ways.
  • Some work was never charged to the budget.
  • A leaf could repeat an edge on its path.

Repeated roots are also counted once now.

Not done here

  • The leaf level scans each edge's member tree with summary pruning rather than opening subtrees one at a time: exact, with less pruning on very wide edges.
  • When scores tie, the two directions may report different paths in DISTINCT mode.
  • Leaf types named like keywords need another spelling.
  • The path renders as text.

REFINE walks down from root hyperedges through a fixed sequence of child
hyperedge types to leaf members and returns the best paths, scored by the
product of membership weights. A best-first search over path bounds,
tightened by each edge's largest member weight, emits results in exact
descending order, so it stops after TOP k. Child links come from the
child-edge index and leaves from the member tree, both pruned by role,
validity and weight summaries. With an anchored leaf the search climbs
the reverse index instead. Paths never revisit a hyperedge, weights
outside [0, 1] are refused, and children or leaves of another tenant are
skipped.

No issue tracks this work.
…etrieval

# Conflicts:
#	database/src/main/java/io/hstore/db/Reader.java
A bottom-up search that ran out of budget returned whatever paths it had
found, which was not a prefix of the answer; it now fails instead, as a
top-down search does while roots are still being read. Weight ranges must
lie inside [0, 1], so a membership outside it is simply not followed and
an unrelated member no longer fails the statement. Roots of a type are read
lazily, and every root, posting, child and leaf counts against the budget;
bottom-up filters postings on role and validity before reading anything
else. A leaf is never a hyperedge already on its path, in either direction,
and repeated roots are counted once.

No issue tracks this work.
@venkat1701
venkat1701 changed the base branch from feature/temporal-retrieval to main November 23, 2026 10:53
…retrieval

# Conflicts:
#	database/src/main/java/io/hstore/db/Reader.java
#	database/src/main/java/io/hstore/db/query/Ast.java
#	database/src/main/java/io/hstore/db/query/Executor.java
#	database/src/main/java/io/hstore/db/query/Parser.java
#	database/src/test/java/io/hstore/db/SecurityTest.java
#	docs/database/hql.md
#	server/src/main/java/io/hstore/server/StatementLogger.java
@venkat1701
venkat1701 merged commit b566035 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