@hviana/sema 0.1.3 → 0.1.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.
- package/dist/example/demo.js +25 -25
- package/dist/example/train_base.d.ts +21 -19
- package/dist/example/train_base.js +1952 -1684
- package/dist/src/alphabet.d.ts +3 -3
- package/dist/src/alphabet.js +27 -24
- package/dist/src/alu/src/alu.d.ts +194 -169
- package/dist/src/alu/src/alu.js +414 -374
- package/dist/src/alu/src/expr.d.ts +43 -36
- package/dist/src/alu/src/expr.js +278 -252
- package/dist/src/alu/src/index.d.ts +98 -9
- package/dist/src/alu/src/index.js +63 -9
- package/dist/src/alu/src/kernel-arith.d.ts +5 -1
- package/dist/src/alu/src/kernel-arith.js +285 -195
- package/dist/src/alu/src/kernel-bits.d.ts +5 -1
- package/dist/src/alu/src/kernel-bits.js +115 -81
- package/dist/src/alu/src/kernel-logic.js +63 -33
- package/dist/src/alu/src/kernel-nd.js +195 -155
- package/dist/src/alu/src/kernel-numeric.d.ts +80 -16
- package/dist/src/alu/src/kernel-numeric.js +331 -259
- package/dist/src/alu/src/operation.d.ts +132 -112
- package/dist/src/alu/src/operation.js +163 -149
- package/dist/src/alu/src/parser.d.ts +175 -168
- package/dist/src/alu/src/parser.js +421 -382
- package/dist/src/alu/src/resonance.d.ts +25 -16
- package/dist/src/alu/src/resonance.js +56 -49
- package/dist/src/alu/src/text.d.ts +7 -3
- package/dist/src/alu/src/text.js +37 -31
- package/dist/src/alu/src/value.d.ts +14 -14
- package/dist/src/alu/src/value.js +160 -150
- package/dist/src/alu/test/alu.test.js +656 -543
- package/dist/src/bytes.d.ts +5 -1
- package/dist/src/bytes.js +40 -33
- package/dist/src/config.d.ts +102 -102
- package/dist/src/config.js +83 -83
- package/dist/src/derive/src/deduction.d.ts +62 -60
- package/dist/src/derive/src/deduction.js +109 -103
- package/dist/src/derive/src/index.d.ts +7 -1
- package/dist/src/derive/src/priority-queue.d.ts +8 -8
- package/dist/src/derive/src/priority-queue.js +61 -57
- package/dist/src/derive/src/rewrite.d.ts +18 -15
- package/dist/src/derive/src/rewrite.js +67 -59
- package/dist/src/derive/src/trie.d.ts +56 -56
- package/dist/src/derive/src/trie.js +179 -175
- package/dist/src/derive/test/derive.test.js +100 -96
- package/dist/src/extension.d.ts +16 -13
- package/dist/src/geometry.d.ts +42 -17
- package/dist/src/geometry.js +266 -235
- package/dist/src/index.d.ts +17 -2
- package/dist/src/index.js +7 -1
- package/dist/src/ingest-cache.d.ts +30 -25
- package/dist/src/ingest-cache.js +127 -108
- package/dist/src/mind/articulation.d.ts +5 -1
- package/dist/src/mind/articulation.js +112 -77
- package/dist/src/mind/attention.d.ts +108 -40
- package/dist/src/mind/attention.js +871 -749
- package/dist/src/mind/canonical.d.ts +19 -4
- package/dist/src/mind/canonical.js +31 -27
- package/dist/src/mind/graph-search.d.ts +225 -201
- package/dist/src/mind/graph-search.js +821 -742
- package/dist/src/mind/index.d.ts +10 -2
- package/dist/src/mind/junction.d.ts +58 -31
- package/dist/src/mind/junction.js +237 -172
- package/dist/src/mind/learning.d.ts +52 -16
- package/dist/src/mind/learning.js +165 -143
- package/dist/src/mind/match.d.ts +69 -20
- package/dist/src/mind/match.js +318 -259
- package/dist/src/mind/mechanisms/alu.js +16 -16
- package/dist/src/mind/mechanisms/cast.d.ts +13 -9
- package/dist/src/mind/mechanisms/cast.js +456 -363
- package/dist/src/mind/mechanisms/confluence.d.ts +12 -8
- package/dist/src/mind/mechanisms/confluence.js +183 -152
- package/dist/src/mind/mechanisms/cover.d.ts +8 -2
- package/dist/src/mind/mechanisms/cover.js +210 -148
- package/dist/src/mind/mechanisms/extraction.d.ts +34 -8
- package/dist/src/mind/mechanisms/extraction.js +288 -234
- package/dist/src/mind/mechanisms/recall.d.ts +10 -6
- package/dist/src/mind/mechanisms/recall.js +185 -126
- package/dist/src/mind/mind.d.ts +154 -129
- package/dist/src/mind/mind.js +288 -258
- package/dist/src/mind/pipeline-mechanism.d.ts +124 -112
- package/dist/src/mind/pipeline-mechanism.js +172 -161
- package/dist/src/mind/pipeline.d.ts +14 -4
- package/dist/src/mind/pipeline.js +189 -125
- package/dist/src/mind/primitives.d.ts +32 -8
- package/dist/src/mind/primitives.js +117 -99
- package/dist/src/mind/rationale.d.ts +98 -86
- package/dist/src/mind/rationale.js +121 -113
- package/dist/src/mind/reasoning.d.ts +13 -2
- package/dist/src/mind/reasoning.js +166 -129
- package/dist/src/mind/recognition.d.ts +4 -1
- package/dist/src/mind/recognition.js +208 -183
- package/dist/src/mind/resonance.d.ts +22 -5
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +25 -6
- package/dist/src/mind/trace.js +58 -50
- package/dist/src/mind/traverse.d.ts +58 -16
- package/dist/src/mind/traverse.js +357 -304
- package/dist/src/mind/types.d.ts +127 -120
- package/dist/src/mind/types.js +69 -60
- package/dist/src/rabitq-hnsw/src/database.d.ts +179 -177
- package/dist/src/rabitq-hnsw/src/database.js +359 -342
- package/dist/src/rabitq-hnsw/src/heap.d.ts +12 -12
- package/dist/src/rabitq-hnsw/src/heap.js +80 -75
- package/dist/src/rabitq-hnsw/src/hnsw.d.ts +103 -103
- package/dist/src/rabitq-hnsw/src/hnsw.js +454 -428
- package/dist/src/rabitq-hnsw/src/index.d.ts +6 -1
- package/dist/src/rabitq-hnsw/src/prng.d.ts +10 -10
- package/dist/src/rabitq-hnsw/src/prng.js +27 -25
- package/dist/src/rabitq-hnsw/src/rabitq.d.ts +69 -69
- package/dist/src/rabitq-hnsw/src/rabitq.js +262 -246
- package/dist/src/rabitq-hnsw/src/store.d.ts +132 -132
- package/dist/src/rabitq-hnsw/src/store.js +843 -752
- package/dist/src/rabitq-hnsw/test/hnsw.test.js +1054 -805
- package/dist/src/sema.d.ts +35 -0
- package/dist/src/sema.js +77 -0
- package/dist/src/store-sqlite.d.ts +166 -144
- package/dist/src/store-sqlite.js +660 -578
- package/dist/src/store.d.ts +630 -593
- package/dist/src/store.js +1581 -1440
- package/dist/src/vec.d.ts +9 -5
- package/dist/src/vec.js +73 -61
- package/package.json +2 -2
- package/src/sema.ts +102 -0
package/dist/src/mind/mind.d.ts
CHANGED
|
@@ -8,140 +8,165 @@ import { GraphSearch, type Leaf, type Site } from "./graph-search.js";
|
|
|
8
8
|
import type { ComputedSpan, ExtensionHost } from "../extension.js";
|
|
9
9
|
export type { ComputedSpan, ExtensionHost };
|
|
10
10
|
import { type InspectRationale, Rationale } from "./rationale.js";
|
|
11
|
-
export type {
|
|
11
|
+
export type {
|
|
12
|
+
InspectRationale,
|
|
13
|
+
RationaleItem,
|
|
14
|
+
RationaleStep,
|
|
15
|
+
} from "./rationale.js";
|
|
12
16
|
export type Input = string | Uint8Array | Grid | Grid[];
|
|
13
17
|
export interface Response {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
v: Vec | null;
|
|
19
|
+
bytes: Uint8Array;
|
|
20
|
+
/** How the answer was grounded (see {@link Provenance}). `"recall-echo"`
|
|
21
|
+
* marks the last-resort fallback that returned the nearest stored form's
|
|
22
|
+
* own bytes verbatim — an echo, NOT a grounded fact. Absent when there is
|
|
23
|
+
* no answer. */
|
|
24
|
+
provenance?: import("./pipeline.js").Provenance;
|
|
21
25
|
}
|
|
22
26
|
import type { AttentionRead, MindContext, Recognition } from "./types.js";
|
|
23
27
|
export interface MindOptions {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
seed?: number;
|
|
29
|
+
recallQueryK?: number;
|
|
30
|
+
haloQueryK?: number;
|
|
31
|
+
normalizeEpsilon?: number;
|
|
32
|
+
cosineEpsilon?: number;
|
|
33
|
+
geometry?: Partial<import("../config.js").GeometryConfig>;
|
|
34
|
+
alphabet?: Partial<import("../config.js").AlphabetConfig>;
|
|
35
|
+
storeConfig?: Partial<import("../config.js").StoreConfig>;
|
|
36
|
+
store?: Store;
|
|
37
|
+
/** Additional grounding mechanisms (appended after the built-in defaults). */
|
|
38
|
+
mechanisms?: import("./pipeline-mechanism.js").PipelineMechanism[];
|
|
39
|
+
/** Factories that receive the {@link ExtensionHost} and return mechanisms. */
|
|
40
|
+
mechanismFactories?: ((
|
|
41
|
+
host: import("../extension.js").ExtensionHost,
|
|
42
|
+
) => import("./pipeline-mechanism.js").PipelineMechanism)[];
|
|
37
43
|
}
|
|
38
44
|
export declare class Mind implements MindContext {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
45
|
+
readonly space: Space;
|
|
46
|
+
readonly alphabet: Alphabet;
|
|
47
|
+
readonly store: Store;
|
|
48
|
+
readonly cfg: MindConfig;
|
|
49
|
+
/** The lightest-derivation engine over the Sema graph. */
|
|
50
|
+
readonly search: GraphSearch;
|
|
51
|
+
/** The grounding mechanisms iterated by {@link think}. */
|
|
52
|
+
readonly mechanisms: import("./pipeline-mechanism.js").PipelineMechanism[];
|
|
53
|
+
/** The live rationale tracer for the inference currently in flight, or null. */
|
|
54
|
+
trace: Rationale | null;
|
|
55
|
+
/** Per-response memo of the consensus climb. NOTE: this memo and
|
|
56
|
+
* {@link recogniseMemo} are BYPASSED while a rationale trace is attached
|
|
57
|
+
* (every mechanism must emit its own steps), so a traced respond re-pays
|
|
58
|
+
* up to four consensus climbs plus repeat recognitions — that is where the
|
|
59
|
+
* traced-vs-untraced latency multiple comes from, by design. */
|
|
60
|
+
climbMemo: WeakMap<Uint8Array, Map<string, AttentionRead>> | null;
|
|
61
|
+
/** Per-response memo of recognise() — see {@link MindContext.recogniseMemo}. */
|
|
62
|
+
recogniseMemo: WeakMap<Uint8Array, Recognition> | null;
|
|
63
|
+
/** Per-response memo of perceive() — see {@link MindContext.perceiveMemo}. */
|
|
64
|
+
perceiveMemo: Map<string, import("../sema.js").Sema> | null;
|
|
65
|
+
/** The perceived gist of the query currently being answered. Set by `think`
|
|
66
|
+
* before the graph search runs; `chooseNext` consults it as a gate (a null
|
|
67
|
+
* guide means no query is in flight, so structural walkers keep plain
|
|
68
|
+
* first-edge behaviour) and the reverse projection uses it for
|
|
69
|
+
* reverse-recall disambiguation via `chooseAmong`. */
|
|
70
|
+
_edgeGuide: Vec | null;
|
|
71
|
+
/** Per-response memo of {@link chooseNext} picks — ensures every mechanism
|
|
72
|
+
* of a single response follows the SAME continuation for each ambiguous
|
|
73
|
+
* context node. */
|
|
74
|
+
_edgeChoice: Map<number, number>;
|
|
75
|
+
/** Previous deposit's seen node ids for incremental change detection. */
|
|
76
|
+
_prevSeen: Set<number> | null;
|
|
77
|
+
/** Session cache of node-id → perceived gist for candidate scoring — see
|
|
78
|
+
* {@link MindContext._gistCache}. 32 MB ≈ 8K gists at D=1024; hub
|
|
79
|
+
* candidate sets (√N at most) fit comfortably and recur across queries. */
|
|
80
|
+
_gistCache: BoundedMap<number, Vec>;
|
|
81
|
+
_depositTrees: BoundedMap<string, import("../geometry.js").FoldPyramid>;
|
|
82
|
+
_depositLens: Set<number>;
|
|
83
|
+
_internIds: WeakMap<Sema, number>;
|
|
84
|
+
/** Canonical node id of a byte span. Required by GraphSearchHost & MindContext. */
|
|
85
|
+
resolve(bytes: Uint8Array): number | null;
|
|
86
|
+
recogniseSpan(bytes: Uint8Array): {
|
|
87
|
+
sites: ReadonlyArray<Site>;
|
|
88
|
+
leaves: ReadonlyArray<Leaf>;
|
|
89
|
+
splits: ReadonlySet<number>;
|
|
90
|
+
};
|
|
91
|
+
/** Disambiguate among multiple learnt continuations of the same context node.
|
|
92
|
+
* Required by {@link GraphSearchHost} — the graph search calls this through the
|
|
93
|
+
* host interface when a recognised form has more than one outgoing edge.
|
|
94
|
+
* Delegates to the standalone {@link chooseNext} which picks the candidate
|
|
95
|
+
* with the most distributional evidence (highest `prevOf` count — the
|
|
96
|
+
* structural manifestation of its halo). When evidence is equal the
|
|
97
|
+
* first-inserted edge wins. */
|
|
98
|
+
chooseNext(node: number): number | undefined;
|
|
99
|
+
constructor(opts?: MindOptions);
|
|
100
|
+
constructor(cfg: MindConfig, store: Store, _fromStore: true);
|
|
101
|
+
/** Exposed for tests: the consensus climb over query sub-regions. */
|
|
102
|
+
climbAttention(
|
|
103
|
+
query: Uint8Array,
|
|
104
|
+
k: number,
|
|
105
|
+
mode?: import("./types.js").DFMode,
|
|
106
|
+
): Promise<import("./types.js").Attention[]>;
|
|
107
|
+
/** Exposed for tests: climb the structural DAG from a node to its
|
|
108
|
+
* edge-bearing ancestor contexts. */
|
|
109
|
+
edgeAncestors(
|
|
110
|
+
id: number,
|
|
111
|
+
contextCount: number,
|
|
112
|
+
): import("./types.js").AncestorReach;
|
|
113
|
+
/** Exposed for tests: find the natural break point in a sorted vote list. */
|
|
114
|
+
naturalBreak(votes: number[]): number;
|
|
115
|
+
/** Perceive input into a content-defined tree. Deterministic — identical
|
|
116
|
+
* bytes always produce an identical tree. Public for ingest-cache. */
|
|
117
|
+
perceive(
|
|
118
|
+
input: Input,
|
|
119
|
+
leafAt?: (i: number) => number | null,
|
|
120
|
+
lookup?: (ids: number[]) => number | null,
|
|
121
|
+
): Sema;
|
|
122
|
+
/** Open one response's transient state — the tracer and the per-response
|
|
123
|
+
* memos. Paired with {@link endResponse}; the ONE place this state is
|
|
124
|
+
* created, so adding a memo cannot forget its reset. */
|
|
125
|
+
private beginResponse;
|
|
126
|
+
/** Close one response's transient state — every per-response field, incl.
|
|
127
|
+
* the edge guide/choices `think` sets mid-flight. */
|
|
128
|
+
private endResponse;
|
|
129
|
+
respond(input: Input, inspectRationale?: InspectRationale): Promise<Response>;
|
|
130
|
+
/** Text view of {@link respond}. NUL bytes (0x00) are stripped before
|
|
131
|
+
* decoding — they are structural padding in text answers. LOSSY for a
|
|
132
|
+
* binary answer that legitimately contains NULs: use {@link respond} and
|
|
133
|
+
* read `bytes` directly for binary/grid modalities. */
|
|
134
|
+
respondText(
|
|
135
|
+
input: string,
|
|
136
|
+
inspectRationale?: InspectRationale,
|
|
137
|
+
): Promise<string>;
|
|
138
|
+
embedding(input: Input): Promise<Vec | null>;
|
|
139
|
+
/** Kinship note: the vector arm below is a miniature of recall's tier 3
|
|
140
|
+
* (resonate → reach gate → read out the nearest form's bytes) — the
|
|
141
|
+
* read-out direction of the same operation, without recall's grounding
|
|
142
|
+
* ladder. If either side's acceptance rule changes, revisit the other. */
|
|
143
|
+
express(idOrV: number | Vec): Promise<Uint8Array>;
|
|
144
|
+
ingest(
|
|
145
|
+
input: Input | (Input | [Input, Input])[],
|
|
146
|
+
second?: Input,
|
|
147
|
+
): Promise<
|
|
148
|
+
(Sema & {
|
|
149
|
+
id: number;
|
|
150
|
+
}) | undefined
|
|
151
|
+
>;
|
|
152
|
+
private extensionHost;
|
|
153
|
+
private groundedContinuation;
|
|
154
|
+
/** Re-index structurally-important nodes whose gists were evicted from the
|
|
155
|
+
* pending cache before they reached the content index. See {@link
|
|
156
|
+
* Store.repairContentIndex} for the contract; this method wires the
|
|
157
|
+
* Mind's perception into the store's repair walk.
|
|
158
|
+
*
|
|
159
|
+
* Run this after training or at checkpoints to restore recall reach for
|
|
160
|
+
* nodes that bridge experiences but were never indexed. A pure interior
|
|
161
|
+
* node (no edges, no halo) is deliberately skipped — it is scaffolding,
|
|
162
|
+
* not an experience root or bridge, and regenerating its gist would waste
|
|
163
|
+
* I/O and index space for no recall benefit.
|
|
164
|
+
*
|
|
165
|
+
* @param minParents only repair nodes with ≥ this many structural parents
|
|
166
|
+
* (default 2 — structural bridges)
|
|
167
|
+
* @returns number of nodes added to the content index */
|
|
168
|
+
repairContentIndex(minParents?: number): Promise<number>;
|
|
169
|
+
save(): Promise<Uint8Array>;
|
|
170
|
+
static load(snapshot: Uint8Array, store: Store): Promise<Mind>;
|
|
171
|
+
static loadFromStore(store: Store): Promise<Mind>;
|
|
147
172
|
}
|