@hviana/sema 0.1.5 → 0.1.7
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 +6 -5
- package/CITATION.cff +49 -0
- package/HOW_IT_WORKS.md +11 -12
- package/README.md +7 -5
- package/dist/example/demo.js +25 -25
- package/dist/example/train_base.d.ts +19 -21
- package/dist/example/train_base.js +1700 -1952
- package/dist/src/alphabet.d.ts +3 -3
- package/dist/src/alphabet.js +24 -27
- package/dist/src/alu/src/alu.d.ts +169 -194
- package/dist/src/alu/src/alu.js +374 -414
- package/dist/src/alu/src/expr.d.ts +36 -43
- package/dist/src/alu/src/expr.js +252 -278
- package/dist/src/alu/src/index.d.ts +9 -98
- package/dist/src/alu/src/index.js +10 -64
- package/dist/src/alu/src/kernel-arith.d.ts +1 -5
- package/dist/src/alu/src/kernel-arith.js +195 -285
- package/dist/src/alu/src/kernel-bits.d.ts +1 -5
- package/dist/src/alu/src/kernel-bits.js +81 -115
- package/dist/src/alu/src/kernel-logic.js +33 -63
- package/dist/src/alu/src/kernel-nd.js +155 -195
- package/dist/src/alu/src/kernel-numeric.d.ts +16 -80
- package/dist/src/alu/src/kernel-numeric.js +259 -331
- package/dist/src/alu/src/operation.d.ts +112 -132
- package/dist/src/alu/src/operation.js +149 -163
- package/dist/src/alu/src/parser.d.ts +168 -175
- package/dist/src/alu/src/parser.js +382 -421
- package/dist/src/alu/src/resonance.d.ts +16 -25
- package/dist/src/alu/src/resonance.js +49 -56
- package/dist/src/alu/src/text.d.ts +3 -7
- package/dist/src/alu/src/text.js +31 -37
- package/dist/src/alu/src/value.d.ts +14 -14
- package/dist/src/alu/src/value.js +150 -160
- package/dist/src/alu/test/alu.test.js +543 -656
- package/dist/src/bytes.d.ts +1 -5
- package/dist/src/bytes.js +33 -40
- package/dist/src/config.d.ts +99 -102
- package/dist/src/config.js +78 -83
- package/dist/src/derive/src/deduction.d.ts +60 -62
- package/dist/src/derive/src/deduction.js +103 -109
- package/dist/src/derive/src/index.d.ts +1 -7
- package/dist/src/derive/src/priority-queue.d.ts +8 -8
- package/dist/src/derive/src/priority-queue.js +57 -61
- package/dist/src/derive/src/rewrite.d.ts +15 -18
- package/dist/src/derive/src/rewrite.js +59 -67
- package/dist/src/derive/src/trie.d.ts +56 -56
- package/dist/src/derive/src/trie.js +175 -179
- package/dist/src/derive/test/derive.test.js +96 -100
- package/dist/src/extension.d.ts +13 -16
- package/dist/src/geometry.d.ts +29 -43
- package/dist/src/geometry.js +324 -268
- package/dist/src/index.d.ts +2 -17
- package/dist/src/index.js +2 -12
- package/dist/src/ingest-cache.d.ts +25 -30
- package/dist/src/ingest-cache.js +108 -127
- package/dist/src/mind/articulation.d.ts +1 -5
- package/dist/src/mind/articulation.js +77 -112
- package/dist/src/mind/attention.d.ts +40 -108
- package/dist/src/mind/attention.js +754 -872
- package/dist/src/mind/canonical.d.ts +4 -19
- package/dist/src/mind/canonical.js +27 -31
- package/dist/src/mind/graph-search.d.ts +201 -225
- package/dist/src/mind/graph-search.js +742 -821
- package/dist/src/mind/index.d.ts +2 -10
- package/dist/src/mind/junction.d.ts +31 -58
- package/dist/src/mind/junction.js +172 -237
- package/dist/src/mind/learning.d.ts +16 -52
- package/dist/src/mind/learning.js +143 -165
- package/dist/src/mind/match.d.ts +20 -69
- package/dist/src/mind/match.js +259 -318
- package/dist/src/mind/mechanisms/alu.js +16 -16
- package/dist/src/mind/mechanisms/cast.d.ts +9 -13
- package/dist/src/mind/mechanisms/cast.js +363 -456
- package/dist/src/mind/mechanisms/confluence.d.ts +8 -12
- package/dist/src/mind/mechanisms/confluence.js +152 -183
- package/dist/src/mind/mechanisms/cover.d.ts +2 -8
- package/dist/src/mind/mechanisms/cover.js +148 -210
- package/dist/src/mind/mechanisms/extraction.d.ts +8 -34
- package/dist/src/mind/mechanisms/extraction.js +234 -288
- package/dist/src/mind/mechanisms/recall.d.ts +6 -10
- package/dist/src/mind/mechanisms/recall.js +141 -185
- package/dist/src/mind/mind.d.ts +194 -155
- package/dist/src/mind/mind.js +392 -289
- package/dist/src/mind/pipeline-mechanism.d.ts +112 -124
- package/dist/src/mind/pipeline-mechanism.js +161 -172
- package/dist/src/mind/pipeline.d.ts +4 -14
- package/dist/src/mind/pipeline.js +125 -189
- package/dist/src/mind/primitives.d.ts +20 -33
- package/dist/src/mind/primitives.js +124 -120
- package/dist/src/mind/rationale.d.ts +86 -98
- package/dist/src/mind/rationale.js +113 -121
- package/dist/src/mind/reasoning.d.ts +2 -13
- package/dist/src/mind/reasoning.js +129 -166
- package/dist/src/mind/recognition.d.ts +1 -4
- package/dist/src/mind/recognition.js +198 -210
- package/dist/src/mind/resonance.d.ts +5 -22
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +6 -25
- package/dist/src/mind/trace.js +50 -58
- package/dist/src/mind/traverse.d.ts +29 -58
- package/dist/src/mind/traverse.js +344 -356
- package/dist/src/mind/types.d.ts +122 -127
- package/dist/src/mind/types.js +60 -69
- 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-hnsw → rabitq-ivf}/src/index.js +1 -3
- 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 +9 -13
- package/dist/src/sema.js +26 -40
- package/dist/src/store-sqlite.d.ts +171 -166
- package/dist/src/store-sqlite.js +768 -662
- package/dist/src/store.d.ts +597 -630
- package/dist/src/store.js +1434 -1581
- package/dist/src/vec.d.ts +5 -9
- package/dist/src/vec.js +61 -73
- package/example/train_base.ts +33 -15
- package/index.html +65 -0
- package/package.json +1 -1
- package/src/alu/README.md +1 -1
- package/src/alu/src/index.ts +1 -1
- package/src/config.ts +19 -27
- package/src/geometry.ts +93 -1
- package/src/index.ts +6 -11
- package/src/mind/attention.ts +11 -6
- package/src/mind/mechanisms/recall.ts +29 -13
- package/src/mind/mind.ts +250 -19
- package/src/mind/primitives.ts +43 -6
- package/src/mind/recognition.ts +26 -8
- package/src/mind/traverse.ts +47 -0
- package/src/mind/types.ts +20 -21
- package/src/rabitq-ivf/README.md +56 -0
- package/src/rabitq-ivf/src/database.ts +276 -0
- package/src/{rabitq-hnsw → rabitq-ivf}/src/index.ts +2 -5
- package/src/rabitq-ivf/src/ivf.ts +1330 -0
- package/src/{rabitq-hnsw → rabitq-ivf}/src/prng.ts +1 -1
- package/src/store-sqlite.ts +204 -9
- package/src/store.ts +27 -34
- package/test/08-storage.test.mjs +3 -3
- package/test/13-conversation.test.mjs +190 -20
- package/test/14-scaling.test.mjs +2 -2
- package/test/35-ivf.test.mjs +263 -0
- package/test/36-bloom.test.mjs +123 -0
- package/dist/src/rabitq-hnsw/src/database.d.ts +0 -202
- package/dist/src/rabitq-hnsw/src/database.js +0 -405
- package/dist/src/rabitq-hnsw/src/heap.d.ts +0 -22
- package/dist/src/rabitq-hnsw/src/heap.js +0 -94
- package/dist/src/rabitq-hnsw/src/hnsw.d.ts +0 -125
- package/dist/src/rabitq-hnsw/src/hnsw.js +0 -500
- package/dist/src/rabitq-hnsw/src/index.d.ts +0 -15
- package/dist/src/rabitq-hnsw/src/prng.d.ts +0 -19
- package/dist/src/rabitq-hnsw/src/prng.js +0 -38
- package/dist/src/rabitq-hnsw/src/rabitq.d.ts +0 -95
- package/dist/src/rabitq-hnsw/src/rabitq.js +0 -299
- package/dist/src/rabitq-hnsw/src/store.d.ts +0 -162
- package/dist/src/rabitq-hnsw/src/store.js +0 -916
- package/dist/src/rabitq-hnsw/test/hnsw.test.d.ts +0 -1
- package/dist/src/rabitq-hnsw/test/hnsw.test.js +0 -1197
- package/src/rabitq-hnsw/README.md +0 -303
- package/src/rabitq-hnsw/src/database.ts +0 -492
- package/src/rabitq-hnsw/src/heap.ts +0 -90
- package/src/rabitq-hnsw/src/hnsw.ts +0 -514
- package/src/rabitq-hnsw/src/store.ts +0 -994
- package/src/rabitq-hnsw/test/hnsw.test.ts +0 -1213
- /package/src/{rabitq-hnsw → rabitq-ivf}/src/rabitq.ts +0 -0
|
@@ -11,16 +11,24 @@ import type { AncestorReach, MindContext } from "./types.js";
|
|
|
11
11
|
* repeatedly — regions sharing a chunk, and canonicalChunkId probing each
|
|
12
12
|
* chunk's prefixes — so without the memo every repeat re-pays the full
|
|
13
13
|
* fan-out reads. */
|
|
14
|
-
export declare function edgeAncestors(
|
|
15
|
-
ctx: MindContext,
|
|
16
|
-
id: number,
|
|
17
|
-
contextCount: number,
|
|
18
|
-
memo?: Map<number, AncestorReach>,
|
|
19
|
-
): AncestorReach;
|
|
14
|
+
export declare function edgeAncestors(ctx: MindContext, id: number, contextCount: number, memo?: Map<number, AncestorReach>): AncestorReach;
|
|
20
15
|
/** Convenience: forward edges of a node. */
|
|
21
16
|
export declare function nextOf(ctx: MindContext, id: number): number[];
|
|
22
17
|
/** Convenience: reverse edges of a node. */
|
|
23
18
|
export declare function prevOf(ctx: MindContext, id: number): number[];
|
|
19
|
+
/** The uniform-expectation floor on a byte atom's corpus commonality: N
|
|
20
|
+
* learnt contexts, each at least one perception chunk of up to W of the 256
|
|
21
|
+
* possible byte values, contain a given atom in ≥ N·W/256 contexts on
|
|
22
|
+
* average. An atom's TRUE containment is unmeasurable (atoms carry no
|
|
23
|
+
* kid/contain links by construction), so this floor is the honest stand-in:
|
|
24
|
+
* derived entirely from the corpus scale N, the perception window W, and
|
|
25
|
+
* the alphabet size — never tuned. */
|
|
26
|
+
export declare function atomReach(ctx: MindContext, contextCount: number): number;
|
|
27
|
+
/** Whether a byte atom is a hub at this corpus scale — its commonality floor
|
|
28
|
+
* {@link atomReach} exceeds the hub bound √N. Below it (small stores) an
|
|
29
|
+
* atom votes and is recognised exactly as any stored form; above it the
|
|
30
|
+
* alphabet is scaffolding everywhere and abstains. */
|
|
31
|
+
export declare function atomIsHub(ctx: MindContext, contextCount: number): boolean;
|
|
24
32
|
/** Whether a node LEADS SOMEWHERE — it bears a continuation edge or a halo.
|
|
25
33
|
* The admission predicate recognition filters sites with (HOW_IT_WORKS
|
|
26
34
|
* §15.3): a form that leads nowhere contributes nothing to any derivation.
|
|
@@ -37,12 +45,7 @@ export declare function leadsSomewhere(ctx: MindContext, id: number): boolean;
|
|
|
37
45
|
* half-dominance convention (geometry.dominates(reach, N)): content
|
|
38
46
|
* reaching a corpus MINORITY of contexts discriminates (an entity, a
|
|
39
47
|
* filler); content reaching a majority is frame scaffolding. */
|
|
40
|
-
export declare function reachOf(
|
|
41
|
-
ctx: MindContext,
|
|
42
|
-
id: number,
|
|
43
|
-
contextCount: number,
|
|
44
|
-
memo?: Map<number, AncestorReach>,
|
|
45
|
-
): number;
|
|
48
|
+
export declare function reachOf(ctx: MindContext, id: number, contextCount: number, memo?: Map<number, AncestorReach>): number;
|
|
46
49
|
/** The corpus scale N — the count of DISTINCT learnt contexts, floored at 2
|
|
47
50
|
* so its derived readings (ln N in the consensus floor, √N in the hub bound)
|
|
48
51
|
* stay meaningful on a near-empty store. The one definition every consumer
|
|
@@ -58,55 +61,31 @@ export declare function hubBound(ctx: MindContext): number;
|
|
|
58
61
|
* §8.6). A node connected to more than √N others is a hub whose individual
|
|
59
62
|
* connections carry ~no discriminative information; materialising or scoring
|
|
60
63
|
* them all would make single decisions scale with the corpus. */
|
|
61
|
-
export declare function hubCap<T>(
|
|
62
|
-
ctx: MindContext,
|
|
63
|
-
ids: readonly T[],
|
|
64
|
-
): readonly T[];
|
|
64
|
+
export declare function hubCap<T>(ctx: MindContext, ids: readonly T[]): readonly T[];
|
|
65
65
|
/** Whether `descendant` lies within `ancestor`'s subtree — a structural DAG
|
|
66
66
|
* relation read off the hash-consed `kids` lists, by a bounded explicit-stack
|
|
67
67
|
* descent. Used by articulation to keep a voice from revoicing a fragment
|
|
68
68
|
* OF that voice. */
|
|
69
|
-
export declare function contains(
|
|
70
|
-
ctx: MindContext,
|
|
71
|
-
ancestor: number,
|
|
72
|
-
descendant: number,
|
|
73
|
-
): boolean;
|
|
69
|
+
export declare function contains(ctx: MindContext, ancestor: number, descendant: number): boolean;
|
|
74
70
|
/** The best-scoring item by cosine against `query`, among items scoring at
|
|
75
71
|
* or above `threshold` — the shared arg-max every Pattern-A "which of these
|
|
76
72
|
* resonates best" decision reduces to. `strict` picks the tie-break a
|
|
77
73
|
* caller needs: `true` keeps the first-seen leader on a tie (`>`), the
|
|
78
74
|
* default lets a later equal score take it (`>=`). */
|
|
79
|
-
export declare function argmaxBy<T>(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
threshold: number,
|
|
83
|
-
strict?: boolean,
|
|
84
|
-
): {
|
|
85
|
-
item: T;
|
|
86
|
-
score: number;
|
|
75
|
+
export declare function argmaxBy<T>(items: Iterable<T>, scoreOf: (item: T) => number, threshold: number, strict?: boolean): {
|
|
76
|
+
item: T;
|
|
77
|
+
score: number;
|
|
87
78
|
} | null;
|
|
88
|
-
export declare function argmaxCosine<T>(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
vecOf: (item: T) => Vec | null | undefined,
|
|
92
|
-
threshold: number,
|
|
93
|
-
strict?: boolean,
|
|
94
|
-
): {
|
|
95
|
-
item: T;
|
|
96
|
-
score: number;
|
|
79
|
+
export declare function argmaxCosine<T>(query: Vec, items: Iterable<T>, vecOf: (item: T) => Vec | null | undefined, threshold: number, strict?: boolean): {
|
|
80
|
+
item: T;
|
|
81
|
+
score: number;
|
|
97
82
|
} | null;
|
|
98
83
|
/** The guided-or-first continuation of a node, as answer-shaped bytes source:
|
|
99
84
|
* chooseNext under the response guide, falling back to the FIRST-inserted
|
|
100
85
|
* edge — the one no-guide convention chooseNext, project() and the search's
|
|
101
86
|
* formRules all share. undefined when the node has no continuation. */
|
|
102
|
-
export declare function guidedFirst(
|
|
103
|
-
|
|
104
|
-
id: number,
|
|
105
|
-
): number | undefined;
|
|
106
|
-
export declare function guidedNext(
|
|
107
|
-
ctx: MindContext,
|
|
108
|
-
node: number,
|
|
109
|
-
): number | undefined;
|
|
87
|
+
export declare function guidedFirst(ctx: MindContext, id: number): number | undefined;
|
|
88
|
+
export declare function guidedNext(ctx: MindContext, node: number): number | undefined;
|
|
110
89
|
/** Disambiguate among a node's learnt continuations by distributional
|
|
111
90
|
* support. NOTE the `guide` contract: its VALUE is deliberately unused —
|
|
112
91
|
* only its PRESENCE gates disambiguation (a null guide means no query is in
|
|
@@ -119,11 +98,7 @@ export declare function guidedNext(
|
|
|
119
98
|
* that their perceived gists ARE semantically meaningful — and which
|
|
120
99
|
* therefore scores by guide cosine. The two directions consult different
|
|
121
100
|
* halves of the evidence on purpose. */
|
|
122
|
-
export declare function chooseNext(
|
|
123
|
-
ctx: MindContext,
|
|
124
|
-
id: number,
|
|
125
|
-
guide?: Vec | null,
|
|
126
|
-
): number | undefined;
|
|
101
|
+
export declare function chooseNext(ctx: MindContext, id: number, guide?: Vec | null): number | undefined;
|
|
127
102
|
/** The perceived gist of a candidate node, through the session gist cache.
|
|
128
103
|
* Re-gisting a candidate is a full river fold of its bytes — the measured
|
|
129
104
|
* recall bottleneck (a hub context offers up to √N continuations, EACH
|
|
@@ -132,11 +107,7 @@ export declare function chooseNext(
|
|
|
132
107
|
* every "score node ids against a guide" decision (chooseAmong here, the
|
|
133
108
|
* bridge's junction pick) so they share ONE cache and one convention. */
|
|
134
109
|
export declare function candidateGist(ctx: MindContext, c: number): Vec | null;
|
|
135
|
-
export declare function chooseAmong(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
guide: Vec,
|
|
139
|
-
): {
|
|
140
|
-
id: number;
|
|
141
|
-
score: number;
|
|
110
|
+
export declare function chooseAmong(ctx: MindContext, candidates: readonly number[], guide: Vec): {
|
|
111
|
+
id: number;
|
|
112
|
+
score: number;
|
|
142
113
|
};
|