Skip to content

feat(retrieval): MOTIFS census, profiles and occurrence search - #121

Merged
venkat1701 merged 2 commits into
mainfrom
feature/motif-census
Nov 23, 2026
Merged

venkat1701 merged 2 commits into
mainfrom
feature/motif-census

Conversation

@venkat1701

Copy link
Copy Markdown
Collaborator

This adds hypergraph motif counting. Three hyperedges that overlap form one of 30 shapes ("classes"). This PR adds statements that count how often each shape occurs, count the shapes around one hyperedge, and list the triples of one shape with conditions on who sits where. The model is the h-motif of Lee, Ko and Shin (PVLDB 2020). Their 26 classes are extended with 4 more for hyperedges that have the same members, since two meetings with the same attendees are ordinary data here.

motifs        = "MOTIFS" [ "OF" identifier ] [ "EXACT" | "SAMPLE" integer | "AUTO" ] [ "SEED" integer ] ;
motif_profile = "MOTIF" "PROFILE" ref [ "OF" identifier ] ;
motif         = "MOTIF" integer [ "TYPES" "(" slot_type "," slot_type "," slot_type ")" ] [ "AROUND" ref ]
                { "REGION" string "HAS" ( ref | "ANY" [ identifier ] ) [ "ROLES" "(" roles { "," roles } ")" ] }
                [ "NESTED" ] [ "RANK" "BY" ( "COMMON" | "DISJOINT" | "INDEPENDENT" ) ] [ "LIMIT" integer ] ;
create_view   = … | "CREATE" "VIEW" identifier "AS" "MOTIFS" [ "OF" identifier ] ;

The syntax is open for renaming before merge. docs/database/motifs.md explains the classes, regions and weights.

How it works

  • Nothing on the write path. One membership change can reclassify every triple that contains its hyperedge, so counts are computed when asked for. Neighbours and overlaps come from the reverse index. Member reads are only needed for the triple overlap, and only when all three pairs overlap.
  • MOTIFS EXACT is the paper's exact algorithm. SAMPLE n draws n hyperedges uniformly and reports an unbiased estimate with a standard error.
  • The default mode counts exactly within half the row budget and otherwise samples. The draw count is fixed by a pilot run, so the result depends on the data and the seed, never on machine load.
  • MOTIF <code> returns each triple once. Results can be narrowed by types per position, an anchor hyperedge, or conditions on a region's member (a fixed atom, a type, roles per hyperedge), and filtered for nesting. RANK BY uses the triplet weights of Niu et al. (IEEE BigData 2024).
  • The census view keeps one cell per class. It is rebuilt on refresh when the tenant's memberships changed, and is on demand only.
  • Format. Format 9 is unreleased, so the view kind and the new view cell tag don't need a format bump.

Testing

  • Full build: engine 269, database 262, server 41, all passing.
  • MotifTest against a brute force that enumerates every triple and classifies it independently:
    • exact counts and per-hyperedge profiles on 6 random graphs with duplicates and nested hyperedges, over three scopes
    • unbiased sampling across 400 seeded runs
    • 400 random occurrence queries with types, anchors, region conditions, roles, nesting, ranking and limits
    • a dense graph for ranked top-k
    • identical results after reopening
  • Mutation checks: each of these breaks a test:
    • dropping open triples from the counting rule
    • never reading the triple overlap
    • double counting around a sample
    • a wrong sampling scale
    • a too-tight ranking bound
    • ignoring the edges outside a region
    • repeating fixed-member triples
  • MotifStatementTest: the design's worked example end to end, including the census view after a member is added (classes 94/31/30 become 95/31/31/53), and every invalid form.
  • Security: SecurityTest#motifsStayInsideTheTenant plants cross-tenant memberships both ways. Without the member filter the test fails.
  • Live, over the wire. A real server and two tenants, comparing against a Python brute force:
    • 107 and 106 motif checks agree; sampled counts fall within 6 standard errors.
    • HYPERMATCH counts and BRANCH DELTA agree.
    • Outputs of DIFFUSE, EXPAND FROM, SELECT EVIDENCE, REFINE and MOTIF were identical after a SIGKILL and recovery (350 commits replayed).
    • All 8 cross-tenant probes were refused.
    • A deliberately wrong reference makes the checker fail.

Independent review. No critical issues. The three important ones are fixed:

  • a hub's postings were walked before the budget was checked
  • the automatic count depended on the clock
  • a continuous census would rebuild on every commit from any tenant

Not done here

  • Ternary (431-class) motifs, temporal motifs, and motifs of four or more hyperedges.
  • The hyperwedge sampler (MoCHy-A+).
  • Parallel counting.
  • An incremental census view.
  • A type named Roles, Region, Nested, Rank, Limit or Around cannot follow HAS ANY.

MOTIFS counts triples of overlapping hyperedges by h-motif class, over one
hyperedge type or all of them: exactly, from a uniform sample of hyperedges
with a standard error, or exactly with a fallback to sampling when the
budget runs out. There are 30 classes, the 26 of Lee, Ko and Shin plus four
for hyperedges with equal member sets. MOTIF PROFILE counts the classes
around one hyperedge. MOTIF <code> lists the triples of one class with
positions, optional types per position, an anchor hyperedge, region
conditions on a member's type, identity and roles, nesting, and ranking by
the triplet weights of Niu et al. Neighbourhoods and overlaps come from the
reverse index at query time; nothing is added to the write path. A census
can also be kept as a view, CREATE VIEW v AS MOTIFS [OF Type], rebuilt on
refresh. Only the reader's hyperedges and visible members count.

No issue tracks this work.
Postings of a hub are now charged every 1,024 reads instead of after the
whole walk, and the holders of a fixed region member are charged too. The
automatic count decides between exact and sampled by rows alone, and a
pilot run with another seed fixes the number of draws, so the same query
on the same data gives the same answer however busy the machine is. A
motif census view cannot be CONTINUOUS, and a refresh rebuilds it only
when the tenant's memberships changed. SEED is refused with EXACT, a
fixed region member is tested directly, and the ROLES order is documented.

No issue tracks this work.
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