@hviana/sema 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/AGENTS.md +16 -7
  2. package/dist/src/mind/learning.js +11 -12
  3. package/dist/src/mind/mind.js +4 -4
  4. package/dist/src/mind/types.d.ts +10 -15
  5. package/dist/src/store.d.ts +10 -10
  6. package/dist/src/store.js +5 -5
  7. package/docs/INDEX.md +62 -59
  8. package/docs/INVARIANTS.md +36 -18
  9. package/docs/PHILOSOPHY.md +317 -0
  10. package/docs/architecture/bounded-reads.md +31 -71
  11. package/docs/architecture/caches.md +61 -81
  12. package/docs/architecture/closure.md +88 -107
  13. package/docs/architecture/commonality.md +47 -38
  14. package/docs/architecture/cost-model.md +57 -79
  15. package/docs/architecture/determinism.md +43 -55
  16. package/docs/architecture/evidence.md +158 -235
  17. package/docs/architecture/exact-vs-approximate.md +41 -35
  18. package/docs/architecture/factored-machinery.md +34 -20
  19. package/docs/architecture/fold-contract.md +110 -118
  20. package/docs/architecture/halo-sketch.md +105 -96
  21. package/docs/architecture/match-project.md +51 -42
  22. package/docs/architecture/mechanism-market.md +87 -91
  23. package/docs/architecture/memoization.md +60 -74
  24. package/docs/architecture/meter.md +37 -47
  25. package/docs/architecture/saturation.md +75 -101
  26. package/docs/architecture/store.md +118 -99
  27. package/docs/architecture/thresholds.md +66 -73
  28. package/docs/failures/tempting-but-wrong.md +139 -165
  29. package/docs/harness/gates.md +27 -32
  30. package/docs/mechanisms/alu.md +22 -69
  31. package/docs/mechanisms/cast.md +76 -71
  32. package/docs/mechanisms/confluence.md +22 -29
  33. package/docs/mechanisms/cover.md +58 -66
  34. package/docs/mechanisms/extraction.md +33 -37
  35. package/docs/mechanisms/prefix-completion.md +36 -39
  36. package/docs/mechanisms/recall.md +60 -53
  37. package/docs/mechanisms/reference.md +63 -49
  38. package/jsr.json +1 -1
  39. package/package.json +1 -1
  40. package/src/alu/README.md +90 -298
  41. package/src/derive/README.md +94 -256
  42. package/src/mind/learning.ts +11 -12
  43. package/src/mind/mind.ts +4 -4
  44. package/src/mind/types.ts +10 -15
  45. package/src/rabitq-ivf/README.md +11 -8
  46. package/src/store.ts +5 -5
@@ -1,68 +1,75 @@
1
- # Recall — Nearest Stored Form
1
+ # Recall — The Nearest Stored Form
2
2
 
3
- Recall resonates the whole query's gist against the content index and grounds
4
- the nearest learned form. Resonance proposes; bytes decide.
3
+ `recall` answers with the continuation of the stored form nearest the question.
4
+ Resonance proposes, and bytes decide (`src/mind/mechanisms/recall.ts`). Its
5
+ tiers degrade in order, and each one is priced as what it is. A tier that only
6
+ resembles accounts for little, so anything that explains more beats it.
5
7
 
6
- ## Gist and budget
8
+ ## Supply and budget
7
9
 
8
- Query gist is `pre.guide`; the single top-k read is `pre.resonance()` shared
9
- across the response. `Precomputed.k = 2·recallQueryK` tiers 0b/1/2/3 through it;
10
- the last tier re-folds bytes.
10
+ All tiers read the response's single top-`k` resonance (`pre.resonance()`,
11
+ `k = 2·recallQueryK`), guided by the query gist. The last tier re-folds the
12
+ hit's bytes instead of trusting its estimate.
11
13
 
12
- ## Tiers (degrading)
14
+ ## Tiers
13
15
 
14
- | Tier | Name | Gate | Action |
15
- | ---- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
16
- | 0 | Exact identity | `pre.queryResolved` exists | Reverse-recall (`reverseContext`) to best-resonating predecessor at `STEP` |
17
- | 0b | RC8 argument binding | One maximal `≥2W` edge-source constituent, no substantial `≥2W` form outside it | `follow` its continuation; refuses if result is a subspan of the query |
18
- | 1 | Clean resonance | `score ≥ identityBar(D,W,len)` per hit | `project` hit; restating hits (bytes or `canon`-equivalent) only via reverse-recall |
19
- | 2 | Scaffolding-dominated | `score ≥ significanceBar(D)` and consensus-climb anchor clears `consensusFloor(N)` or `dominates(breadth,1) && peak>ln2`, and query is not all-scaffolding | `project` anchor at `CONCEPT`; refuses if continuation voices the anchor's displaced filler or is a query subspan |
20
- | 3 | Last resort + bridge | Query-relative fraction `max(0,cos−sig)·√(lenG/lenQ) ≥ reachThreshold(W)` | Best grounded `project` hit at `STEP` |
16
+ | Tier | Name | Gate | Action |
17
+ | ---- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
18
+ | 0 | exact identity | the question resolves | reverse-recall to its best-resonating predecessor, at `STEP` |
19
+ | 0b | argument binding | one maximal recognised constituent of at least `2W` that is an edge source, with no substantial form outside it. Fragments that answer other questions are set aside first. When the pick would otherwise be blind, the climb is asked first | `follow` its continuation, guided by the whole question |
20
+ | 1 | clean resonance | per hit, `score ≥ identityBar(D, W, len)` | `project` the hit. A hit that restates the question goes only through reverse-recall |
21
+ | — | an argument held under the equivalence | no argument recognised, and a canonical index present | the climb's points that the question canonically contains bind as arguments (`evidence.md`) |
22
+ | 2 | scaffolding-dominated | resonance `≥ significanceBar`; the climb's anchor clears `consensusFloor(N)` (or is broad with a peak above `ln 2`); the question is not all scaffolding | `project` the anchor at `CONCEPT` |
23
+ | 3 | last resort | the share of the question the grounding explains, `max(0, cos − sig)·√(lenG/lenQ) ≥ reachThreshold(W)` | `project` the best grounded hit, at `STEP` |
24
+ | 3b | substitution bridge | only after every gist tier failed (below) | align and substitute |
21
25
 
22
- W = `maxGroup` (river window); bars from `src/geometry.ts`.
26
+ **Tier 2 refuses three things.** Each would voice the anchor's own occupant as
27
+ the asker's:
28
+
29
+ - a continuation that voices the anchor's displaced filler
30
+ (`voicesDisplacedFiller`);
31
+ - a continuation that is a subspan of the question;
32
+ - an anchor that is a co-instance of the question (`evidence.md`).
33
+
34
+ Putting the asker's referent in that place is `reference`'s job, because it
35
+ needs the corpus's own evidence of carriage.
23
36
 
24
37
  ## Echo — the refusing tail
25
38
 
26
- If no tier grounded, the exact cosine of the top hit is re-folded (`gistOf` on
27
- its bytes). It uses that exact value in the same chance-corrected fraction —
28
- never the RaBitQ estimate. Below `reach` → silence; restating → silence;
29
- otherwise the hit's own bytes are returned as an ungrounded echo.
30
-
31
- ## Provenance
32
-
33
- Grounded answers carry `recall`; the echo carries `recall-echo` (`echoed: true`
34
- on `RecallResult`); it declares `used: ∅`. Consumers distinguish a continuation
35
- through learned edges from a near-identity echo.
36
-
37
- ## Substitution bridge — refusal-path only (`src/mind/bridge.ts`)
38
-
39
- Runs only after every gist tier failed, reusing the same top-k proposals (the
40
- bridge's cap is `2·recallQueryK`; every proposal is byte-verified). A candidate
41
- context is byte-aligned around the rarest stored W-windows. A mismatch becomes a
42
- corroborated substitution only when its query span is corpus-attested (every
43
- W-window stored, one reused ≥2 containers), its geometry clears
44
- `conceptThreshold(D)` or its halo clears `significanceBar(D)`, its frame is
45
- unanimous, and the raw gap is length-balanced. Coverage must dominate the query
46
- and no dismissed gap may hide known content (`dismissedKnownContent` gate). Cost
47
- is `CONCEPT` per substitution plus `STEP`; accounted spans include matched and
48
- substituted ranges (so a 28/29-byte paraphrase is not charged `PASS` per
49
- substituted byte — the double-charge that let `cast` outbid the bridge).
50
- Zero-substitution identity bridges carry `complete: true` (the whole read-out);
51
- substituted bridges do not.
52
-
53
- Scaffolding-only queries abstain: when every window that could anchor is
54
- saturated (corpus-global scaffolding, `allWindowsAreScaffolding`), the bridge
55
- returns nothing — one substituted word cannot carry the load.
39
+ When no tier grounds, the top hit's exact cosine is recomputed from its bytes
40
+ and read with the same chance-corrected fraction. The outcome is one of two:
41
+
42
+ - **Silence,** when the fraction is below reach, or when the hit restates the
43
+ question.
44
+ - **An echo,** otherwise: the hit's own bytes, labelled `recall-echo` and
45
+ declaring `used: ∅`. It tells the asker that the answer is near, not derived.
46
+
47
+ ## The substitution bridge — refusal path only (`src/mind/bridge.ts`)
48
+
49
+ The bridge aligns a candidate around the rarest stored windows. A mismatch
50
+ becomes a corroborated substitution only when all of these hold:
51
+
52
+ - the question's span is attested in the corpus;
53
+ - the geometry clears `conceptThreshold`, or the halo clears `significanceBar`;
54
+ - the frame is unanimous;
55
+ - the gap is balanced in length.
56
+
57
+ Coverage must dominate the question, and no dismissed gap may hide known content
58
+ (`dismissedKnownContent`). Each substitution costs `CONCEPT`, and the
59
+ substituted spans are accounted. A question made only of scaffolding abstains,
60
+ because one substituted word cannot carry it. A zero-substitution identity
61
+ bridge is `complete`.
56
62
 
57
63
  ## Cost
58
64
 
59
- Tiers 0/1/3 price `STEP` (one hop); tier 2 and the bridge price `CONCEPT` per
60
- substitution/scaffold step. Mechanism `floor` is `STEP`; weight is
61
- `moves + PASS·unaccounted`.
65
+ Tiers 0, 0b, 1 and 3 cost `STEP`. Tier 2 and the bridge cost `CONCEPT` per
66
+ substitution or scaffolding step. The floor is `STEP`.
62
67
 
63
68
  ## Pins
64
69
 
65
- - `test/03-recall.test.mjs` — exact identity and reverse-recall
66
- - `test/16-bridge.test.mjs` — corroborated substitutions
67
- - `test/73-scaffolding-only-bridge-abstains.test.mjs` — scaffolding-only queries
68
- stay silent
70
+ - `test/03` — exact identity and reverse-recall.
71
+ - `test/16`, `test/56` — corroborated substitutions, and the bridge's admission
72
+ by identity.
73
+ - `test/73` — a question made only of scaffolding stays silent.
74
+ - `test/154.6`, `test/154.8` — a stranger fragment is not bound; an argument
75
+ held only under the equivalence binds.
@@ -1,58 +1,72 @@
1
- # Reference — Voicing a Slot with the Asker's Bytes
2
-
3
- Reference voices a slot of a learned frame with the bytes the asker supplied in
4
- that position — asserting _position_, not equivalence. The bytes are the
5
- asker's, so voicing them cannot fabricate corpus knowledge; the fabricable claim
6
- is the _relation_ about them, which the licence withholds.
7
-
8
- ## Matcher — `frameSlots` inventory
9
-
10
- The shared matcher is `frameSlots` (`src/mind/match.ts`) via
11
- `Precomputed.frames()`.
12
-
13
- - Seeded at origin `(0,0)`, `alignAround` finds common runs (seed `W`) then
14
- sweeps both directions; each gap is contracted by `contractGap` to its varying
15
- core (shared prefix/suffix stripped) and tagged
16
- `substitution | insertion | deletion`.
17
- - `frameSlots` **reports, never judges**: every gap (any kind, any size), sorted
18
- by `qs`, plus `covered` (shared bytes) and `matched` spans. No gate is applied
19
- there.
20
-
21
- ## Gate — reference elects and licences; matcher does not
22
-
23
- All voicing gates belong to the **consumer**
24
- (`src/mind/mechanisms/reference.ts`), not the matcher. A shared layer that
25
- refused on their behalf would be reference-shaped and hide most real pairings.
26
-
27
- - **Election:** `electFrame` groups inventory by full slot signature
28
- (`qs:qe,...`) and keeps the modal group — one frame, not one slot.
29
- - **Carriage licence:** `carriesFillers` —
30
- `substituteAll(contA, fillersA→fillersB) == contB` byte-exact, all slots
31
- simultaneously (longest needle first). Constant continuations pass vacuously;
32
- filler-dependent content is refused.
33
- - **Four voicing gates** (in `voiceable` + caller):
34
- 1. frame `dominates` query (`covered > |query|/2`);
35
- 2. every slot reaches one window `W` on _both_ sides;
36
- 3. no insertion/deletion (substitutions only);
37
- 4. fillers pairwise distinct. Additional: referents pairwise distinct and no
38
- slot inside `answeredSpans`.
39
-
40
- Matched frame + every slot is `accounted`; `complete: true`.
1
+ # Reference — Voice a Slot With the Asker's Bytes
41
2
 
42
- ## Cost
3
+ `reference` learns a frame from worked examples and voices its slot with the
4
+ bytes the asker put in that position (`src/mind/mechanisms/reference.ts`). It
5
+ asserts _position_ ("this is the thing you named, where the corpus keeps one"),
6
+ not equivalence. The voiced bytes are the asker's, so they cannot fabricate
7
+ corpus knowledge. What can be fabricated is the relation claimed about them, and
8
+ the licence exists to withhold that.
9
+
10
+ The substitution bridge refuses this shape, and is right to. A substitution
11
+ asserts that two spans mean the same, which no corpus can corroborate for bytes
12
+ it has never seen.
13
+
14
+ ## Matcher — the frame inventory
15
+
16
+ `Precomputed.frames()` reads the ranked candidates as instances of the
17
+ question's own frame, through `frameSlots`, which reports and elects nothing
18
+ (`match-project.md`).
19
+
20
+ Its supply is the shared top-`k` resonance, so a frame the corpus instantiates
21
+ only once within `k` is out of reach. Measured on the trained store,
22
+ `How do you say 'flurbish' in French?` finds one instance of its frame in the
23
+ top 24, so `reference` abstains. Widening the supply is not the fix: abstaining
24
+ on thin evidence is.
25
+
26
+ ## Election and voicing gates
43
27
 
44
- `moves = STEP·slots + STEP` (one binding per slot + one edge follow). Not
45
- `CONCEPT` — byte identity, not halo. `scaffolding` is never reported; a referent
46
- is explained, not carried for lack of explanation.
28
+ `electFrame` keeps the modal group of instances that place the question's slots
29
+ alike. It needs at least `MIN_INSTANCES = 2`, because one alignment agrees with
30
+ nothing. Each instance must also be voiceable:
31
+
32
+ 1. the frame dominates the question, covering more than half of it;
33
+ 2. every slot reaches one window `W` on both sides;
34
+ 3. substitutions only, with no insertion or deletion;
35
+ 4. the fillers are pairwise distinct, the referents are distinct, and no slot
36
+ lies inside an already answered span.
37
+
38
+ ## The licence — what a new referent may inherit
39
+
40
+ Each instance's continuation is followed, one at a time, because refusal is the
41
+ common outcome and usually comes on the second instance. Two checks apply:
42
+
43
+ - **Co-variation.** `carriesFillers` requires
44
+ `substituteAll(contA, fillersA → fillersB) == contB`, byte for byte, for all
45
+ slots at once. Content that depends on which filler stands in the slot is
46
+ refused.
47
+ - **A fact filed under a filler is not a carriage.** A continuation that does
48
+ not vary passes co-variation vacuously, and coincidence lives there. If an
49
+ instance's answer is a continuation of its own filler, it is something the
50
+ corpus knows _about_ that filler. Two people born in Wellington once gave an
51
+ unknown `Zorblax` the same birthplace. `Run gcc hello.c` is filed under the
52
+ question alone, so it still carries.
53
+
54
+ ## Cost
47
55
 
48
- `floor` is `STEP+STEP`, investment-disciplined before touching `frames()`.
56
+ `moves = STEP · slots + STEP`: one binding per slot and one edge followed. It is
57
+ not `CONCEPT`, because the reading is byte identity, not halo. The matched frame
58
+ and every slot are `accounted`, the answer is `complete`, and no scaffolding is
59
+ reported. The floor is `2·STEP`, checked with `worthRunning` before `frames()`
60
+ is touched.
49
61
 
50
62
  ## Provenance
51
63
 
52
- `provenance: "reference"` with trace steps `bindReferent` / `referenceLicence`.
64
+ `reference`, with the trace steps `bindReferent` and `referenceLicence`.
53
65
 
54
66
  ## Pins
55
67
 
56
- - `test/76-reference-binding` — inventory vs gate split, carried/absorbed/
57
- refused, multi-slot licence, `complete` and answered-span guard.
58
- - `test/76-type-level-company` — type-level halo company underpinning.
68
+ - `test/76-reference-binding` — the split between inventory and gate; carried,
69
+ absorbed and refused frames; the multi-slot licence; `complete`; the guard on
70
+ answered spans; a fact filed under its filler is no carriage.
71
+ - `test/76-type-level-company` — the halo company by type that the inventory's
72
+ supply relies on.
package/jsr.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://jsr.io/schema/config-file.v1.json",
3
3
  "name": "@hviana/sema",
4
- "version": "0.9.3",
4
+ "version": "0.9.5",
5
5
  "exports": "./src/index.ts"
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hviana/sema",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Sema: a non-parametric, instance-based reasoning system.",
5
5
  "repository": {
6
6
  "type": "git",