Repository navigation
feat(query): add RANK for scoring hyperedges against a query hyperedge - #109
Merged
Merged
Conversation
RANK EDGE e:T LIKE (slots) [VALID AT t [TAU d] | VALID DURING [f, u)] [PREFER ...] [SIZE n] [WEIGHTS (...)] TOP k returns the k hyperedges that best fit a query hyperedge. The score is a weighted sum of five parts in [0, 1]: members, roles, attributes, time and topology. MATCH is unchanged. REQUIRED named slots drive the candidates through role-filtered posting cursors; otherwise every hyperedge of the type is a candidate. Each candidate gets an upper bound from cheap reads, and candidates are fully scored in bound order until no remaining bound can enter the top k, which returns exactly what scoring every candidate would. Candidates, full scores and member reads are charged to a row budget, slots and preferences are capped while parsing, and an empty interval in any statement is now a syntax error instead of an internal one.
venkat1701
changed the base branch from
feature/role-filtered-postings
to
main
October 27, 2026 12:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #108 (uses its role-filtered posting cursors). Merge #108 first; this PR then retargets to
main.Adds role- and time-aware scoring of hyperedges as a new statement.
MATCHis unchanged, so no existing query changes behaviour.Statement
Output:
edge, score, members, roles, attributes, time, topology. Each part is between 0 and 1 with a fixed meaning, so scores are comparable across queries; parts the query does not use areNULLand get weight 0. Full reference indocs/database/hql.md#rank, algorithm and costs in the newdocs/database/ranking.md.How it runs
REQUIREDnamed slots give the candidates: the intersection of their reverse-index postings, role-filtered. Without one, every hyperedge of the type is a candidate, so the answer stays exact.io.hstore.db.retrieve:RankQuery,RoleTimeScorer,Ranking.Limits and safety
TOPup to 10,000, at most 16 slots and 16 preferences (checked while parsing), weights,TAU,SCALEand intervals validated.Budget.DEFAULT(1,000,000 rows, 30 s); page reads use the statement's page budget. Going over fails the statement rather than returning a partial ranking. The per-query member-type cache is capped.Reader.require, so another tenant's atom fails exactly like a missing one; typed slots only count membersReader.atomreturns; candidates are admitted throughReader.atombefore anything else is read.RANKis logged as a read by the statement logger.[5, 5)) in any statement was an internalIllegalArgumentException; it is now a syntax error.Tests
RankTest.workedExampleRanksByTheFiveComponents: the example from the design doc, scores checked to 1e-9.RankTest.earlyStoppingAgreesWithScoringEverything: 300 random queries (random slots, roles, required flags, time specs, preferences, sizes and weights) over 500 random edges; checks that the bound is never below the score for every edge, and that the early-stopping top k equals scoring every edge. Making the bound too tight for typed slots makes it fail.longrange.SecurityTest.rankStaysInsideTheTenant: another tenant's atom cannot be named, and a cross-tenant member does not fill a typed slot.An independent review found no correctness issues in the bound or the early stop; its smaller findings (NaN scores, exact time arithmetic above 2^53, the unbounded member-type cache, caps checked after slot resolution, the statement-logger category) are fixed here.