P1 (v0.5): Hierarchical + dialectical memory — full implementation#69
P1 (v0.5): Hierarchical + dialectical memory — full implementation#69
Conversation
…d upgrade Ingest - HierarchyBuilder: cluster pages→books→volumes→shelves using cosine-distance medoid selection; persist each tier; run promotion sweeps after each level - FastNeighborInsert: build sparse SemanticNeighbor graph (NOT Hebbian); forward + symmetric reverse edges; degree-bounded with eviction; marks affected volumes dirty; runs promotion sweep for new pages - Ingest: replace manual single-book construction with buildHierarchy; add insertSemanticNeighbors call; extend IngestResult with volumes/shelves - Tests: 11 HierarchyBuilder tests + 8 FastNeighborInsert tests (230 total pass) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- cortex/OpenTSPSolver.ts: greedy nearest-neighbor open-path TSP heuristic with deterministic start (lex smallest node) and tiebreaker - cortex/MetroidBuilder.ts: dialectical probe builder selecting m1 (thesis) and m2 (antithesis medoid) with Matryoshka dimensional unwinding across standard tiers [32,64,128,256,512,768,1024,2048]; computes frozen synthesis centroid c - cortex/KnowledgeGapDetector.ts: detectKnowledgeGap + buildCuriosityProbe with deterministic SHA-256 probeId - cortex/QueryResult.ts: add coherencePath, metroid, knowledgeGap fields - cortex/Query.ts: populate new QueryResult fields with flat-query defaults - 32 new tests across OpenTSPSolver, MetroidBuilder, KnowledgeGapDetector Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add cortex/Ranking.ts: rankPages/rankBooks/rankVolumes/rankShelves
use cosine similarity against entity representative vectors;
spillToWarm('page') scores the full corpus as fallback
- Rewrite cortex/Query.ts (P1-E1): full dialectical orchestrator
- HOT path: rankPages() over resident hotpath entries
- Warm spill: spillToWarm('page') when hot path is insufficient
- buildMetroid() with book medoid + page candidates
- detectKnowledgeGap() from metroid result
- getInducedNeighborSubgraph() + solveOpenTSP() for coherence path
- queryHitCount increment + runPromotionSweep()
- QueryResult now fully populated (coherencePath, metroid, knowledgeGap)
- Add tests/cortex/Ranking.test.ts: 12 tests covering empty inputs,
cosine scoring, descending order, topK, spillToWarm all tiers
- Update tests/cortex/Query.test.ts: add assertions for new fields
(coherencePath, metroid, knowledgeGap); preserve all existing
behavioral checks; update describe label to reflect new orchestrator
All 274 tests pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tor, P1-B Ranking, P1-E Query rewrite, P1-F integration tests Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Implements the v0.5 (P1) “hierarchical + dialectical memory” slice by adding hierarchy construction (Pages→Books→Volumes→Shelves), semantic neighbor graph storage/retrieval, dialectical probing (Metroid + knowledge gap), coherence path derivation (open TSP), and updated query orchestration, alongside substantial new unit/integration test coverage.
Changes:
- Adds hierarchy builder + semantic neighbor insertion to ingest, with IndexedDB schema updates for the neighbor graph.
- Introduces cortex modules for ranking, dialectical Metroid construction, knowledge gap detection, and coherence path solving; rewrites
cortex/query. - Adds/updates tests to cover hierarchy persistence, neighbor graph behavior, ranking/query behavior, and knowledge gap signaling.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/IngestQuery.test.ts | Adds v0.5 integration tests for hierarchy, neighbors, Williams bound, knowledge-gap signaling. |
| tests/hippocampus/HierarchyBuilder.test.ts | New unit tests for hierarchy building + persistence + hotpath admission. |
| tests/hippocampus/FastNeighborInsert.test.ts | New unit tests for semantic neighbor insertion behavior and constraints. |
| tests/cortex/Ranking.test.ts | New unit tests for ranking and warm spill behavior. |
| tests/cortex/Query.test.ts | Updates query tests for new QueryResult fields and dialectical behavior. |
| tests/cortex/OpenTSPSolver.test.ts | New unit tests for deterministic greedy open-path TSP. |
| tests/cortex/MetroidBuilder.test.ts | New unit tests for Metroid construction + determinism + Matryoshka behavior. |
| tests/cortex/KnowledgeGapDetector.test.ts | New unit tests for knowledge gap detection and curiosity probe creation. |
| tests/SalienceEngine.test.ts | Updates mock MetadataStore to renamed neighbor-graph APIs. |
| tests/Persistence.test.ts | Updates persistence tests to renamed neighbor-graph types/APIs. |
| storage/IndexedDbMetadataStore.ts | Bumps DB version; renames neighbor store to neighbor_graph; renames APIs. |
| hippocampus/Ingest.ts | Integrates hierarchy building + semantic neighbor insertion into ingest pipeline. |
| hippocampus/HierarchyBuilder.ts | New hierarchy builder (books/volumes/shelves) + prototype vector creation. |
| hippocampus/FastNeighborInsert.ts | New semantic neighbor insertion implementation + dirty-volume recalc flagging. |
| cortex/Ranking.ts | New ranking functions for pages/books/volumes/shelves + warm spill for pages. |
| cortex/QueryResult.ts | Extends query result schema with coherencePath/metroid/knowledgeGap fields. |
| cortex/Query.ts | Rewrites query orchestration to use ranking→metroid→gap→subgraph→TSP pipeline. |
| cortex/OpenTSPSolver.ts | New deterministic greedy open-path TSP heuristic over neighbor subgraph. |
| cortex/MetroidBuilder.ts | New Metroid builder with Matryoshka unwinding and centroid freezing. |
| cortex/KnowledgeGapDetector.ts | New knowledge gap detection + curiosity probe builder. |
| core/types.ts | Renames Metroid neighbor graph types/APIs to SemanticNeighbor equivalents. |
| const pageChunks = chunkArray(pageIds, PAGES_PER_BOOK); | ||
| const books: Book[] = []; | ||
|
|
||
| for (const chunk of pageChunks) { | ||
| const sortedChunk = [...chunk].sort(); | ||
| const bookId = await hashText(sortedChunk.join("|")); | ||
|
|
||
| const chunkVectors = chunk.map((id) => { | ||
| const idx = pageIds.indexOf(id); | ||
| return pageVectors[idx]; | ||
| }); | ||
|
|
There was a problem hiding this comment.
@copilot Also verify prev/next edges are added to nodes that follow one another directly from slicing.
There was a problem hiding this comment.
Done in de785cd. HierarchyBuilder.buildHierarchy now inserts SemanticNeighbor edges between every consecutive pair of pages within each book slice — both the forward (A→B) and reverse (B→A) edges — using the actual cosine similarity. These document-order adjacency edges bypass the cosine-distance cutoff (adjacent text chunks of the same source are always related) but still respect a per-direction degree cap (16). A Map<Hash, Float32Array> was also introduced to replace the O(n²) indexOf calls. The FastNeighborInsert test fixture was updated to build pages directly without going through ingestText/buildHierarchy, keeping those tests isolated from the adjacency-edge insertion.
| const chunkVectors = chunk.map((id) => { | ||
| const idx = pageIds.indexOf(id); | ||
| return pageVectors[idx]; | ||
| }); | ||
|
|
||
| const medoidIdx = selectMedoidIndex(chunkVectors); | ||
| const medoidPageId = chunk[medoidIdx]; | ||
|
|
||
| const book: Book = { bookId, pageIds: chunk, medoidPageId, meta: {} }; | ||
| await metadataStore.putBook(book); | ||
| books.push(book); | ||
| } | ||
|
|
||
| await runPromotionSweep(books.map((b) => b.bookId), metadataStore, policy); | ||
|
|
||
| // ------------------------------------------------------------------------- | ||
| // Level 2: Books → Volumes | ||
| // ------------------------------------------------------------------------- | ||
| const bookChunks = chunkArray(books, BOOKS_PER_VOLUME); | ||
| const volumes: Volume[] = []; | ||
|
|
||
| for (const bookChunk of bookChunks) { | ||
| const sortedBookIds = bookChunk.map((b) => b.bookId).sort(); | ||
| const volumeId = await hashText(sortedBookIds.join("|")); | ||
|
|
||
| const medoidVectors = bookChunk.map((b) => { | ||
| const idx = pageIds.indexOf(b.medoidPageId); | ||
| return pageVectors[idx]; | ||
| }); |
There was a problem hiding this comment.
@copilot Ok I agree with this, just make sure to fix it using your best judgement and update the DESIGN.md to reflect this design decision. Insertion needs to be fast and lightweight. Daydreaming exists to find connections we never noticed before.
There was a problem hiding this comment.
Fixed in b2fd983. The Map<Hash, Float32Array> (O(1) lookups) was already landed in the previous commit. DESIGN.md now explicitly documents the fast/lightweight ingest strategy: only document-order adjacency edges are created at ingest time using O(1) precomputed maps, and the Daydreamer is responsible for discovering the semantic cross-connections we never noticed before via its idle-pass graph walks.
|
|
||
| if (oppositeSet.length === 0) return null; | ||
|
|
||
| const medoidIdx = findMedoidIndex(oppositeSet.map((s) => s.candidate.embedding)); |
There was a problem hiding this comment.
@copilot Use your best judgement to resolve the discrepancy please.
There was a problem hiding this comment.
Fixed in b2fd983. searchM2 now calls findMedoidIndex(oppositeSet.map((s) => s.candidate.embedding.slice(protectedDim))) — the medoid is selected over the free-dimension slices only, matching the scoring used to build the opposite set.
…ice pages in HierarchyBuilder Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
|
@copilot Apparently the PR touched on some P0 issues that were being worked on concurrently. As a result there has been drift on main and this PR has merge conflicts. Rebase to head main and then roll forward applying the changes that still make sense in light of the higher priority P0 issues that were recently closed. Sorry about that! |
…move vectorBackend, ONE Book per ingest, DESIGN.md update Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
…e ARCHITECTURE-REVIEW.md and close-legacy-issues.yml Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
Done in dc04d6f. The branch is now aligned with main's HEAD (619374d):
All 280 tests pass, build and lint clean. |
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.