@hviana/sema 0.4.0 → 0.4.2
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/CONTRIBUTING.md +92 -10
- package/LICENSE.md +2 -2
- package/package.json +1 -1
- package/src/ingest-cache.ts +4 -0
- package/src/meter.ts +5 -0
- package/src/mind/attention.ts +18 -1
- package/src/mind/bridge.ts +292 -54
- package/src/mind/junction.ts +21 -7
- package/src/mind/match.ts +92 -1
- package/src/mind/mechanisms/cast.ts +12 -0
- package/src/mind/mechanisms/confluence.ts +30 -1
- package/src/mind/mechanisms/cover.ts +36 -4
- package/src/mind/mechanisms/recall.ts +21 -44
- package/src/mind/mind.ts +39 -2
- package/src/mind/pipeline-mechanism.ts +86 -4
- package/src/mind/pipeline.ts +1 -1
- package/src/mind/reasoning.ts +15 -8
- package/src/mind/recognition.ts +40 -0
- package/src/mind/resonance.ts +0 -0
- package/src/mind/traverse.ts +17 -15
- package/src/mind/types.ts +10 -0
- package/test/49-natural-units-synonym-bridge.test.mjs +56 -15
- package/dist/example/demo.d.ts +0 -1
- package/dist/example/demo.js +0 -39
- package/dist/example/train_base.d.ts +0 -87
- package/dist/example/train_base.js +0 -2252
- 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 -26
- package/dist/src/canon.js +0 -57
- 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 -175
- package/dist/src/geometry.js +0 -823
- 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 -161
- package/dist/src/meter.d.ts +0 -171
- package/dist/src/meter.js +0 -269
- 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 -414
- package/dist/src/mind/attention.js +0 -2065
- package/dist/src/mind/bridge.d.ts +0 -39
- package/dist/src/mind/bridge.js +0 -738
- package/dist/src/mind/canonical.d.ts +0 -34
- package/dist/src/mind/canonical.js +0 -93
- 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 -134
- package/dist/src/mind/junction.js +0 -331
- package/dist/src/mind/learning.d.ts +0 -75
- package/dist/src/mind/learning.js +0 -270
- package/dist/src/mind/match.d.ts +0 -166
- package/dist/src/mind/match.js +0 -565
- 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 -773
- package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
- package/dist/src/mind/mechanisms/confluence.js +0 -225
- package/dist/src/mind/mechanisms/cover.d.ts +0 -6
- package/dist/src/mind/mechanisms/cover.js +0 -203
- package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
- package/dist/src/mind/mechanisms/extraction.js +0 -300
- package/dist/src/mind/mechanisms/recall.d.ts +0 -16
- package/dist/src/mind/mechanisms/recall.js +0 -388
- package/dist/src/mind/mind.d.ts +0 -330
- package/dist/src/mind/mind.js +0 -594
- package/dist/src/mind/pipeline-mechanism.d.ts +0 -172
- package/dist/src/mind/pipeline-mechanism.js +0 -382
- package/dist/src/mind/pipeline.d.ts +0 -49
- package/dist/src/mind/pipeline.js +0 -275
- package/dist/src/mind/primitives.d.ts +0 -66
- package/dist/src/mind/primitives.js +0 -306
- 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 -40
- package/dist/src/mind/reasoning.js +0 -272
- package/dist/src/mind/recognition.d.ts +0 -20
- package/dist/src/mind/recognition.js +0 -463
- package/dist/src/mind/resonance.d.ts +0 -23
- package/dist/src/mind/resonance.js +0 -0
- 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 -124
- package/dist/src/mind/traverse.js +0 -649
- package/dist/src/mind/types.d.ts +0 -323
- package/dist/src/mind/types.js +0 -130
- 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 -283
- package/dist/src/sema.d.ts +0 -31
- package/dist/src/sema.js +0 -63
- package/dist/src/store-sqlite.d.ts +0 -184
- package/dist/src/store-sqlite.js +0 -942
- package/dist/src/store.d.ts +0 -678
- package/dist/src/store.js +0 -1703
- package/dist/src/vec.d.ts +0 -31
- package/dist/src/vec.js +0 -109
package/dist/src/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from "./bytes.js";
|
|
2
|
-
export * from "./vec.js";
|
|
3
|
-
export * from "./sema.js";
|
|
4
|
-
export * from "./alphabet.js";
|
|
5
|
-
export * from "./geometry.js";
|
|
6
|
-
export * from "./store.js";
|
|
7
|
-
export * from "./meter.js";
|
|
8
|
-
export * from "./mind/rationale.js";
|
|
9
|
-
export * from "./mind/index.js";
|
|
10
|
-
export * from "./store-sqlite.js";
|
|
11
|
-
export * from "./config.js";
|
|
12
|
-
export * from "./extension.js";
|
|
13
|
-
export * from "./canon.js";
|
|
14
|
-
export * from "./ingest-cache.js";
|
|
15
|
-
export { IvfIndex, Prng, RaBitQuantizer, VectorDatabase, } from "./rabitq-ivf/src/index.js";
|
|
16
|
-
export type { DatabaseOptions, ExternalId, IvfConfig, IvfHit, QueryContext, QueryResult, RaBitQOptions, StorageStats, } from "./rabitq-ivf/src/index.js";
|
|
17
|
-
export * from "./derive/src/index.js";
|
package/dist/src/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// sema — an elementary, recursive, weight-free multimodal mind.
|
|
2
|
-
// One structure, one verb, one memory. See AGENTS.md for the full algorithm.
|
|
3
|
-
export * from "./bytes.js";
|
|
4
|
-
export * from "./vec.js";
|
|
5
|
-
export * from "./sema.js";
|
|
6
|
-
export * from "./alphabet.js";
|
|
7
|
-
export * from "./geometry.js";
|
|
8
|
-
export * from "./store.js";
|
|
9
|
-
export * from "./meter.js";
|
|
10
|
-
export * from "./mind/rationale.js";
|
|
11
|
-
export * from "./mind/index.js";
|
|
12
|
-
export * from "./store-sqlite.js";
|
|
13
|
-
export * from "./config.js";
|
|
14
|
-
export * from "./extension.js";
|
|
15
|
-
export * from "./canon.js";
|
|
16
|
-
export * from "./ingest-cache.js";
|
|
17
|
-
// rabitq-ivf: the partitioned (IVF) vector index over 1-bit RaBitQ codes.
|
|
18
|
-
export { IvfIndex, Prng, RaBitQuantizer, VectorDatabase, } from "./rabitq-ivf/src/index.js";
|
|
19
|
-
export * from "./derive/src/index.js";
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Mind } from "./mind/index.js";
|
|
2
|
-
import { type Sema } from "./sema.js";
|
|
3
|
-
import type { Input } from "./mind/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* An ingest cache layered over a Mind.
|
|
6
|
-
*
|
|
7
|
-
* Usage (drop-in for mind.ingest in training loops):
|
|
8
|
-
* const ci = new CachedIngest(mind);
|
|
9
|
-
* await ci.ingest(ctx, cont); // caches both sides
|
|
10
|
-
* await ci.ingest("some text"); // caches the single text
|
|
11
|
-
* await ci.ingest([[ctx, cont]]); // array form
|
|
12
|
-
*
|
|
13
|
-
* All other Mind methods (respond, save, …) are accessed on `ci.mind`.
|
|
14
|
-
*/
|
|
15
|
-
export declare class CachedIngest {
|
|
16
|
-
readonly mind: Mind;
|
|
17
|
-
/** One unified, content-addressed memo of interned inputs. Each value holds
|
|
18
|
-
* Float32 root vector (D·4 bytes) plus a small id array, so the byte budget
|
|
19
|
-
* is spent on the inputs most worth remembering (LRU). */
|
|
20
|
-
private _memo;
|
|
21
|
-
hits: number;
|
|
22
|
-
misses: number;
|
|
23
|
-
constructor(mind: Mind);
|
|
24
|
-
private newMemo;
|
|
25
|
-
private keyOf;
|
|
26
|
-
ingest(input: Input | (Input | [Input, Input])[], second?: Input): Promise<(Sema & {
|
|
27
|
-
id: number;
|
|
28
|
-
}) | undefined>;
|
|
29
|
-
/** Resolve an input to its interned nodes, from the memo when its content has
|
|
30
|
-
* been seen before, else by the Mind's OWN untracked {@link deposit}
|
|
31
|
-
* (perceive + intern + sub-span/containment indexing — identical to the
|
|
32
|
-
* direct path; those writes are durable and idempotent, so a later memo hit
|
|
33
|
-
* legitimately skips them). This is the single expensive operation both
|
|
34
|
-
* ingest paths share; caching it here is what makes every repeated input —
|
|
35
|
-
* in any role — cheap. */
|
|
36
|
-
private resolveInput;
|
|
37
|
-
private ingestPair;
|
|
38
|
-
private ingestOne;
|
|
39
|
-
clear(): void;
|
|
40
|
-
get size(): number;
|
|
41
|
-
}
|
package/dist/src/ingest-cache.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// ingest-cache.ts — ingest-level cache for Mind.
|
|
2
|
-
//
|
|
3
|
-
// Wraps a Mind and memoises the expensive, content-determined half of ingestion:
|
|
4
|
-
// turning ONE input (a context, a continuation, or a bare experience) into its
|
|
5
|
-
// interned graph nodes. Perception (riverFold) and interning are a PURE function
|
|
6
|
-
// of the input bytes — the same bytes always cut the same way and hash-cons to
|
|
7
|
-
// the same node ids — so the result can be cached by content and reused wherever
|
|
8
|
-
// those same bytes appear again, in ANY role.
|
|
9
|
-
//
|
|
10
|
-
// This is why the cache keys on the single input, not on the (context,
|
|
11
|
-
// continuation) pair: real training corpora repeat content at the INPUT level far
|
|
12
|
-
// more than at the pair level — a shared system/tool preamble in front of every
|
|
13
|
-
// row, a common answer ("Yes.", a refusal) under many questions, an accumulated
|
|
14
|
-
// dialogue prefix, an exactly-duplicated row. A pair-level key sees none of these
|
|
15
|
-
// (the pair as a whole is almost always unique); the input-level key catches them
|
|
16
|
-
// all, and a context that recurs as a continuation (or vice versa) hits too.
|
|
17
|
-
//
|
|
18
|
-
// On a cache hit only the cheap relational writes are replayed — the edge and the
|
|
19
|
-
// two halo pours for a pair, or the part-chain links for a single — while the
|
|
20
|
-
// perceive + internTree work (the dominant cost, and on a large store the dominant
|
|
21
|
-
// VECTOR-INDEX cost too) is skipped entirely. The interned node ids are stable
|
|
22
|
-
// across eviction: a re-perceive of evicted content reproduces the same ids by
|
|
23
|
-
// the store's hash-cons, so correctness never depends on a hit.
|
|
24
|
-
//
|
|
25
|
-
// DEPOSITION IS THE MIND'S OWN: every miss goes through the same
|
|
26
|
-
// {@link deposit} the direct Mind.ingest path uses — perception, interning,
|
|
27
|
-
// sub-span/window indexing, durable CONTAINMENT edges, whole-stream flat
|
|
28
|
-
// branch, changed-node tracking against the Mind's `_prevSeen` — so a store
|
|
29
|
-
// trained through this cache is structurally IDENTICAL to one trained by
|
|
30
|
-
// calling mind.ingest() directly (this class used to re-implement the deposit
|
|
31
|
-
// and drifted: no indexSubSpans/addContainer, wrong part-link stride). Only
|
|
32
|
-
// the memo layer lives here. Behaviour is identical to mind.ingest() (links
|
|
33
|
-
// and halos are reinforced on every call), just faster when content repeats.
|
|
34
|
-
import { deposit, dispatchIngest, ingestOne as depositOne, } from "./mind/learning.js";
|
|
35
|
-
import { bindSeat, companySignature } from "./sema.js";
|
|
36
|
-
import { BoundedMap } from "./store.js";
|
|
37
|
-
/**
|
|
38
|
-
* An ingest cache layered over a Mind.
|
|
39
|
-
*
|
|
40
|
-
* Usage (drop-in for mind.ingest in training loops):
|
|
41
|
-
* const ci = new CachedIngest(mind);
|
|
42
|
-
* await ci.ingest(ctx, cont); // caches both sides
|
|
43
|
-
* await ci.ingest("some text"); // caches the single text
|
|
44
|
-
* await ci.ingest([[ctx, cont]]); // array form
|
|
45
|
-
*
|
|
46
|
-
* All other Mind methods (respond, save, …) are accessed on `ci.mind`.
|
|
47
|
-
*/
|
|
48
|
-
export class CachedIngest {
|
|
49
|
-
mind;
|
|
50
|
-
/** One unified, content-addressed memo of interned inputs. Each value holds
|
|
51
|
-
* Float32 root vector (D·4 bytes) plus a small id array, so the byte budget
|
|
52
|
-
* is spent on the inputs most worth remembering (LRU). */
|
|
53
|
-
_memo;
|
|
54
|
-
hits = 0;
|
|
55
|
-
misses = 0;
|
|
56
|
-
constructor(mind) {
|
|
57
|
-
this.mind = mind;
|
|
58
|
-
this._memo = this.newMemo();
|
|
59
|
-
}
|
|
60
|
-
newMemo() {
|
|
61
|
-
return new BoundedMap(this.mind.cfg.store.ingestCacheBytes, (c) => c.rootV.byteLength + c.partIds.length * 4 + 8 + c.keyBytes);
|
|
62
|
-
}
|
|
63
|
-
// ── cache key ───────────────────────────────────────────────────────────
|
|
64
|
-
// Content key for an input, or null when the input cannot be keyed reliably
|
|
65
|
-
// — in which case it BYPASSES the cache (recomputed every time) rather than
|
|
66
|
-
// risk a collision returning the wrong nodes. A string is its own key; raw
|
|
67
|
-
// bytes hash by FNV-1a (+ length, so a hash collision still needs an equal
|
|
68
|
-
// length to alias); a Grid / Grid[] has no cheap stable key, so it bypasses.
|
|
69
|
-
keyOf(input) {
|
|
70
|
-
if (typeof input === "string")
|
|
71
|
-
return "S:" + input;
|
|
72
|
-
if (input instanceof Uint8Array) {
|
|
73
|
-
// FNV-1a — no spread onto the call stack, safe on large binary inputs.
|
|
74
|
-
let h = 0x811c9dc5 >>> 0;
|
|
75
|
-
for (let i = 0; i < input.length; i++) {
|
|
76
|
-
h ^= input[i];
|
|
77
|
-
h = Math.imul(h, 0x01000193) >>> 0;
|
|
78
|
-
}
|
|
79
|
-
return "B:" + (h >>> 0).toString(16) + ":" + input.length;
|
|
80
|
-
}
|
|
81
|
-
return null; // Grid / Grid[] — bypass the cache
|
|
82
|
-
}
|
|
83
|
-
// ── public API ────────────────────────────────────────────────────────
|
|
84
|
-
async ingest(input, second) {
|
|
85
|
-
// One shape-reading for both ingest paths — see {@link dispatchIngest}.
|
|
86
|
-
return dispatchIngest(input, second, (i) => this.ingestOne(i), (a, b) => this.ingestPair(a, b));
|
|
87
|
-
}
|
|
88
|
-
// ── the one cached step: perceive + intern + index ONE input ──────────────
|
|
89
|
-
/** Resolve an input to its interned nodes, from the memo when its content has
|
|
90
|
-
* been seen before, else by the Mind's OWN untracked {@link deposit}
|
|
91
|
-
* (perceive + intern + sub-span/containment indexing — identical to the
|
|
92
|
-
* direct path; those writes are durable and idempotent, so a later memo hit
|
|
93
|
-
* legitimately skips them). This is the single expensive operation both
|
|
94
|
-
* ingest paths share; caching it here is what makes every repeated input —
|
|
95
|
-
* in any role — cheap. */
|
|
96
|
-
async resolveInput(input) {
|
|
97
|
-
const key = this.keyOf(input);
|
|
98
|
-
if (key !== null) {
|
|
99
|
-
const cached = this._memo.get(key);
|
|
100
|
-
if (cached) {
|
|
101
|
-
this.hits++;
|
|
102
|
-
return cached;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
this.misses++;
|
|
106
|
-
// The full deposit, untracked (a continuation must not break the tracked
|
|
107
|
-
// deposit chain). `partIds` are the root's immediate children, already
|
|
108
|
-
// interned by the deposit — free to capture. Only the root vector and
|
|
109
|
-
// ids are retained; the tree is GC'd.
|
|
110
|
-
const { tree, rootId, ids } = await deposit(this.mind, input, false);
|
|
111
|
-
const partIds = tree.kids
|
|
112
|
-
? tree.kids.map((k) => ids.get(k))
|
|
113
|
-
: [rootId];
|
|
114
|
-
const entry = {
|
|
115
|
-
rootV: tree.v,
|
|
116
|
-
rootId,
|
|
117
|
-
partIds,
|
|
118
|
-
// ~2 bytes per UTF-16 code unit — the key is retained by the map.
|
|
119
|
-
keyBytes: key !== null ? key.length * 2 : 0,
|
|
120
|
-
};
|
|
121
|
-
if (key !== null)
|
|
122
|
-
this._memo.set(key, entry);
|
|
123
|
-
return entry;
|
|
124
|
-
}
|
|
125
|
-
// ── pair ingest ───────────────────────────────────────────────────────
|
|
126
|
-
async ingestPair(ctx, cont) {
|
|
127
|
-
// The CONTEXT side is TRACKED (it continues the Mind's deposit chain and
|
|
128
|
-
// is the growing, unique-per-turn side — a cache miss anyway), via the
|
|
129
|
-
// same {@link deposit} the direct path uses; the continuation resolves
|
|
130
|
-
// through the memo.
|
|
131
|
-
const c = await deposit(this.mind, ctx, true);
|
|
132
|
-
const b = await this.resolveInput(cont);
|
|
133
|
-
// EDGE on the FULL context (disambiguates a shared pivot). HALO only on the
|
|
134
|
-
// CHANGED NODES — the coherent new subtrees this turn adds — so a recurring
|
|
135
|
-
// shared prefix never collects halo mass. (See Mind.ingestPair.)
|
|
136
|
-
await this.mind.store.link(c.rootId, b.rootId);
|
|
137
|
-
// Halos pour company SIGNATURES (identity), not gists (content) — see
|
|
138
|
-
// companySignature in sema.ts.
|
|
139
|
-
const contSeat = bindSeat(this.mind.space, companySignature(this.mind.space, b.rootId), 1);
|
|
140
|
-
for (const part of c.changed) {
|
|
141
|
-
const partId = c.ids.get(part);
|
|
142
|
-
await this.mind.store.pourHalo(partId, contSeat);
|
|
143
|
-
await this.mind.store.pourHalo(b.rootId, bindSeat(this.mind.space, companySignature(this.mind.space, partId), 0));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// ── one-side ingest ───────────────────────────────────────────────────
|
|
147
|
-
async ingestOne(input) {
|
|
148
|
-
// A bare experience is the direct path verbatim — tracked deposit, root
|
|
149
|
-
// marked a resonance target, part chain linked at the maxGroup stride.
|
|
150
|
-
// (The tracked side is a memo miss by design, so there is nothing for the
|
|
151
|
-
// cache to add here.)
|
|
152
|
-
return depositOne(this.mind, input);
|
|
153
|
-
}
|
|
154
|
-
// ── helpers ───────────────────────────────────────────────────────────
|
|
155
|
-
clear() {
|
|
156
|
-
this._memo = this.newMemo();
|
|
157
|
-
}
|
|
158
|
-
get size() {
|
|
159
|
-
return this._memo.size;
|
|
160
|
-
}
|
|
161
|
-
}
|
package/dist/src/meter.d.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/** Per-phase accumulation — one entry per mechanism `floor`/`run` and per
|
|
2
|
-
* named stage.
|
|
3
|
-
*
|
|
4
|
-
* PHASES NEST, AND ARE NOT DISJOINT. `think` contains every mechanism
|
|
5
|
-
* phase; a mechanism's `floor` contains whatever shared analysis it
|
|
6
|
-
* first-touched (`attention`, `weave`); `recall.run` contains
|
|
7
|
-
* `substitutionBridge`, which contains `recall.exhaustiveResonate`. Read a
|
|
8
|
-
* phase as "wall-clock spent inside this, inclusive" — never sum them and
|
|
9
|
-
* expect the total. `CostReport.elapsedMs` is the only whole.
|
|
10
|
-
*
|
|
11
|
-
* Shared analyses are charged to THEMSELVES, not to the mechanism that
|
|
12
|
-
* first-touched them: the first toucher pays the wall clock, but every
|
|
13
|
-
* later consumer gets the result free, so blaming it would misread which
|
|
14
|
-
* work is expensive. (Before this, the profile read "cast.floor costs
|
|
15
|
-
* 2.9 s"; what actually cost 2.7 s of that was the consensus climb, which
|
|
16
|
-
* cast merely paid for on everyone's behalf.) */
|
|
17
|
-
export interface PhaseCost {
|
|
18
|
-
/** How many times the phase ran. */
|
|
19
|
-
calls: number;
|
|
20
|
-
/** Wall-clock milliseconds spent inside it (non-deterministic). */
|
|
21
|
-
ms: number;
|
|
22
|
-
/** Work counters accrued INSIDE this phase — the same names as
|
|
23
|
-
* {@link CostReport.counters}, differenced across the phase's entry and
|
|
24
|
-
* exit, summed over its calls. Deterministic, unlike `ms`, and the field
|
|
25
|
-
* that answers "which phase did those 75,000 byte reads?" — a question a
|
|
26
|
-
* whole-response counter total cannot. Inclusive, like `ms`: a nested
|
|
27
|
-
* phase's work is counted in its parent too. */
|
|
28
|
-
counters: Record<string, number>;
|
|
29
|
-
}
|
|
30
|
-
/** A snapshot of one inference call's computational usage. Plain data —
|
|
31
|
-
* JSON-serialisable, diffable between runs. */
|
|
32
|
-
export interface CostReport {
|
|
33
|
-
version: 1;
|
|
34
|
-
/** Wall-clock milliseconds of the whole call (non-deterministic). */
|
|
35
|
-
elapsedMs: number;
|
|
36
|
-
/** Query length in bytes — the scale every other number is read against. */
|
|
37
|
-
queryBytes: number;
|
|
38
|
-
/** Deterministic work counters, by layer. */
|
|
39
|
-
counters: Record<string, number>;
|
|
40
|
-
/** Per-phase call counts and millisecond totals, insertion-ordered.
|
|
41
|
-
* NESTED — see {@link PhaseCost}; do not sum. */
|
|
42
|
-
phases: Record<string, PhaseCost>;
|
|
43
|
-
}
|
|
44
|
-
/** The mutable accumulator. One is created per profiled inference call and
|
|
45
|
-
* handed to every layer through `ctx.meter` / `store.meter`. */
|
|
46
|
-
export declare class Meter {
|
|
47
|
-
/** `store.get` — one node record materialised (cache hit or DB row). */
|
|
48
|
-
nodeRecords: number;
|
|
49
|
-
/** `store.bytes` / `store.bytesPrefix` — one reconstruction request. */
|
|
50
|
-
byteReads: number;
|
|
51
|
-
/** Bytes actually handed back by those reads — the real I/O volume, and
|
|
52
|
-
* the number that exposes an unbounded read (AGENTS §2.8) that a call
|
|
53
|
-
* count alone hides. */
|
|
54
|
-
bytesRead: number;
|
|
55
|
-
/** `store.contentLen`. */
|
|
56
|
-
lenReads: number;
|
|
57
|
-
/** `store.findLeaf`. */
|
|
58
|
-
leafLookups: number;
|
|
59
|
-
/** `store.findBranch`. */
|
|
60
|
-
branchLookups: number;
|
|
61
|
-
/** `store.canonFind` — equivalence-class candidate proposal. */
|
|
62
|
-
canonLookups: number;
|
|
63
|
-
/** `parents` + `parentsFirst` — materialising parent reads. */
|
|
64
|
-
parentReads: number;
|
|
65
|
-
/** `hasParents` — indexed existence probe. */
|
|
66
|
-
parentProbes: number;
|
|
67
|
-
/** `chainRun` — one bounded transparent-chain climb. */
|
|
68
|
-
chainRuns: number;
|
|
69
|
-
/** `containers` + `containersSlice`. */
|
|
70
|
-
containerReads: number;
|
|
71
|
-
/** `hasContainers` — indexed existence probe. */
|
|
72
|
-
containerProbes: number;
|
|
73
|
-
/** `next` + `nextFirst`. */
|
|
74
|
-
edgeReads: number;
|
|
75
|
-
/** `hasNext` — indexed existence probe. */
|
|
76
|
-
edgeProbes: number;
|
|
77
|
-
/** `prev` + `prevFirst`. */
|
|
78
|
-
prevReads: number;
|
|
79
|
-
/** `prevCount` — indexed count probe. */
|
|
80
|
-
prevProbes: number;
|
|
81
|
-
/** `halo` — one halo vector decoded. */
|
|
82
|
-
haloReads: number;
|
|
83
|
-
/** `hasHalo` + `haloMass` — probes that never decode a vector. */
|
|
84
|
-
haloProbes: number;
|
|
85
|
-
/** `resonate` calls that descended the content index. */
|
|
86
|
-
annQueries: number;
|
|
87
|
-
/** `resonate` calls served from the per-flush read cache. */
|
|
88
|
-
annCacheHits: number;
|
|
89
|
-
/** Stored vectors the content index actually scored — the dominant cost of
|
|
90
|
-
* a query on a large store, and the one counter that grows with N when a
|
|
91
|
-
* budget is missing. */
|
|
92
|
-
annVectorReads: number;
|
|
93
|
-
/** `resonateHalo` calls. */
|
|
94
|
-
haloQueries: number;
|
|
95
|
-
/** `perceive` calls that actually folded (memo misses only). */
|
|
96
|
-
perceptions: number;
|
|
97
|
-
/** Bytes folded by those perceptions — perception is O(bytes), so this is
|
|
98
|
-
* its true cost, and it is what a multi-turn regression shows up in first
|
|
99
|
-
* (re-folding the whole context instead of the new turn). */
|
|
100
|
-
perceivedBytes: number;
|
|
101
|
-
/** `perceive` calls served from the per-response / conversation memo. */
|
|
102
|
-
perceiveHits: number;
|
|
103
|
-
/** `recognise` calls that actually ran. */
|
|
104
|
-
recognitions: number;
|
|
105
|
-
/** Bytes recognised by those calls. */
|
|
106
|
-
recognisedBytes: number;
|
|
107
|
-
/** `recognise` calls served from the memo. */
|
|
108
|
-
recogniseHits: number;
|
|
109
|
-
/** `resolve` — whole-span content-addressed identity requests. */
|
|
110
|
-
resolves: number;
|
|
111
|
-
/** `climbAttentionAll` calls that actually climbed. */
|
|
112
|
-
climbs: number;
|
|
113
|
-
/** `climbAttentionAll` calls served from `climbMemo`. */
|
|
114
|
-
climbHits: number;
|
|
115
|
-
/** Query regions the climb voted on, summed over climbs. */
|
|
116
|
-
climbRegions: number;
|
|
117
|
-
/** Nodes popped and examined by `edgeAncestors` ascents — the climb's
|
|
118
|
-
* inner loop, and the thing `hubBound` is supposed to be bounding. */
|
|
119
|
-
ancestorVisits: number;
|
|
120
|
-
/** `alignGraded` / `alignRuns` invocations. */
|
|
121
|
-
alignments: number;
|
|
122
|
-
/** Σ (query bytes × context bytes) over those alignments — the alignment
|
|
123
|
-
* family is quadratic, so this is the honest unit. */
|
|
124
|
-
alignCells: number;
|
|
125
|
-
/** `junctionContainersFrom` ascents started — the cross-region ladder's
|
|
126
|
-
* and the bridge's shared "which learnt whole contains these two forms?"
|
|
127
|
-
* walk. */
|
|
128
|
-
junctionWalks: number;
|
|
129
|
-
/** Nodes popped by those ascents, against their √N·W budget — the counter
|
|
130
|
-
* that shows whether the walks are deciding early or burning the budget. */
|
|
131
|
-
junctionPops: number;
|
|
132
|
-
/** `lightestDerivation` searches started. */
|
|
133
|
-
searches: number;
|
|
134
|
-
/** Chart items popped by those searches. */
|
|
135
|
-
searchPops: number;
|
|
136
|
-
/** Chart items pushed by those searches. */
|
|
137
|
-
searchPushes: number;
|
|
138
|
-
/** `floor()` calls that returned a bound (the mechanism could fire). */
|
|
139
|
-
mechanismFloors: number;
|
|
140
|
-
/** `floor()` calls that returned null (structurally impossible). */
|
|
141
|
-
mechanismSkips: number;
|
|
142
|
-
/** `run()` calls — the ones the floor pruning let through. */
|
|
143
|
-
mechanismRuns: number;
|
|
144
|
-
/** Candidates the decider weighed. */
|
|
145
|
-
candidates: number;
|
|
146
|
-
/** Candidates refused before the competition for explaining less than 1/W
|
|
147
|
-
* of the query — the honesty-density floor (see pipeline.ts `consider`). */
|
|
148
|
-
thinRejects: number;
|
|
149
|
-
private readonly _phases;
|
|
150
|
-
private readonly _t0;
|
|
151
|
-
/** Every work counter's current value, by name — the snapshot `time`
|
|
152
|
-
* differences to attribute work to a phase. */
|
|
153
|
-
private snapshot;
|
|
154
|
-
/** Charge `ms`, one call, and a counter delta to a named phase.
|
|
155
|
-
* Insertion-ordered, so a report reads in execution order. */
|
|
156
|
-
charge(phase: string, ms: number, delta?: Record<string, number>): void;
|
|
157
|
-
/** Time one async phase and attribute the work done inside it. Returns
|
|
158
|
-
* the awaited value untouched — a meter never changes what a layer
|
|
159
|
-
* computes, only what is known about it. */
|
|
160
|
-
time<T>(phase: string, fn: () => Promise<T>): Promise<T>;
|
|
161
|
-
/** The finished report. Zero-valued counters are dropped: a report should
|
|
162
|
-
* show what a query DID, not the whole vocabulary of what it might have. */
|
|
163
|
-
report(queryBytes: number): CostReport;
|
|
164
|
-
}
|
|
165
|
-
/** Sum a set of reports into one — for aggregating a battery of probes or a
|
|
166
|
-
* multi-turn session. `elapsedMs` and `queryBytes` add; counters and phases
|
|
167
|
-
* merge by key. */
|
|
168
|
-
export declare function sumReports(reports: readonly CostReport[]): CostReport;
|
|
169
|
-
/** A human-readable rendering of a report — the shape a profiling run prints.
|
|
170
|
-
* Pure formatting; no ANSI, so it is safe to log anywhere. */
|
|
171
|
-
export declare function formatReport(r: CostReport): string;
|