@hviana/sema 0.1.9 → 0.2.1
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.
- package/dist/example/demo.d.ts +1 -0
- package/dist/example/demo.js +39 -0
- package/dist/example/train_base.d.ts +87 -0
- package/dist/example/train_base.js +2252 -0
- package/dist/src/alphabet.d.ts +7 -0
- package/dist/src/alphabet.js +33 -0
- package/dist/src/alu/src/alu.d.ts +185 -0
- package/dist/src/alu/src/alu.js +440 -0
- package/dist/src/alu/src/expr.d.ts +61 -0
- package/dist/src/alu/src/expr.js +318 -0
- package/dist/src/alu/src/index.d.ts +11 -0
- package/dist/src/alu/src/index.js +19 -0
- package/dist/src/alu/src/kernel-arith.d.ts +16 -0
- package/dist/src/alu/src/kernel-arith.js +264 -0
- package/dist/src/alu/src/kernel-bits.d.ts +19 -0
- package/dist/src/alu/src/kernel-bits.js +152 -0
- package/dist/src/alu/src/kernel-logic.d.ts +4 -0
- package/dist/src/alu/src/kernel-logic.js +60 -0
- package/dist/src/alu/src/kernel-nd.d.ts +3 -0
- package/dist/src/alu/src/kernel-nd.js +208 -0
- package/dist/src/alu/src/kernel-numeric.d.ts +54 -0
- package/dist/src/alu/src/kernel-numeric.js +366 -0
- package/dist/src/alu/src/operation.d.ts +168 -0
- package/dist/src/alu/src/operation.js +189 -0
- package/dist/src/alu/src/parser.d.ts +221 -0
- package/dist/src/alu/src/parser.js +577 -0
- package/dist/src/alu/src/resonance.d.ts +55 -0
- package/dist/src/alu/src/resonance.js +126 -0
- package/dist/src/alu/src/text.d.ts +31 -0
- package/dist/src/alu/src/text.js +73 -0
- package/dist/src/alu/src/value.d.ts +109 -0
- package/dist/src/alu/src/value.js +300 -0
- package/dist/src/alu/test/alu.test.d.ts +1 -0
- package/dist/src/alu/test/alu.test.js +764 -0
- package/dist/src/bytes.d.ts +14 -0
- package/dist/src/bytes.js +59 -0
- package/dist/src/canon.d.ts +26 -0
- package/dist/src/canon.js +57 -0
- package/dist/src/config.d.ts +111 -0
- package/dist/src/config.js +91 -0
- package/dist/src/derive/src/deduction.d.ts +125 -0
- package/dist/src/derive/src/deduction.js +155 -0
- package/dist/src/derive/src/index.d.ts +7 -0
- package/dist/src/derive/src/index.js +11 -0
- package/dist/src/derive/src/priority-queue.d.ts +20 -0
- package/dist/src/derive/src/priority-queue.js +73 -0
- package/dist/src/derive/src/rewrite.d.ts +56 -0
- package/dist/src/derive/src/rewrite.js +100 -0
- package/dist/src/derive/src/trie.d.ts +90 -0
- package/dist/src/derive/src/trie.js +217 -0
- package/dist/src/derive/test/derive.test.d.ts +1 -0
- package/dist/src/derive/test/derive.test.js +122 -0
- package/dist/src/extension.d.ts +37 -0
- package/dist/src/extension.js +7 -0
- package/dist/src/geometry.d.ts +148 -0
- package/dist/src/geometry.js +511 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +18 -0
- package/dist/src/ingest-cache.d.ts +41 -0
- package/dist/src/ingest-cache.js +161 -0
- package/dist/src/mind/articulation.d.ts +6 -0
- package/dist/src/mind/articulation.js +99 -0
- package/dist/src/mind/attention.d.ts +72 -0
- package/dist/src/mind/attention.js +898 -0
- package/dist/src/mind/canonical.d.ts +29 -0
- package/dist/src/mind/canonical.js +88 -0
- package/dist/src/mind/graph-search.d.ts +270 -0
- package/dist/src/mind/graph-search.js +927 -0
- package/dist/src/mind/index.d.ts +5 -0
- package/dist/src/mind/index.js +5 -0
- package/dist/src/mind/junction.d.ts +95 -0
- package/dist/src/mind/junction.js +262 -0
- package/dist/src/mind/learning.d.ts +47 -0
- package/dist/src/mind/learning.js +233 -0
- package/dist/src/mind/match.d.ts +113 -0
- package/dist/src/mind/match.js +446 -0
- package/dist/src/mind/mechanisms/alu.d.ts +4 -0
- package/dist/src/mind/mechanisms/alu.js +29 -0
- package/dist/src/mind/mechanisms/cast.d.ts +35 -0
- package/dist/src/mind/mechanisms/cast.js +461 -0
- package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
- package/dist/src/mind/mechanisms/confluence.js +225 -0
- package/dist/src/mind/mechanisms/cover.d.ts +6 -0
- package/dist/src/mind/mechanisms/cover.js +179 -0
- package/dist/src/mind/mechanisms/extraction.d.ts +67 -0
- package/dist/src/mind/mechanisms/extraction.js +342 -0
- package/dist/src/mind/mechanisms/recall.d.ts +13 -0
- package/dist/src/mind/mechanisms/recall.js +235 -0
- package/dist/src/mind/mind.d.ts +273 -0
- package/dist/src/mind/mind.js +598 -0
- package/dist/src/mind/pipeline-mechanism.d.ts +142 -0
- package/dist/src/mind/pipeline-mechanism.js +213 -0
- package/dist/src/mind/pipeline.d.ts +20 -0
- package/dist/src/mind/pipeline.js +185 -0
- package/dist/src/mind/primitives.d.ts +63 -0
- package/dist/src/mind/primitives.js +251 -0
- package/dist/src/mind/rationale.d.ts +134 -0
- package/dist/src/mind/rationale.js +162 -0
- package/dist/src/mind/reasoning.d.ts +15 -0
- package/dist/src/mind/reasoning.js +162 -0
- package/dist/src/mind/recognition.d.ts +20 -0
- package/dist/src/mind/recognition.js +246 -0
- package/dist/src/mind/resonance.d.ts +23 -0
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +15 -0
- package/dist/src/mind/trace.js +73 -0
- package/dist/src/mind/traverse.d.ts +113 -0
- package/dist/src/mind/traverse.js +488 -0
- package/dist/src/mind/types.d.ts +186 -0
- package/dist/src/mind/types.js +84 -0
- package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
- package/dist/src/rabitq-ivf/src/database.js +201 -0
- package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
- package/dist/src/rabitq-ivf/src/index.js +4 -0
- package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
- package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
- package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
- package/dist/src/rabitq-ivf/src/prng.js +36 -0
- package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
- package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
- package/dist/src/sema.d.ts +31 -0
- package/dist/src/sema.js +63 -0
- package/dist/src/store-sqlite.d.ts +184 -0
- package/dist/src/store-sqlite.js +942 -0
- package/dist/src/store.d.ts +654 -0
- package/dist/src/store.js +1612 -0
- package/dist/src/vec.d.ts +31 -0
- package/dist/src/vec.js +109 -0
- package/package.json +1 -1
- package/src/mind/graph-search.ts +128 -46
- package/src/mind/mind.ts +37 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type Vec = Float32Array;
|
|
2
|
+
/** Deterministic PRNG (32-bit mixer). */
|
|
3
|
+
export declare function rng(seed: number): () => number;
|
|
4
|
+
export declare const zeros: (D: number) => Vec;
|
|
5
|
+
export declare const copy: (v: Vec) => Vec;
|
|
6
|
+
/** Random point on the unit sphere. */
|
|
7
|
+
export declare function randomUnit(D: number, rand: () => number): Vec;
|
|
8
|
+
/** target += src * scale (in place). */
|
|
9
|
+
export declare function addInto(target: Vec, src: Vec, scale?: number): Vec;
|
|
10
|
+
export declare function dot(a: Vec, b: Vec): number;
|
|
11
|
+
/** In-place normalization. */
|
|
12
|
+
export declare function normalize(v: Vec): Vec;
|
|
13
|
+
/** Resonance: 1 = same, 0 = unrelated. */
|
|
14
|
+
export declare function cosine(a: Vec, b: Vec): number;
|
|
15
|
+
/** Set vector epsilon thresholds. Called once by Mind at construction. */
|
|
16
|
+
export declare function setVecConfig(cfg: {
|
|
17
|
+
normalizeEpsilon?: number;
|
|
18
|
+
cosineEpsilon?: number;
|
|
19
|
+
}): void;
|
|
20
|
+
export interface Permutation {
|
|
21
|
+
fwd: Uint32Array;
|
|
22
|
+
inv: Uint32Array;
|
|
23
|
+
}
|
|
24
|
+
/** The keyring: one independent permutation per seat.
|
|
25
|
+
* Independent keys do not commute, so an address in a tree is the
|
|
26
|
+
* path itself — "seat 2 inside seat 1" ≠ "seat 1 inside seat 2". */
|
|
27
|
+
export declare function makeKeyring(D: number, seats: number, rand: () => number): Permutation[];
|
|
28
|
+
/** Apply permutation: out[i] = v[table[i]]. */
|
|
29
|
+
export declare function permute(v: Vec, table: Uint32Array): Vec;
|
|
30
|
+
/** Permute into existing buffer — zero allocation. */
|
|
31
|
+
export declare function permuteInto(out: Vec, v: Vec, table: Uint32Array): Vec;
|
package/dist/src/vec.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// vec.ts — vector primitives.
|
|
2
|
+
// Superposition (add), normalization (stay on the sphere),
|
|
3
|
+
// resonance (cosine), and seat binding (a keyring of fixed permutations).
|
|
4
|
+
// No weights. No gradients.
|
|
5
|
+
/** Deterministic PRNG (32-bit mixer). */
|
|
6
|
+
export function rng(seed) {
|
|
7
|
+
let s = seed >>> 0;
|
|
8
|
+
return () => {
|
|
9
|
+
s = (s + 0x6d2b79f5) >>> 0;
|
|
10
|
+
let t = s;
|
|
11
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
12
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
13
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Standard normal sample (Box–Muller). */
|
|
17
|
+
function gaussian(rand) {
|
|
18
|
+
let u = 0, v = 0;
|
|
19
|
+
while (u === 0)
|
|
20
|
+
u = rand();
|
|
21
|
+
while (v === 0)
|
|
22
|
+
v = rand();
|
|
23
|
+
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
|
|
24
|
+
}
|
|
25
|
+
export const zeros = (D) => new Float32Array(D);
|
|
26
|
+
export const copy = (v) => new Float32Array(v);
|
|
27
|
+
/** Random point on the unit sphere. */
|
|
28
|
+
export function randomUnit(D, rand) {
|
|
29
|
+
const v = zeros(D);
|
|
30
|
+
for (let i = 0; i < D; i++)
|
|
31
|
+
v[i] = gaussian(rand);
|
|
32
|
+
return normalize(v);
|
|
33
|
+
}
|
|
34
|
+
/** target += src * scale (in place). */
|
|
35
|
+
export function addInto(target, src, scale = 1) {
|
|
36
|
+
for (let i = 0; i < target.length; i++)
|
|
37
|
+
target[i] += src[i] * scale;
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
export function dot(a, b) {
|
|
41
|
+
let s = 0;
|
|
42
|
+
for (let i = 0; i < a.length; i++)
|
|
43
|
+
s += a[i] * b[i];
|
|
44
|
+
return s;
|
|
45
|
+
}
|
|
46
|
+
const norm = (v) => Math.sqrt(dot(v, v));
|
|
47
|
+
// Epsilon thresholds (settable once via setVecConfig).
|
|
48
|
+
let _normalizeEpsilon = 1e-12;
|
|
49
|
+
let _cosineEpsilon = 1e-12;
|
|
50
|
+
/** In-place normalization. */
|
|
51
|
+
export function normalize(v) {
|
|
52
|
+
const n = norm(v);
|
|
53
|
+
if (n > _normalizeEpsilon) {
|
|
54
|
+
for (let i = 0; i < v.length; i++)
|
|
55
|
+
v[i] /= n;
|
|
56
|
+
}
|
|
57
|
+
return v;
|
|
58
|
+
}
|
|
59
|
+
/** Resonance: 1 = same, 0 = unrelated. */
|
|
60
|
+
export function cosine(a, b) {
|
|
61
|
+
const na = norm(a), nb = norm(b);
|
|
62
|
+
return na > _cosineEpsilon && nb > _cosineEpsilon ? dot(a, b) / (na * nb) : 0;
|
|
63
|
+
}
|
|
64
|
+
/** Set vector epsilon thresholds. Called once by Mind at construction. */
|
|
65
|
+
export function setVecConfig(cfg) {
|
|
66
|
+
if (cfg.normalizeEpsilon !== undefined) {
|
|
67
|
+
_normalizeEpsilon = cfg.normalizeEpsilon;
|
|
68
|
+
}
|
|
69
|
+
if (cfg.cosineEpsilon !== undefined)
|
|
70
|
+
_cosineEpsilon = cfg.cosineEpsilon;
|
|
71
|
+
}
|
|
72
|
+
/** One fixed random permutation (Fisher–Yates). */
|
|
73
|
+
function makePermutation(D, rand) {
|
|
74
|
+
const fwd = new Uint32Array(D);
|
|
75
|
+
for (let i = 0; i < D; i++)
|
|
76
|
+
fwd[i] = i;
|
|
77
|
+
for (let i = D - 1; i > 0; i--) {
|
|
78
|
+
const j = Math.floor(rand() * (i + 1));
|
|
79
|
+
const t = fwd[i];
|
|
80
|
+
fwd[i] = fwd[j];
|
|
81
|
+
fwd[j] = t;
|
|
82
|
+
}
|
|
83
|
+
const inv = new Uint32Array(D);
|
|
84
|
+
for (let i = 0; i < D; i++)
|
|
85
|
+
inv[fwd[i]] = i;
|
|
86
|
+
return { fwd, inv };
|
|
87
|
+
}
|
|
88
|
+
/** The keyring: one independent permutation per seat.
|
|
89
|
+
* Independent keys do not commute, so an address in a tree is the
|
|
90
|
+
* path itself — "seat 2 inside seat 1" ≠ "seat 1 inside seat 2". */
|
|
91
|
+
export function makeKeyring(D, seats, rand) {
|
|
92
|
+
const ring = [];
|
|
93
|
+
for (let s = 0; s < seats; s++)
|
|
94
|
+
ring.push(makePermutation(D, rand));
|
|
95
|
+
return ring;
|
|
96
|
+
}
|
|
97
|
+
/** Apply permutation: out[i] = v[table[i]]. */
|
|
98
|
+
export function permute(v, table) {
|
|
99
|
+
const out = new Float32Array(v.length);
|
|
100
|
+
for (let i = 0; i < v.length; i++)
|
|
101
|
+
out[i] = v[table[i]];
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
/** Permute into existing buffer — zero allocation. */
|
|
105
|
+
export function permuteInto(out, v, table) {
|
|
106
|
+
for (let i = 0; i < v.length; i++)
|
|
107
|
+
out[i] = v[table[i]];
|
|
108
|
+
return out;
|
|
109
|
+
}
|
package/package.json
CHANGED
package/src/mind/graph-search.ts
CHANGED
|
@@ -707,52 +707,104 @@ export class GraphSearch {
|
|
|
707
707
|
return;
|
|
708
708
|
}
|
|
709
709
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
//
|
|
716
|
-
//
|
|
717
|
-
//
|
|
718
|
-
//
|
|
719
|
-
//
|
|
720
|
-
//
|
|
721
|
-
//
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
710
|
+
if (it.via) {
|
|
711
|
+
// A CHAIN hop (this form was itself reached by following an edge):
|
|
712
|
+
// read up to the hub bound — the SAME √(max(2,N)) convention {@link
|
|
713
|
+
// hubBound} in traverse.ts derives, replicated here because
|
|
714
|
+
// GraphSearch holds only a bare Store, not a MindContext — and fork
|
|
715
|
+
// across EVERY continuation. A bidirectional pair (SmolSent trains
|
|
716
|
+
// both directions) puts the back-edge to where we came from ahead of
|
|
717
|
+
// the forward edge in insertion order; a single first-inserted pick
|
|
718
|
+
// would walk the search straight into a cycle (the A*LD duplicate-key
|
|
719
|
+
// guard then dead-ends it) with no way to reach the forward edge.
|
|
720
|
+
// Forking offers every continuation as its own rule so the one that
|
|
721
|
+
// genuinely advances (not a duplicate) is still reachable.
|
|
722
|
+
const bound = Math.ceil(
|
|
723
|
+
Math.sqrt(Math.max(2, this.store.edgeSourceCount())),
|
|
724
|
+
);
|
|
725
|
+
const nx = this.store.nextFirst(it.node, bound);
|
|
726
|
+
if (nx.length) {
|
|
727
|
+
// The SAME evidence-weighted disambiguation the first hop uses
|
|
728
|
+
// (below) identifies the most-corroborated continuation. Yielding
|
|
729
|
+
// it FIRST matters: {@link lightestDerivation}'s chart keeps the
|
|
730
|
+
// FIRST rule to reach a given cost for an item and discards later
|
|
731
|
+
// arrivals at an EQUAL cost (`cost < current`, strictly) — so
|
|
732
|
+
// among same-depth sibling forks that tie in cost, the
|
|
733
|
+
// evidence-backed edge wins deterministically, never by
|
|
734
|
+
// exploration-order luck. `preferred`, when set, is necessarily
|
|
735
|
+
// an element of `nx` (chooseNext reads the identical hub-bounded
|
|
736
|
+
// set — see traverse.ts), so a plain skip-in-place suffices; no
|
|
737
|
+
// second array need be allocated to reorder it to the front.
|
|
738
|
+
const preferred = nx.length > 1
|
|
739
|
+
? this.host.chooseNext?.(it.node)
|
|
740
|
+
: undefined;
|
|
741
|
+
const fork = (node: number): Rule<GItem> => ({
|
|
742
|
+
premises: [it],
|
|
743
|
+
conclusion: { kind: "form", i: it.i, j: it.j, node, via: true },
|
|
744
|
+
// A real edge always costs STEP, whether it is the first hop or
|
|
745
|
+
// the fifth — so a chain's total cost is proportional to its
|
|
746
|
+
// length and the lightest derivation is always the SHORTEST
|
|
747
|
+
// successful one. (Charging every hop after the first for
|
|
748
|
+
// FREE, as an earlier design did, made every stopping point at
|
|
749
|
+
// any depth tie at the same cost — indistinguishable to the
|
|
750
|
+
// search, decided by whichever arrived first.)
|
|
751
|
+
cost: STEP,
|
|
752
|
+
});
|
|
753
|
+
if (preferred !== undefined) yield fork(preferred);
|
|
754
|
+
for (const c of nx) {
|
|
755
|
+
if (c !== preferred) yield fork(c);
|
|
756
|
+
}
|
|
757
|
+
// Also offer stopping HERE, at CONCEPT above whatever the chain
|
|
758
|
+
// has already cost — the same "a synonym jump is dearer than a
|
|
759
|
+
// direct edge" ordering the ladder already uses elsewhere,
|
|
760
|
+
// repurposed as "giving up early is dearer than one more real
|
|
761
|
+
// hop". A premature stop at depth D costs D·STEP + CONCEPT, so a
|
|
762
|
+
// SHORTER premature stop always beats a longer one, and a genuine
|
|
763
|
+
// fixpoint (below, costing +0) always beats any premature stop at
|
|
764
|
+
// the same depth — the search only settles here when continuing
|
|
765
|
+
// genuinely dead-ends (every fork above revisits an already-
|
|
766
|
+
// explored key) or grows costlier than giving up.
|
|
767
|
+
//
|
|
768
|
+
// The stop-here bytes are the node's OWN, as-is — NOT recompleteNode's
|
|
769
|
+
// recursive re-cover. recompleteNode re-runs the full recognition
|
|
770
|
+
// + edge/fuse search over the node's bytes, an O(node's own
|
|
771
|
+
// substructure) cost independent of chain depth; offering it at
|
|
772
|
+
// EVERY premature stop makes a query's total cost scale with how
|
|
773
|
+
// many nodes the corpus happens to interconnect here (corpus
|
|
774
|
+
// density), not with the answer's own hop count — the exact
|
|
775
|
+
// output-sensitivity the rest of this search is built to keep.
|
|
776
|
+
// Reserved below for the ONE place it is load-bearing: the true
|
|
777
|
+
// fixpoint, checked once, at the chain's actual end.
|
|
778
|
+
yield {
|
|
779
|
+
premises: [it],
|
|
780
|
+
conclusion: {
|
|
781
|
+
kind: "out",
|
|
782
|
+
i: it.i,
|
|
783
|
+
j: it.j,
|
|
784
|
+
bytes: nodeBytes(it.node),
|
|
785
|
+
cover: true,
|
|
786
|
+
rec: true,
|
|
787
|
+
node: it.node,
|
|
788
|
+
},
|
|
789
|
+
cost: CONCEPT,
|
|
790
|
+
};
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
// The chain reached a node with no WHOLE-node continuation anywhere
|
|
794
|
+
// — a genuine fixpoint, not a premature stop. Before emitting it as
|
|
795
|
+
// terminal, CONTINUE THE EXPLORATION into its own structure: a
|
|
796
|
+
// composite answer like "p1 p2" leads nowhere as a whole, yet
|
|
797
|
+
// recognising it surfaces p1, p2 — each of which continues (→ R1,
|
|
798
|
+
// R2) and recomposes into a deeper learnt form (→ FINAL). {@link
|
|
799
|
+
// recompleteNode} re-covers the node's bytes through the SAME
|
|
800
|
+
// recognition + edge/fuse machinery the top query uses (a continued
|
|
801
|
+
// graph exploration, not a re-perception), and returns the deeper
|
|
802
|
+
// completion's bytes when it genuinely leads somewhere new. Emit
|
|
803
|
+
// that; else emit the node itself as the terminal answer. This is
|
|
804
|
+
// the ONE place the recursive re-cover runs — once, at the chain's
|
|
805
|
+
// actual end, never per intermediate stop — so its cost tracks the
|
|
806
|
+
// ANSWER's own structure, not how densely the corpus interconnects
|
|
807
|
+
// the nodes passed through on the way there.
|
|
756
808
|
const deeper = this.recompleteNode(it.node);
|
|
757
809
|
yield {
|
|
758
810
|
premises: [it],
|
|
@@ -768,6 +820,36 @@ export class GraphSearch {
|
|
|
768
820
|
cost: 0,
|
|
769
821
|
};
|
|
770
822
|
} else {
|
|
823
|
+
// The FIRST hop out of a recognised site — unchanged from the
|
|
824
|
+
// original design. LIMIT 2 only senses PLURALITY (does this node
|
|
825
|
+
// have more than one learnt continuation?); the actual bounded read
|
|
826
|
+
// and evidence-weighted pick both live inside {@link
|
|
827
|
+
// Mind.chooseNext} (see traverse.ts), which floors its own hub bound
|
|
828
|
+
// at √(max(2,N)) regardless of what we read here.
|
|
829
|
+
const nx = this.store.nextFirst(it.node, 2);
|
|
830
|
+
if (nx.length) {
|
|
831
|
+
yield {
|
|
832
|
+
premises: [it],
|
|
833
|
+
conclusion: {
|
|
834
|
+
kind: "form",
|
|
835
|
+
i: it.i,
|
|
836
|
+
j: it.j,
|
|
837
|
+
node:
|
|
838
|
+
(nx.length > 1 ? this.host.chooseNext?.(it.node) : undefined) ??
|
|
839
|
+
nx[0],
|
|
840
|
+
via: true,
|
|
841
|
+
rcmp: it.rcmp,
|
|
842
|
+
},
|
|
843
|
+
// A recomposed form's continuation is FREE: the two (or more) parts
|
|
844
|
+
// were already paid for as their own rewrites, and the single
|
|
845
|
+
// consolidated span saves one cover-bridge versus leaving them
|
|
846
|
+
// split — so charging 0 here makes the grounded whole (e.g.
|
|
847
|
+
// "DE"→F) strictly beat the split ("D","E") by exactly that saved
|
|
848
|
+
// bridge, deterministically.
|
|
849
|
+
cost: it.rcmp ? 0 : STEP,
|
|
850
|
+
};
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
771
853
|
// Recognised but edge-less: borrow a concept (halo) sibling's edge. No
|
|
772
854
|
// edge and no concept means the form leads nowhere — it yields no rule, so
|
|
773
855
|
// a query of only such forms produces no derivation, and think is silent.
|
package/src/mind/mind.ts
CHANGED
|
@@ -644,6 +644,43 @@ export class Mind implements MindContext {
|
|
|
644
644
|
this.canonMemo = this.canon ? new Map() : null;
|
|
645
645
|
|
|
646
646
|
try {
|
|
647
|
+
// Seed the recognise memo with the STANDALONE recognition of the
|
|
648
|
+
// NEW turn, offset into the accumulated context. In the full-context
|
|
649
|
+
// tree, content-defined chunk boundaries shift when bytes are
|
|
650
|
+
// concatenated — foldTree no longer visits the original turn's root
|
|
651
|
+
// node, so the structural pass misses it. Perceiving the turn alone
|
|
652
|
+
// preserves intact structure. We seed ONLY the suffix (the new turn);
|
|
653
|
+
// prefix forms stay visible through the full-context recognition
|
|
654
|
+
// (they serve as context, not as questions to re-answer).
|
|
655
|
+
if (data.boundaries.length > 0) {
|
|
656
|
+
const suffixStart = data.boundaries[data.boundaries.length - 1];
|
|
657
|
+
if (suffixStart < newContext.length) {
|
|
658
|
+
const suffixBytes = newContext.subarray(suffixStart);
|
|
659
|
+
const suffixRec = recognise(this, suffixBytes);
|
|
660
|
+
const fullRec = recognise(this, newContext);
|
|
661
|
+
const seen = new Set(fullRec.sites.map((s) => `${s.start},${s.end}`));
|
|
662
|
+
const mergedSites = [...fullRec.sites];
|
|
663
|
+
for (const site of suffixRec.sites) {
|
|
664
|
+
const absStart = suffixStart + site.start;
|
|
665
|
+
const absEnd = suffixStart + site.end;
|
|
666
|
+
const key = `${absStart},${absEnd}`;
|
|
667
|
+
if (!seen.has(key)) {
|
|
668
|
+
seen.add(key);
|
|
669
|
+
mergedSites.push({
|
|
670
|
+
start: absStart,
|
|
671
|
+
end: absEnd,
|
|
672
|
+
payload: site.payload,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
data.recogniseMemo.set(latin1Key(newContext), {
|
|
677
|
+
sites: mergedSites,
|
|
678
|
+
leaves: fullRec.leaves,
|
|
679
|
+
splits: fullRec.splits,
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
647
684
|
const top = this.trace?.enter("respondTurn", [
|
|
648
685
|
rItem(newContext, "query"),
|
|
649
686
|
]);
|