Repository navigation
feat(memory): region hierarchy with top-p routing - #126
Merged
Merged
Conversation
CREATE HIERARCHY groups the sections that have a vector in one model and view into nested regions by recursive spherical k-means. REFRESH (or CONTINUOUS upkeep after each relevant commit) follows new revisions, purges and vector changes from the change feed: sections are inserted by descending to the most similar centroid, overfull regions split with 2-means, emptied regions go away and centroids on changed paths are recomputed. Region and leaf records are the truth; child, document and hierarchy indexes are derived from them. ROUTE expands regions best first. At each step it turns calibrated child scores into a softmax, keeps the smallest set holding MASS of the probability (within MIN and MAX), and widens to MAX when the entropy says the children cannot be told apart. It reports regions scored and expanded, sections examined, entropy, kept mass, fallback use and, with RECALL, recall against an exact ranking. REFERENCE REGION and CALIBRATE HIERARCHY load reference vectors and per-level calibration trained outside the database.
- Centroids and reference vectors move from payload vector records to a region-vectors slot in 64-component pieces. Replaced versions are freed with their tree pages, so a purged section's direction no longer survives in an old centroid payload, the payload files stop growing with every refresh, and no payload quota is charged. The public region vector methods on Writer are gone. - Leaves remember their vector's payload, so replacing a section's vector in place moves the leaf and fixes its centroids. - Hierarchy ids derive from tenant and name: two concurrent creates of one name conflict. - Continuous upkeep refreshes only hierarchies of the tenants a commit touched, writes nothing when nothing changed, and holds the change feed only while a hierarchy has relevant changes left to read. Closing waits for a refresh in progress. - Calibration scale and shift are bounded, temperatures are at least 0.001, the default depth is 64, RECALL charges its full scan up front, REGIONS OF HIERARCHY needs a tenant admin and SHOW HIERARCHIES hides counts from users limited by type grants.
Collaborator
Author
|
Pushed fixes from a review pass: centroids and reference vectors now live in their own tree slot instead of payload files, so purged content can't survive in an old centroid and refreshes no longer grow the payload store; replaced section vectors move their leaf; hierarchy names are unique under concurrent creates; continuous upkeep only touches hierarchies of the affected tenant, writes nothing when nothing changed and no longer holds the change feed; calibration and temperature are bounded; REGIONS OF needs a tenant admin. Full build: engine 269, database 361, server 41; each new test fails with its fix reverted; live run green before and after SIGKILL. |
…eature/memory-hierarchy
…eature/memory-hierarchy
…eature/memory-hierarchy
This was referenced Nov 24, 2026
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.
Third part of the memory work, stacked on #125.
What it does
CREATE HIERARCHY name ON MODEL m VIEW v [OF Type] [FANOUT f] [LEAVES n] [CONTINUOUS]groups sections into nested regions.FANOUTchildren per region and at mostLEAVESsections per lowest region.REFRESH HIERARCHYfollows new revisions, purges and vector changes from the change feed.CONTINUOUShierarchy refreshes after each relevant commit and once on open.ROUTE query IN HIERARCHY hexpands regions best first.MASSof the probability, withinMINandMAX.FALLBACK, it widens toMAX.REGIONSandDEPTHcap the work.RECALL, recall against an exact ranking.REFERENCE REGION r OF HIERARCHY h VECTORS (…), up to 16 vectors per region, which replace the centroid when scoring;CALIBRATE HIERARCHY h [TEMPERATURE t] [LEVEL l SCALE a SHIFT b]…, which also bumps the router version.Slots 64 to 66 and 68 to 70 are new, still under format 10.
Syntax
Testing
RouterTest, on generated trees:HierarchyTestchecks the structure after build, refresh, purge, continuous upkeep, rebuild and restart:HierarchyStatementTestcovers the HQL.SecurityTest#hierarchiesStayInsideTheTenantcovers tenants and roles.ROUTEat full mass returns the exact top 5 on 10 of 10 queries.Merge order for the memory stack: #128 (CI fix), #124, #125, #126, #127, #129 (online text index rebuild), #130 (starter kit). Retarget each to main once the one below it merges. A private preview image built from #129 merged with #128 is at ghcr.io/metacoglabs/hstore-memory:0.2.0-dec80f2.