Skip to content

Commit be34986

Browse files
Copilotdevlux76
andcommitted
docs: clarify FastNeighborInsert algorithm, edge-role invariants, and Query.ts rework scope
PLAN.md: - FastNeighborInsert row: use Williams-cutoff distance (not K), lazy Daydreamer reconnection, cosine=discovery+Bayesian vs Hebbian=TSP traversal; DESIGN.md cross-ref - Query.ts/QueryResult.ts: status "Needs Rework"; existing flat top-K code is superseded TODO.md: - P1-C1: neighbors found within Williams-cutoff distance; Daydreamer builds additional edges lazily; edge-role invariant (SemanticNeighbor.cosineSimilarity vs edges_hebbian) - P1-C3: add test that FastNeighborInsert does NOT create Hebbian edges - P1-E: "Rewrite" not "Upgrade"; note flat-scoring code path is fully superseded; add Hebbian edge traversal in P1-E1; recommended order updated DESIGN.md: - SemanticNeighbor: add edge-role distinction table; remove misleading "TSP-ready" comment - SemanticNeighborSubgraph: inline note that TSP uses Hebbian weights for tour traversal - Incremental Strategy: Williams-cutoff distance; Daydreamer lazy reconnection Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
1 parent cda985c commit be34986

3 files changed

Lines changed: 41 additions & 15 deletions

File tree

DESIGN.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,28 @@ Sparse radius-graph edge connecting pages with high cosine similarity. Used for
434434

435435
> **Note:** The current codebase names this type `MetroidNeighbor` — this is an architectural naming error introduced by early conceptual drift. The correct term is `SemanticNeighbor` (or equivalent). A code-level rename is tracked in the TODO. The edge is a proximity concept, not a Metroid concept.
436436
437+
**Critical distinction — two edge types, two roles:**
438+
439+
| Edge type | Storage | Role |
440+
|-----------|---------|------|
441+
| `SemanticNeighbor` | `neighbor_graph` IDB store | Neighbor discovery during ingest; Bayesian belief updates |
442+
| Hebbian edge (`Edge`) | `edges_hebbian` IDB store | TSP tour traversal distance; LTP/LTD strengthening/decay |
443+
444+
`SemanticNeighbor.cosineSimilarity` drives:
445+
- Which pages become neighbors during `FastNeighborInsert` (Williams-cutoff distance, not a fixed K)
446+
- Bayesian belief score updates for the retrieved page set
447+
448+
Hebbian `Edge.weight` drives:
449+
- The distance metric used by `OpenTSPSolver` when ordering pages into a coherent narrative path
450+
- Strength of connection for LTP/LTD during Daydreamer consolidation
451+
452+
These two edge types must **never** be conflated or substituted for one another.
453+
437454
```typescript
438455
interface SemanticNeighbor {
439456
neighborPageId: Hash;
440457
cosineSimilarity: number;
441-
distance: number; // 1 - cosineSimilarity (TSP-ready)
458+
distance: number; // 1 - cosineSimilarity; used for subgraph edge weight
442459
}
443460
```
444461

@@ -450,6 +467,9 @@ Induced subgraph for BFS-based coherence path expansion.
450467
```typescript
451468
interface SemanticNeighborSubgraph {
452469
nodes: Hash[];
470+
// distance: 1 - cosineSimilarity; used for BFS expansion candidate selection.
471+
// OpenTSPSolver uses Hebbian edge weights (from edges_hebbian) as the tour
472+
// traversal distance to determine how far to walk — not these cosine distances.
453473
edges: { from: Hash; to: Hash; distance: number }[];
454474
}
455475
```
@@ -556,7 +576,9 @@ Rather than returning nearest neighbors by similarity, Cortex traces a coherent
556576
7. **Mark Dirty** — Flag volumes for full recalc by Daydreamer
557577

558578
**Incremental Strategy:**
559-
Fast local semantic neighbor insertion keeps query-time latency low. Full neighborhood recalculation is deferred to idle Daydreamer passes. Hotpath admission runs at ingest time for new pages and hierarchy prototypes.
579+
Fast local semantic neighbor insertion keeps ingest-time latency low. At ingest time, only the initial forward and reverse edges are created — neighbors are selected by cosine similarity within Williams-cutoff **distance** (not a fixed K; the cutoff is derived from `HotpathPolicy`). On degree overflow, the lowest-cosine-similarity neighbor is evicted.
580+
581+
Full cross-edge reconnection is intentionally deferred: Daydreamer walks the graph during idle passes to build additional edges, strengthening or pruning connections via LTP/LTD. This avoids a full graph recalculation on every insert while still converging to a well-connected graph over time. Hotpath admission runs at ingest time for new pages and hierarchy prototypes.
560582

561583
## Consolidation Design
562584

PLAN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ This document tracks the implementation status of each major module in CORTEX. I
8181
| Page Builder | ✅ Complete | `hippocampus/PageBuilder.ts` | Builds signed `Page` entities with `contentHash`, `vectorHash`, `prevPageId`/`nextPageId` linkage; covered by `tests/hippocampus/PageBuilder.test.ts` |
8282
| Ingest Orchestrator | 🟡 Partial | `hippocampus/Ingest.ts` | `ingestText()` implemented: chunk → embed → persist pages + PageActivity → create Book → run hotpath promotion sweep. **Missing:** hierarchy building (Volume/Shelf), semantic neighbor insertion. |
8383
| Hierarchy Builder | ❌ Missing | `hippocampus/HierarchyBuilder.ts` (planned) | Construct/update Books, Volumes, Shelves; attempt tier-quota hotpath admission for each level's medoid/prototype; Williams-derived fanout bounds; trigger split via ClusterStability when bounds exceeded |
84-
| Fast Semantic Neighbor Insert | ❌ Missing | `hippocampus/FastNeighborInsert.ts` (planned) | Incremental semantic neighbor graph update; max degree derived from HotpathPolicy (not hardcoded K); evict lowest-cosine-similarity neighbor on degree overflow; check new page for hotpath admission. **Note:** Not to be confused with Metroid construction, which is a CORTEX retrieval concern. |
84+
| Fast Semantic Neighbor Insert | ❌ Missing | `hippocampus/FastNeighborInsert.ts` (planned) | Cosine-nearest neighbors within Williams-cutoff distance (not fixed K). Degree overflow evicts lowest-cosine-similarity neighbor. Initial edges only at ingest; Daydreamer builds additional edges lazily. `SemanticNeighbor.cosineSimilarity` drives discovery + Bayesian updates; Hebbian weights (separate) drive TSP traversal. See DESIGN.md §Graph Structures for the full edge-role invariant. |
8585

8686
**Hippocampus Status:** 2.5/5 complete (50%)
8787

@@ -100,8 +100,8 @@ This document tracks the implementation status of each major module in CORTEX. I
100100
| Seed Selection | ❌ Missing | `cortex/SeedSelection.ts` (planned) | Threshold-based top-k page selection from ranking output |
101101
| Subgraph Expansion | 🟡 Partial | `storage/IndexedDbMetadataStore.ts` (`getInducedMetroidSubgraph` — to be renamed `getInducedNeighborSubgraph`) | BFS expansion implemented in storage layer; needs dynamic Williams bounds; needs orchestration wrapper |
102102
| Open TSP Solver | ❌ Missing | `cortex/OpenTSPSolver.ts` (planned) | Dummy-node open-path heuristic for coherent ordering |
103-
| Query Orchestrator | 🟡 Partial | `cortex/Query.ts` | `query()` implemented: hotpath-first scoring → warm/cold spill → PageActivity update → promotion sweep. **Missing:** MetroidBuilder, dialectical zone scoring, subgraph expansion, TSP coherence, query cost meter. |
104-
| Result DTO | 🟡 Partial | `cortex/QueryResult.ts` | Minimal DTO: `pages`, `scores`, `metadata`. **Missing:** `coherencePath`, `metroid`, `knowledgeGap`, `provenance` fields. |
103+
| Query Orchestrator | 🟡 Needs Rework | `cortex/Query.ts` | Flat top-K scoring implemented (hotpath-first → warm/cold spill → PageActivity update → promotion sweep). **Must be substantially reworked** to implement the full dialectical pipeline: replace flat scoring with hierarchical resident-first ranking, add MetroidBuilder, dialectical zone scoring (thesis/antithesis/synthesis), subgraph expansion with dynamic Williams bounds, TSP coherence path, and query cost meter. The existing implementation does not use Hebbian edges or cosine-similarity-bounded subgraph expansion; it is a functional placeholder only. |
104+
| Result DTO | 🟡 Needs Rework | `cortex/QueryResult.ts` | Minimal DTO (`pages`, `scores`, `metadata`). **Must be reworked** to add `coherencePath: Hash[]`, `metroid?: { m1, m2, centroid }`, `knowledgeGap?: KnowledgeGap`, and `provenance: { subgraphSize, hopCount, edgeWeights, vectorOpCost, earlyStop }`. |
105105

106106
**Cortex Status:** 1.5/9 complete (17%)
107107

TODO.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,12 @@ These items add hierarchical routing and coherent path ordering. They transform
308308
**Why:** Need a sparse semantic neighbor graph for coherent path tracing. This graph connects pages with high cosine similarity and is used for BFS subgraph expansion during retrieval. Degree must be bounded by `HotpathPolicy` to prevent unbounded graph mass growth. **This is not related to Metroid construction** — the semantic neighbor graph is a proximity concept, not a dialectical probe concept.
309309

310310
- [ ] **P1-C1:** Implement `hippocampus/FastNeighborInsert.ts`
311-
- For each new page, compute similarity to existing pages
312-
- Derive max neighbors per page from `HotpathPolicy` constant (not hardcoded K)
313-
- Insert forward edges (page → neighbors) as `SemanticNeighbor` records
314-
- Insert reverse edges (neighbors → page), respecting max degree
311+
- For each new page, find cosine-nearest neighbors within Williams-cutoff **distance** (not a fixed K); derive the cutoff radius from `HotpathPolicy` rather than a hardcoded constant
312+
- Insert forward edges (page → neighbors) as `SemanticNeighbor` records, respecting max degree
313+
- Insert reverse edges (neighbors → page), respecting max degree per direction
315314
- If a page is already at max degree, evict the neighbor with the lowest cosine similarity
315+
- Insert only initial edges at ingest time; do not attempt full cross-edge reconnection — Daydreamer walks the graph during idle passes to build additional edges (avoids full graph recalc on every insert)
316+
- **Edge role invariant:** `SemanticNeighbor.cosineSimilarity` is used for neighbor discovery and Bayesian belief updates. Hebbian edge weights (in `edges_hebbian`) are used for TSP tour traversal. These are separate edge types with separate roles; do not mix them.
316317
- Mark affected volumes as dirty for full Daydreamer recalc
317318
- After insertion, check new page for hotpath admission via `SalienceEngine`
318319

@@ -321,10 +322,11 @@ These items add hierarchical routing and coherent path ordering. They transform
321322

322323
- [ ] **P1-C3:** Add semantic neighbor insert test coverage
323324
- `tests/hippocampus/FastNeighborInsert.test.ts`
324-
- Test neighbor lists are bounded by the policy-derived max degree
325+
- Test neighbor lists are bounded by Williams-cutoff distance (not a fixed K)
325326
- Test symmetry (if A→B, then B→A)
326-
- Test that degree overflow evicts lowest-similarity neighbor, not a random one
327+
- Test that degree overflow evicts lowest-cosine-similarity neighbor, not a random one
327328
- Test that new page is considered for hotpath admission after insertion
329+
- Test that `edges_hebbian` records are NOT created by FastNeighborInsert (Hebbian is Daydreamer's concern)
328330

329331
**Exit Criteria:** Semantic neighbor graph is maintained during ingest with policy-bounded degree.
330332

@@ -420,19 +422,21 @@ These items add hierarchical routing and coherent path ordering. They transform
420422

421423
**Why:** This is the "aha" moment — return memories in natural narrative order through the resident hotpath via dialectical Metroid exploration, with dynamic, sublinear expansion bounds.
422424

423-
- [ ] **P1-E1:** Upgrade `cortex/Query.ts` (full version)
425+
> **Note on scope:** The existing `cortex/Query.ts` is a flat top-K scorer that does not use MetroidBuilder, Hebbian edge traversal, or cosine-similarity-bounded subgraph expansion. It must be **substantially reworked** — not merely extended — to implement the dialectical pipeline described below. The same applies to `cortex/QueryResult.ts`. Do not attempt to preserve the flat-scoring code path; it is superseded entirely.
426+
427+
- [ ] **P1-E1:** Rewrite `cortex/Query.ts` (full dialectical version)
424428
- Use resident-first hierarchical ranking to select topic medoid (m1)
425429
- Call `MetroidBuilder` to construct `{ m1, m2, c }`
426430
- If knowledge gap detected, include in result and continue with partial Metroid (m1 only)
427431
- Use centroid `c` as the primary scoring anchor for page selection
428432
- Derive dynamic subgraph bounds from `HotpathPolicy` (`maxSubgraphSize`, `maxHops`, `perHopBranching`)
429-
- Call `MetadataStore.getInducedNeighborSubgraph(seedPages, maxHops)` using dynamic `maxHops`
433+
- Call `MetadataStore.getInducedNeighborSubgraph(seedPages, maxHops)` using dynamic `maxHops`; traverse edges using Hebbian weights for tour distance (not cosine similarity)
430434
- Call `OpenTSPSolver.solve(subgraph)`
431435
- Return ordered page list via coherent path
432436
- **Query cost meter:** count vector operations; early-stop and return best-so-far if cost exceeds Williams-derived budget
433437
- Include provenance metadata (hop count, edge weights, subgraph size, cost, Metroid details)
434438

435-
- [ ] **P1-E2:** Upgrade `cortex/QueryResult.ts`
439+
- [ ] **P1-E2:** Rewrite `cortex/QueryResult.ts`
436440
- Add `coherencePath: Hash[]` (ordered page IDs)
437441
- Add `metroid?: { m1: Hash; m2: Hash | null; centroid: Float32Array | null }` (Metroid used for this query)
438442
- Add `knowledgeGap?: KnowledgeGap` (if antithesis discovery failed)
@@ -847,7 +851,7 @@ If you're reading this and want to know "what do I work on right now?", here's t
847851
7. **P1-M1/M2:** Implement `cortex/MetroidBuilder.ts` with Matryoshka unwinding
848852
8. **P1-N1/N2:** Implement `cortex/KnowledgeGapDetector.ts`
849853
9. **P1-D1:** Implement `cortex/OpenTSPSolver.ts`
850-
10. **P1-E1:** Upgrade `cortex/Query.ts` to full dialectical orchestrator
854+
10. **P1-E1:** Rewrite `cortex/Query.ts` to full dialectical orchestrator (substantial rework; not backward-compatible with flat top-K version)
851855

852856
---
853857

0 commit comments

Comments
 (0)