@hviana/sema 0.5.2 → 0.5.4
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/AGENTS.md +115 -53
- package/HOW_IT_WORKS.md +291 -184
- package/jsr.json +6 -0
- package/package.json +1 -1
- package/src/mind/bridge.ts +10 -104
- package/src/mind/match.ts +497 -7
- package/src/mind/{prefix-completion.ts → mechanisms/prefix-completion.ts} +66 -92
- package/src/mind/mechanisms/recall.ts +38 -129
- package/src/mind/mechanisms/reference.ts +343 -0
- package/src/mind/mind.ts +12 -8
- package/src/mind/pipeline-mechanism.ts +120 -3
- package/src/mind/pipeline.ts +16 -2
- package/src/mind/traverse.ts +92 -1
- package/src/store.ts +13 -4
- package/test/33-multi-candidate.test.mjs +21 -11
- package/test/70-prefix-completion.test.mjs +1 -1
- package/test/72-prefix-candidate-supply.test.mjs +7 -9
- package/test/74-prefix-trap-not-sprung-early.test.mjs +1 -1
- package/test/76-reference-binding.test.mjs +543 -0
- package/dist/example/demo.d.ts +0 -1
- package/dist/example/demo.js +0 -39
- package/dist/example/train_base.d.ts +0 -93
- package/dist/example/train_base.js +0 -2269
- package/dist/src/alphabet.d.ts +0 -7
- package/dist/src/alphabet.js +0 -33
- package/dist/src/alu/src/alu.d.ts +0 -185
- package/dist/src/alu/src/alu.js +0 -440
- package/dist/src/alu/src/expr.d.ts +0 -61
- package/dist/src/alu/src/expr.js +0 -318
- package/dist/src/alu/src/index.d.ts +0 -11
- package/dist/src/alu/src/index.js +0 -19
- package/dist/src/alu/src/kernel-arith.d.ts +0 -16
- package/dist/src/alu/src/kernel-arith.js +0 -264
- package/dist/src/alu/src/kernel-bits.d.ts +0 -19
- package/dist/src/alu/src/kernel-bits.js +0 -152
- package/dist/src/alu/src/kernel-logic.d.ts +0 -4
- package/dist/src/alu/src/kernel-logic.js +0 -60
- package/dist/src/alu/src/kernel-nd.d.ts +0 -3
- package/dist/src/alu/src/kernel-nd.js +0 -208
- package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
- package/dist/src/alu/src/kernel-numeric.js +0 -366
- package/dist/src/alu/src/operation.d.ts +0 -168
- package/dist/src/alu/src/operation.js +0 -189
- package/dist/src/alu/src/parser.d.ts +0 -221
- package/dist/src/alu/src/parser.js +0 -577
- package/dist/src/alu/src/resonance.d.ts +0 -55
- package/dist/src/alu/src/resonance.js +0 -126
- package/dist/src/alu/src/text.d.ts +0 -31
- package/dist/src/alu/src/text.js +0 -73
- package/dist/src/alu/src/value.d.ts +0 -109
- package/dist/src/alu/src/value.js +0 -300
- package/dist/src/alu/test/alu.test.d.ts +0 -1
- package/dist/src/alu/test/alu.test.js +0 -764
- package/dist/src/bytes.d.ts +0 -14
- package/dist/src/bytes.js +0 -59
- package/dist/src/canon.d.ts +0 -45
- package/dist/src/canon.js +0 -85
- package/dist/src/config.d.ts +0 -111
- package/dist/src/config.js +0 -91
- package/dist/src/derive/src/deduction.d.ts +0 -136
- package/dist/src/derive/src/deduction.js +0 -159
- package/dist/src/derive/src/index.d.ts +0 -8
- package/dist/src/derive/src/index.js +0 -11
- package/dist/src/derive/src/priority-queue.d.ts +0 -20
- package/dist/src/derive/src/priority-queue.js +0 -73
- package/dist/src/derive/src/rewrite.d.ts +0 -56
- package/dist/src/derive/src/rewrite.js +0 -100
- package/dist/src/derive/src/trie.d.ts +0 -90
- package/dist/src/derive/src/trie.js +0 -217
- package/dist/src/derive/test/derive.test.d.ts +0 -1
- package/dist/src/derive/test/derive.test.js +0 -122
- package/dist/src/extension.d.ts +0 -37
- package/dist/src/extension.js +0 -7
- package/dist/src/geometry.d.ts +0 -233
- package/dist/src/geometry.js +0 -1089
- package/dist/src/index.d.ts +0 -17
- package/dist/src/index.js +0 -19
- package/dist/src/ingest-cache.d.ts +0 -41
- package/dist/src/ingest-cache.js +0 -165
- package/dist/src/meter.d.ts +0 -176
- package/dist/src/meter.js +0 -274
- package/dist/src/mind/articulation.d.ts +0 -6
- package/dist/src/mind/articulation.js +0 -99
- package/dist/src/mind/attention.d.ts +0 -430
- package/dist/src/mind/attention.js +0 -2418
- package/dist/src/mind/bridge.d.ts +0 -39
- package/dist/src/mind/bridge.js +0 -998
- package/dist/src/mind/canonical.d.ts +0 -34
- package/dist/src/mind/canonical.js +0 -93
- package/dist/src/mind/frame-filler.d.ts +0 -15
- package/dist/src/mind/frame-filler.js +0 -535
- package/dist/src/mind/graph-search.d.ts +0 -294
- package/dist/src/mind/graph-search.js +0 -996
- package/dist/src/mind/index.d.ts +0 -9
- package/dist/src/mind/index.js +0 -5
- package/dist/src/mind/junction.d.ts +0 -137
- package/dist/src/mind/junction.js +0 -358
- package/dist/src/mind/learning.d.ts +0 -75
- package/dist/src/mind/learning.js +0 -265
- package/dist/src/mind/match.d.ts +0 -192
- package/dist/src/mind/match.js +0 -666
- package/dist/src/mind/mechanisms/alu.d.ts +0 -4
- package/dist/src/mind/mechanisms/alu.js +0 -36
- package/dist/src/mind/mechanisms/cast.d.ts +0 -89
- package/dist/src/mind/mechanisms/cast.js +0 -1186
- package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
- package/dist/src/mind/mechanisms/confluence.js +0 -271
- package/dist/src/mind/mechanisms/cover.d.ts +0 -6
- package/dist/src/mind/mechanisms/cover.js +0 -232
- package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
- package/dist/src/mind/mechanisms/extraction.js +0 -327
- package/dist/src/mind/mechanisms/recall.d.ts +0 -16
- package/dist/src/mind/mechanisms/recall.js +0 -558
- package/dist/src/mind/mind.d.ts +0 -386
- package/dist/src/mind/mind.js +0 -754
- package/dist/src/mind/pipeline-mechanism.d.ts +0 -183
- package/dist/src/mind/pipeline-mechanism.js +0 -521
- package/dist/src/mind/pipeline.d.ts +0 -49
- package/dist/src/mind/pipeline.js +0 -331
- package/dist/src/mind/prefix-completion.d.ts +0 -59
- package/dist/src/mind/prefix-completion.js +0 -270
- package/dist/src/mind/primitives.d.ts +0 -85
- package/dist/src/mind/primitives.js +0 -333
- package/dist/src/mind/rationale.d.ts +0 -139
- package/dist/src/mind/rationale.js +0 -163
- package/dist/src/mind/reasoning.d.ts +0 -42
- package/dist/src/mind/reasoning.js +0 -305
- package/dist/src/mind/recognition.d.ts +0 -20
- package/dist/src/mind/recognition.js +0 -696
- package/dist/src/mind/resonance.d.ts +0 -35
- package/dist/src/mind/resonance.js +0 -365
- package/dist/src/mind/trace.d.ts +0 -15
- package/dist/src/mind/trace.js +0 -73
- package/dist/src/mind/traverse.d.ts +0 -158
- package/dist/src/mind/traverse.js +0 -716
- package/dist/src/mind/types.d.ts +0 -418
- package/dist/src/mind/types.js +0 -179
- package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
- package/dist/src/rabitq-ivf/src/database.js +0 -201
- package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
- package/dist/src/rabitq-ivf/src/index.js +0 -4
- package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
- package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
- package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
- package/dist/src/rabitq-ivf/src/prng.js +0 -36
- package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
- package/dist/src/rabitq-ivf/src/rabitq.js +0 -313
- package/dist/src/sema.d.ts +0 -41
- package/dist/src/sema.js +0 -77
- package/dist/src/store-sqlite.d.ts +0 -184
- package/dist/src/store-sqlite.js +0 -942
- package/dist/src/store.d.ts +0 -762
- package/dist/src/store.js +0 -1823
- package/dist/src/vec.d.ts +0 -31
- package/dist/src/vec.js +0 -109
- package/src/mind/frame-filler.ts +0 -604
- package/test/69-frame-filler.test.mjs +0 -115
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { MindContext } from "./types.js";
|
|
2
|
-
/** The two sliding-window lengths the WRITE side interns over a stream's leaf
|
|
3
|
-
* ids: W−1 and W (the river's grouping quantum and its off-by-one neighbour,
|
|
4
|
-
* so a form straddling a group boundary is reachable from either cut).
|
|
5
|
-
*
|
|
6
|
-
* Widening this to cover the reader's full segment scale (W−1..2W) was
|
|
7
|
-
* measured and REFUTED: it tripled the store (3,160 → 8,980 nodes on a
|
|
8
|
-
* 200-pair corpus), slowed ingest 80%, and fixed not one test. Unknown
|
|
9
|
-
* regions are not caused by the index's scale. */
|
|
10
|
-
export declare function canonicalWindows(W: number): [number, number];
|
|
11
|
-
/** The READ side's chain reach: how many leaf ids a canonical chain may grow
|
|
12
|
-
* to from one position — W², the deepest two-level composite the write side's
|
|
13
|
-
* windows can spell. */
|
|
14
|
-
export declare function chainReach(W: number): number;
|
|
15
|
-
/** The id of the single-byte leaf at position `p`, or null when that byte was
|
|
16
|
-
* never interned. */
|
|
17
|
-
export declare function leafIdAt(ctx: MindContext, bytes: Uint8Array, p: number): number | null;
|
|
18
|
-
/** The leaf ids of the window `[from, to)`, or null the moment ANY byte in it
|
|
19
|
-
* is unknown — the all-or-nothing read {@link canonicalChunkId} anchors on. */
|
|
20
|
-
export declare function leafIdRun(ctx: MindContext, bytes: Uint8Array, from: number, to: number): number[] | null;
|
|
21
|
-
/** The leaf ids of the LONGEST KNOWN PREFIX of `bytes` — stops at the first
|
|
22
|
-
* unknown byte and returns what it has (possibly empty). The caller decides
|
|
23
|
-
* what a partial prefix means (deposit only interns the whole-stream flat
|
|
24
|
-
* branch when the prefix covers everything). */
|
|
25
|
-
export declare function leafIdPrefix(ctx: MindContext, bytes: Uint8Array): number[];
|
|
26
|
-
/** The canonical W-window node ids of a byte stream, offset → id — the
|
|
27
|
-
* CONTENT-ADDRESSED IDENTITY of every W-sized slice, under which any content
|
|
28
|
-
* two deposits share IS the same node (hash-consing paid the comparison at
|
|
29
|
-
* write time). The read side of the {@link canonicalWindows} contract asked
|
|
30
|
-
* at every offset: a window over unknown bytes, or one never interned as a
|
|
31
|
-
* flat branch, has no identity and is skipped. Confluence's meet and CAST's
|
|
32
|
-
* frame detection both read shared/common content through this — never
|
|
33
|
-
* through a byte scan. */
|
|
34
|
-
export declare function windowIds(ctx: MindContext, bytes: Uint8Array): Map<number, number>;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
// canonical.ts — THE canonical-segmentation convention, defined once.
|
|
2
|
-
//
|
|
3
|
-
// The store's canonical reading of a byte stream — "the id of each single-byte
|
|
4
|
-
// leaf, chained into flat branches" — is a WRITE/READ CONTRACT split across
|
|
5
|
-
// four consumers that previously each re-implemented the chaining loop:
|
|
6
|
-
//
|
|
7
|
-
// WRITE side (training):
|
|
8
|
-
// • learning.indexSubSpans — interns sliding windows of the two
|
|
9
|
-
// {@link canonicalWindows} lengths over the stream's leaf ids;
|
|
10
|
-
// • learning.deposit — interns the WHOLE stream as one flat branch
|
|
11
|
-
// (via {@link leafIdPrefix}) so every deposit has a byte-level identity.
|
|
12
|
-
// READ side (inference):
|
|
13
|
-
// • recognition's canonical pass — chains leaf ids from every position and
|
|
14
|
-
// probes each growing prefix as a flat branch, up to {@link chainReach};
|
|
15
|
-
// • attention.canonicalChunkId — reads a chunk's window of leaf ids
|
|
16
|
-
// (via {@link leafIdRun}) and probes its prefixes for the best anchor.
|
|
17
|
-
// (geometry.knownPrefixLength is the same convention below the store layer,
|
|
18
|
-
// expressed through injected `leafAt`/`lookup` capabilities — it cannot
|
|
19
|
-
// import this module without inverting the dependency spine, so its header
|
|
20
|
-
// cross-references this file instead.)
|
|
21
|
-
//
|
|
22
|
-
// If the write side's windows or the read side's reach ever change, they must
|
|
23
|
-
// change HERE — a drift between them silently makes recognition stop finding
|
|
24
|
-
// what training indexed, which no type checker catches.
|
|
25
|
-
/** The two sliding-window lengths the WRITE side interns over a stream's leaf
|
|
26
|
-
* ids: W−1 and W (the river's grouping quantum and its off-by-one neighbour,
|
|
27
|
-
* so a form straddling a group boundary is reachable from either cut).
|
|
28
|
-
*
|
|
29
|
-
* Widening this to cover the reader's full segment scale (W−1..2W) was
|
|
30
|
-
* measured and REFUTED: it tripled the store (3,160 → 8,980 nodes on a
|
|
31
|
-
* 200-pair corpus), slowed ingest 80%, and fixed not one test. Unknown
|
|
32
|
-
* regions are not caused by the index's scale. */
|
|
33
|
-
export function canonicalWindows(W) {
|
|
34
|
-
return [W - 1, W];
|
|
35
|
-
}
|
|
36
|
-
/** The READ side's chain reach: how many leaf ids a canonical chain may grow
|
|
37
|
-
* to from one position — W², the deepest two-level composite the write side's
|
|
38
|
-
* windows can spell. */
|
|
39
|
-
export function chainReach(W) {
|
|
40
|
-
return W * W;
|
|
41
|
-
}
|
|
42
|
-
/** The id of the single-byte leaf at position `p`, or null when that byte was
|
|
43
|
-
* never interned. */
|
|
44
|
-
export function leafIdAt(ctx, bytes, p) {
|
|
45
|
-
return ctx.store.findLeaf(bytes.subarray(p, p + 1));
|
|
46
|
-
}
|
|
47
|
-
/** The leaf ids of the window `[from, to)`, or null the moment ANY byte in it
|
|
48
|
-
* is unknown — the all-or-nothing read {@link canonicalChunkId} anchors on. */
|
|
49
|
-
export function leafIdRun(ctx, bytes, from, to) {
|
|
50
|
-
const ids = [];
|
|
51
|
-
for (let i = from; i < to; i++) {
|
|
52
|
-
const lid = leafIdAt(ctx, bytes, i);
|
|
53
|
-
if (lid === null)
|
|
54
|
-
return null;
|
|
55
|
-
ids.push(lid);
|
|
56
|
-
}
|
|
57
|
-
return ids;
|
|
58
|
-
}
|
|
59
|
-
/** The leaf ids of the LONGEST KNOWN PREFIX of `bytes` — stops at the first
|
|
60
|
-
* unknown byte and returns what it has (possibly empty). The caller decides
|
|
61
|
-
* what a partial prefix means (deposit only interns the whole-stream flat
|
|
62
|
-
* branch when the prefix covers everything). */
|
|
63
|
-
export function leafIdPrefix(ctx, bytes) {
|
|
64
|
-
const ids = [];
|
|
65
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
66
|
-
const lid = leafIdAt(ctx, bytes, i);
|
|
67
|
-
if (lid === null)
|
|
68
|
-
break;
|
|
69
|
-
ids.push(lid);
|
|
70
|
-
}
|
|
71
|
-
return ids;
|
|
72
|
-
}
|
|
73
|
-
/** The canonical W-window node ids of a byte stream, offset → id — the
|
|
74
|
-
* CONTENT-ADDRESSED IDENTITY of every W-sized slice, under which any content
|
|
75
|
-
* two deposits share IS the same node (hash-consing paid the comparison at
|
|
76
|
-
* write time). The read side of the {@link canonicalWindows} contract asked
|
|
77
|
-
* at every offset: a window over unknown bytes, or one never interned as a
|
|
78
|
-
* flat branch, has no identity and is skipped. Confluence's meet and CAST's
|
|
79
|
-
* frame detection both read shared/common content through this — never
|
|
80
|
-
* through a byte scan. */
|
|
81
|
-
export function windowIds(ctx, bytes) {
|
|
82
|
-
const W = ctx.space.maxGroup;
|
|
83
|
-
const out = new Map();
|
|
84
|
-
for (let off = 0; off + W <= bytes.length; off++) {
|
|
85
|
-
const ids = leafIdRun(ctx, bytes, off, off + W);
|
|
86
|
-
if (ids === null)
|
|
87
|
-
continue;
|
|
88
|
-
const wid = ctx.store.findBranch(ids);
|
|
89
|
-
if (wid !== null)
|
|
90
|
-
out.set(off, wid);
|
|
91
|
-
}
|
|
92
|
-
return out;
|
|
93
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { MindContext } from "./types.js";
|
|
2
|
-
/** A grounded frame-filler substitution: the stored form the constructed key
|
|
3
|
-
* resolved to, and the spans that explain how it was reached. */
|
|
4
|
-
export interface FrameFillerHit {
|
|
5
|
-
/** The trained form the key resolved to — grounded through its own edge. */
|
|
6
|
-
id: number;
|
|
7
|
-
/** `[start, end)` of the query span the filler stood in for. */
|
|
8
|
-
described: [number, number];
|
|
9
|
-
/** The filler's bytes, for the rationale trace. */
|
|
10
|
-
filler: Uint8Array;
|
|
11
|
-
}
|
|
12
|
-
/** Find the query's own most discriminative unit and the trained contexts that
|
|
13
|
-
* hold it, then try the store for the query with a candidate filler in the
|
|
14
|
-
* described span's place. Returns the sole surviving stored form, or null. */
|
|
15
|
-
export declare function frameFillerSubstitution(ctx: MindContext, query: Uint8Array, ranked: ReadonlyArray<number>): FrameFillerHit | null;
|