@hviana/sema 0.4.2 → 0.4.3
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 +136 -0
- package/dist/src/derive/src/deduction.js +159 -0
- package/dist/src/derive/src/index.d.ts +8 -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 +175 -0
- package/dist/src/geometry.js +823 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +19 -0
- package/dist/src/ingest-cache.d.ts +41 -0
- package/dist/src/ingest-cache.js +165 -0
- package/dist/src/meter.d.ts +176 -0
- package/dist/src/meter.js +274 -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 +414 -0
- package/dist/src/mind/attention.js +2082 -0
- package/dist/src/mind/bridge.d.ts +39 -0
- package/dist/src/mind/bridge.js +947 -0
- package/dist/src/mind/canonical.d.ts +34 -0
- package/dist/src/mind/canonical.js +93 -0
- package/dist/src/mind/graph-search.d.ts +294 -0
- package/dist/src/mind/graph-search.js +996 -0
- package/dist/src/mind/index.d.ts +9 -0
- package/dist/src/mind/index.js +5 -0
- package/dist/src/mind/junction.d.ts +137 -0
- package/dist/src/mind/junction.js +342 -0
- package/dist/src/mind/learning.d.ts +75 -0
- package/dist/src/mind/learning.js +270 -0
- package/dist/src/mind/match.d.ts +181 -0
- package/dist/src/mind/match.js +655 -0
- package/dist/src/mind/mechanisms/alu.d.ts +4 -0
- package/dist/src/mind/mechanisms/alu.js +36 -0
- package/dist/src/mind/mechanisms/cast.d.ts +89 -0
- package/dist/src/mind/mechanisms/cast.js +784 -0
- package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
- package/dist/src/mind/mechanisms/confluence.js +255 -0
- package/dist/src/mind/mechanisms/cover.d.ts +6 -0
- package/dist/src/mind/mechanisms/cover.js +227 -0
- package/dist/src/mind/mechanisms/extraction.d.ts +33 -0
- package/dist/src/mind/mechanisms/extraction.js +300 -0
- package/dist/src/mind/mechanisms/recall.d.ts +16 -0
- package/dist/src/mind/mechanisms/recall.js +364 -0
- package/dist/src/mind/mind.d.ts +337 -0
- package/dist/src/mind/mind.js +617 -0
- package/dist/src/mind/pipeline-mechanism.d.ts +172 -0
- package/dist/src/mind/pipeline-mechanism.js +465 -0
- package/dist/src/mind/pipeline.d.ts +49 -0
- package/dist/src/mind/pipeline.js +275 -0
- package/dist/src/mind/primitives.d.ts +66 -0
- package/dist/src/mind/primitives.js +306 -0
- package/dist/src/mind/rationale.d.ts +139 -0
- package/dist/src/mind/rationale.js +163 -0
- package/dist/src/mind/reasoning.d.ts +40 -0
- package/dist/src/mind/reasoning.js +280 -0
- package/dist/src/mind/recognition.d.ts +20 -0
- package/dist/src/mind/recognition.js +504 -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 +126 -0
- package/dist/src/mind/traverse.js +650 -0
- package/dist/src/mind/types.d.ts +333 -0
- package/dist/src/mind/types.js +130 -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 +678 -0
- package/dist/src/store.js +1703 -0
- package/dist/src/vec.d.ts +31 -0
- package/dist/src/vec.js +109 -0
- package/package.json +1 -1
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import type { DerivationStep } from "./graph-search.js";
|
|
2
|
+
import type { AncestorReach, Attention, AttentionRead, DFMode, MindContext, Region, RegionVote, SaturationInfo, SaturationStop } from "./types.js";
|
|
3
|
+
import { type StructuralPart } from "../geometry.js";
|
|
4
|
+
import { type JunctionSynonymSides } from "./junction.js";
|
|
5
|
+
import type { Vec } from "../vec.js";
|
|
6
|
+
/** How the newly-added graded junction ladder (junction.ts / attention.ts's
|
|
7
|
+
* {@link CrossRegionTier}) is reported on a `junctionVotes` entry. The
|
|
8
|
+
* instrumentation spec this implements predates that ladder and only knew
|
|
9
|
+
* two tiers ("exact" | "synonym"); with the richer `CrossRegionTier` now
|
|
10
|
+
* the real shape of a junction vote's provenance, `junctionVotes[].tier`
|
|
11
|
+
* reports it DIRECTLY (the tier as-is: "exact" | "single-synonym" |
|
|
12
|
+
* "double-synonym" | "structural-resonance") rather than collapsing every
|
|
13
|
+
* non-exact tier into a lossy "synonym" bucket — the whole point of
|
|
14
|
+
* exposing `tier` here is to let a debugger tell a halo-sibling
|
|
15
|
+
* substitution apart from a structural-resonance ANN guess, which the
|
|
16
|
+
* spec's original two-value type cannot do. */
|
|
17
|
+
export type ClimbConsensusJunctionTier = CrossRegionTier;
|
|
18
|
+
export type RegionOutcome = "voted" | "no-ann-hit" | "no-structural-reach" | "saturated-abstention" | "nonpositive-df-weight" | "contrastive-margin-rejection";
|
|
19
|
+
/** The best DIFFERENT-conclusion rival the contrastive-margin gate found
|
|
20
|
+
* while scanning an ordinary (approximate) region's ANN hits — spec §1.
|
|
21
|
+
* Its roots/saturation/contextsReached are already available through
|
|
22
|
+
* `reaches` (serialiseReaches) for `node`; not duplicated here. */
|
|
23
|
+
export interface ConsensusContrastiveRivalTrace {
|
|
24
|
+
node: number;
|
|
25
|
+
rank: number;
|
|
26
|
+
score: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ConsensusRegionTrace {
|
|
29
|
+
index: number;
|
|
30
|
+
source: "perceived" | "recognised";
|
|
31
|
+
span: [number, number];
|
|
32
|
+
chunk: boolean;
|
|
33
|
+
known: boolean;
|
|
34
|
+
canonicalId?: number;
|
|
35
|
+
canonicalUsable: boolean;
|
|
36
|
+
canonicalFailed: boolean;
|
|
37
|
+
annQueried: boolean;
|
|
38
|
+
annHitsReturned: number;
|
|
39
|
+
annHitsExamined: number;
|
|
40
|
+
selected?: {
|
|
41
|
+
source: "canonical" | "ann";
|
|
42
|
+
node: number;
|
|
43
|
+
rank?: number;
|
|
44
|
+
score: number;
|
|
45
|
+
fallback?: "orphan" | "saturated-tie";
|
|
46
|
+
};
|
|
47
|
+
reachNode?: number;
|
|
48
|
+
outcome: RegionOutcome;
|
|
49
|
+
idf?: number;
|
|
50
|
+
dfWeight?: number;
|
|
51
|
+
contrastiveMargin?: number;
|
|
52
|
+
contrastiveNoiseFloor?: number;
|
|
53
|
+
contrastiveRival?: ConsensusContrastiveRivalTrace;
|
|
54
|
+
mutualWeight?: number;
|
|
55
|
+
voteWeightPerRoot?: number;
|
|
56
|
+
focusWeightPerRoot?: number;
|
|
57
|
+
ordinaryVoteProduced: boolean;
|
|
58
|
+
superseded: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface ConsensusReachTrace {
|
|
61
|
+
node: number;
|
|
62
|
+
roots: number[];
|
|
63
|
+
contextsReached: number;
|
|
64
|
+
saturated: boolean;
|
|
65
|
+
saturation?: SaturationStop;
|
|
66
|
+
/** Nodes the climb processed — see {@link AncestorReach.visited}. Absent
|
|
67
|
+
* on payloads recorded before this field existed. */
|
|
68
|
+
visited?: number;
|
|
69
|
+
/** Maximum ascent distance — see {@link AncestorReach.maxDepth}. */
|
|
70
|
+
maxDepth?: number;
|
|
71
|
+
}
|
|
72
|
+
export type AnchorRejectionReason = "below-natural-break" | "below-consensus-floor" | "leading-saturation";
|
|
73
|
+
export interface ConsensusAnchorTrace {
|
|
74
|
+
anchor: number;
|
|
75
|
+
rank: number;
|
|
76
|
+
pooledVote: number;
|
|
77
|
+
idfVote: number;
|
|
78
|
+
candidateBreadth: number;
|
|
79
|
+
contributingVotes: number;
|
|
80
|
+
contributingEvidence: number;
|
|
81
|
+
breadth: number;
|
|
82
|
+
contributingSpans: Array<[number, number]>;
|
|
83
|
+
clusters: number;
|
|
84
|
+
commit: {
|
|
85
|
+
status: "root" | "overlap" | "rejected";
|
|
86
|
+
dominant: boolean;
|
|
87
|
+
passesNaturalBreak?: boolean;
|
|
88
|
+
passesConsensusFloor?: boolean;
|
|
89
|
+
pastLeadingSaturation?: boolean;
|
|
90
|
+
rejectionReasons: AnchorRejectionReason[];
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export interface JunctionVoteTrace {
|
|
94
|
+
container: number;
|
|
95
|
+
span: [number, number];
|
|
96
|
+
roots: number[];
|
|
97
|
+
sourceRegionIndices: number[];
|
|
98
|
+
explainedAwayRegionIndices: number[];
|
|
99
|
+
absorbed: number;
|
|
100
|
+
tier?: ClimbConsensusJunctionTier;
|
|
101
|
+
/** Zero-based index into `crossRegion.probes` — the probe this vote was
|
|
102
|
+
* produced from (spec §8). */
|
|
103
|
+
probe: number;
|
|
104
|
+
confidence: number;
|
|
105
|
+
/** "Evidence bytes" — the container-coverage byte count (the existing
|
|
106
|
+
* `bestCov` variable at the push site). */
|
|
107
|
+
evidenceBytes: number;
|
|
108
|
+
mutualWeight: number;
|
|
109
|
+
voteWeightPerRoot: number;
|
|
110
|
+
}
|
|
111
|
+
/** Whether one DAG/synonym tier attempt was even made for a probe, and how
|
|
112
|
+
* many candidate containers it returned — spec §2/§3. */
|
|
113
|
+
export interface CrossRegionTierAttemptTrace {
|
|
114
|
+
attempted: boolean;
|
|
115
|
+
candidatesReturned: number;
|
|
116
|
+
}
|
|
117
|
+
/** Aggregate outcome of the container-selection loop for a DAG/synonym tier
|
|
118
|
+
* that returned at least one container — spec §4. Only aggregate counts
|
|
119
|
+
* and the final outcome are recorded, never every candidate. */
|
|
120
|
+
export interface CrossRegionStructuralTrace {
|
|
121
|
+
tier: "exact" | "single-synonym" | "double-synonym";
|
|
122
|
+
selfEvidenceRejected: number;
|
|
123
|
+
contradictionRejected: number;
|
|
124
|
+
passedGuards: number;
|
|
125
|
+
selectedNode?: number;
|
|
126
|
+
outcome: "all-rejected" | "saturated" | "no-roots" | "nonpositive-idf" | "accepted";
|
|
127
|
+
}
|
|
128
|
+
/** One retained structural-resonance variant that actually issued its own
|
|
129
|
+
* ANN query — spec §5. */
|
|
130
|
+
export interface StructuralResonanceVariantTrace {
|
|
131
|
+
kind: StructuralVariant["kind"];
|
|
132
|
+
semanticConfidence: number;
|
|
133
|
+
leftSiblingId?: number;
|
|
134
|
+
rightSiblingId?: number;
|
|
135
|
+
annHitsReturned: number;
|
|
136
|
+
}
|
|
137
|
+
/** One merged structural-resonance proposal actually examined via
|
|
138
|
+
* edgeAncestors — spec §5. Retains node/variant/scores, but NOT
|
|
139
|
+
* roots/saturation/contextsReached/idf (already in `reaches`). */
|
|
140
|
+
export interface StructuralResonanceCandidateTrace {
|
|
141
|
+
node: number;
|
|
142
|
+
variant: StructuralVariant["kind"];
|
|
143
|
+
leftSiblingId?: number;
|
|
144
|
+
rightSiblingId?: number;
|
|
145
|
+
annScore: number;
|
|
146
|
+
semanticConfidence: number;
|
|
147
|
+
effectiveScore: number;
|
|
148
|
+
outcome: "saturated" | "no-roots" | "nonpositive-idf" | "same-as-endpoint" | "same-as-selected" | "selected" | "contrastive-rival";
|
|
149
|
+
}
|
|
150
|
+
export interface StructuralResonanceTrace {
|
|
151
|
+
variantBudget: number;
|
|
152
|
+
variants: StructuralResonanceVariantTrace[];
|
|
153
|
+
mergedProposals: number;
|
|
154
|
+
examined: StructuralResonanceCandidateTrace[];
|
|
155
|
+
contrastiveMargin?: number;
|
|
156
|
+
noiseFloor: number;
|
|
157
|
+
outcome: "ineligible" | "empty" | "no-valid-proposal" | "margin-rejected" | "accepted";
|
|
158
|
+
ineligibleReasons?: Array<"between-region" | "not-both-strong" | "not-both-known" | "gap-too-large">;
|
|
159
|
+
}
|
|
160
|
+
/** One cross-region pair the ladder actually probed — spec §2. Exactly one
|
|
161
|
+
* of these is pushed per pair that incremented `probes`. */
|
|
162
|
+
export interface CrossRegionProbeTrace {
|
|
163
|
+
leftRegionIndex: number;
|
|
164
|
+
rightRegionIndex: number;
|
|
165
|
+
betweenRegionIndices: number[];
|
|
166
|
+
exact: CrossRegionTierAttemptTrace;
|
|
167
|
+
singleSynonym: CrossRegionTierAttemptTrace;
|
|
168
|
+
doubleSynonym: CrossRegionTierAttemptTrace;
|
|
169
|
+
structural?: CrossRegionStructuralTrace;
|
|
170
|
+
resonance?: StructuralResonanceTrace;
|
|
171
|
+
outcome: "accepted" | "structural-rejected" | "resonance-ineligible" | "resonance-rejected";
|
|
172
|
+
}
|
|
173
|
+
export interface ClimbConsensusData {
|
|
174
|
+
version: 1;
|
|
175
|
+
cache: {
|
|
176
|
+
hit: boolean;
|
|
177
|
+
detailAvailable: boolean;
|
|
178
|
+
};
|
|
179
|
+
config: {
|
|
180
|
+
annK: number;
|
|
181
|
+
crossRegionProbeLimit: number;
|
|
182
|
+
mode: DFMode;
|
|
183
|
+
corpusN?: number;
|
|
184
|
+
dimension?: number;
|
|
185
|
+
hubBound?: number;
|
|
186
|
+
estimatorNoise?: number;
|
|
187
|
+
naturalBreak?: number;
|
|
188
|
+
consensusFloor?: number;
|
|
189
|
+
};
|
|
190
|
+
candidates: {
|
|
191
|
+
perceived: number;
|
|
192
|
+
recognised: number;
|
|
193
|
+
total: number;
|
|
194
|
+
};
|
|
195
|
+
regions?: ConsensusRegionTrace[];
|
|
196
|
+
reaches?: ConsensusReachTrace[];
|
|
197
|
+
crossRegion?: {
|
|
198
|
+
eligibleRegions: number;
|
|
199
|
+
maximalRegions: number;
|
|
200
|
+
probeLimit: number;
|
|
201
|
+
probesAttempted: number;
|
|
202
|
+
junctionVotes: JunctionVoteTrace[];
|
|
203
|
+
supersededOrdinaryVotes: number;
|
|
204
|
+
probes: CrossRegionProbeTrace[];
|
|
205
|
+
stopReason: "insufficient-regions" | "probe-limit" | "pairs-exhausted";
|
|
206
|
+
};
|
|
207
|
+
saturation?: {
|
|
208
|
+
regionIntervals: Array<{
|
|
209
|
+
start: number;
|
|
210
|
+
end: number;
|
|
211
|
+
}>;
|
|
212
|
+
hasLeading: boolean;
|
|
213
|
+
leadingEnd: number;
|
|
214
|
+
};
|
|
215
|
+
pooling?: {
|
|
216
|
+
inputVotes: number;
|
|
217
|
+
eligibleVotes: number;
|
|
218
|
+
saturationMaskedVotes: number;
|
|
219
|
+
};
|
|
220
|
+
anchors?: ConsensusAnchorTrace[];
|
|
221
|
+
result: AttentionRead;
|
|
222
|
+
}
|
|
223
|
+
/** The mutable collection buffers threaded through one traced consensus
|
|
224
|
+
* climb — allocated exactly once, in {@link computeAttention}, only when
|
|
225
|
+
* `ctx.trace` is set. Every field mirrors a `ClimbConsensusData` array/map,
|
|
226
|
+
* built incrementally as the pipeline runs so commit-time decisions (in
|
|
227
|
+
* particular) are recorded LIVE, not reconstructed afterward. */
|
|
228
|
+
interface TraceDraft {
|
|
229
|
+
perceivedCount: number;
|
|
230
|
+
regions: ConsensusRegionTrace[];
|
|
231
|
+
crossRegionJunctionVotes: JunctionVoteTrace[];
|
|
232
|
+
crossRegionSummary?: {
|
|
233
|
+
eligibleRegions: number;
|
|
234
|
+
maximalRegions: number;
|
|
235
|
+
probeLimit: number;
|
|
236
|
+
probesAttempted: number;
|
|
237
|
+
stopReason?: "insufficient-regions" | "probe-limit" | "pairs-exhausted";
|
|
238
|
+
};
|
|
239
|
+
crossRegionProbes: CrossRegionProbeTrace[];
|
|
240
|
+
supersededOrdinaryVotes: number;
|
|
241
|
+
saturation?: {
|
|
242
|
+
regionIntervals: Array<{
|
|
243
|
+
start: number;
|
|
244
|
+
end: number;
|
|
245
|
+
}>;
|
|
246
|
+
hasLeading: boolean;
|
|
247
|
+
leadingEnd: number;
|
|
248
|
+
};
|
|
249
|
+
pooling?: {
|
|
250
|
+
inputVotes: number;
|
|
251
|
+
eligibleVotes: number;
|
|
252
|
+
saturationMaskedVotes: number;
|
|
253
|
+
};
|
|
254
|
+
anchors: ConsensusAnchorTrace[];
|
|
255
|
+
}
|
|
256
|
+
/** The config/corpus context {@link traceAttention} needs to fill in
|
|
257
|
+
* `ClimbConsensusData.config` and `.result` at whichever exit fires —
|
|
258
|
+
* threaded down from {@link computeAttention} rather than re-derived, so
|
|
259
|
+
* every emission point reports the SAME numbers the real climb used. */
|
|
260
|
+
interface ClimbConsensusCfg {
|
|
261
|
+
k: number;
|
|
262
|
+
mode: DFMode;
|
|
263
|
+
perceivedCount: number;
|
|
264
|
+
totalRegions: number;
|
|
265
|
+
N?: number;
|
|
266
|
+
reachMemo?: ReadonlyMap<number, AncestorReach>;
|
|
267
|
+
naturalBreak?: number;
|
|
268
|
+
consensusFloor?: number;
|
|
269
|
+
}
|
|
270
|
+
/** Climb the query's perceived byte regions up the structural DAG via
|
|
271
|
+
* resonance, pool the evidence, and return only the ROOT points of
|
|
272
|
+
* attention — those that cleared commitVotes' significance floor. */
|
|
273
|
+
export declare function climbAttention(ctx: MindContext, query: Uint8Array, k: number, mode?: DFMode): Promise<Attention[]>;
|
|
274
|
+
/** Full read-out of one consensus climb: both the roots (dominant points of
|
|
275
|
+
* attention) and the entire ranked list. Cached via ctx.climbMemo, ALWAYS —
|
|
276
|
+
* see {@link recognise} for why this memo (and recognise()'s own) must
|
|
277
|
+
* never be skipped while tracing: computeAttention's collectRegions walks
|
|
278
|
+
* the query's perceived tree via the same foldTree whose subtree-resolution
|
|
279
|
+
* fast path makes a second call on identical bytes non-idempotent once
|
|
280
|
+
* ctx._resolvedSubtrees is warm (which a multi-turn conversation's shared
|
|
281
|
+
* prefix subtrees guarantee by the second turn). A cache hit still emits
|
|
282
|
+
* a trace step — abbreviated, since the full per-sub-region voting detail
|
|
283
|
+
* {@link traceAttention} builds isn't preserved by the cached read-out —
|
|
284
|
+
* so a traced response is never silently blacked out for a repeated
|
|
285
|
+
* query. */
|
|
286
|
+
export declare function climbAttentionAll(ctx: MindContext, query: Uint8Array, k: number, mode?: DFMode): Promise<AttentionRead>;
|
|
287
|
+
export declare function computeAttention(ctx: MindContext, query: Uint8Array, k: number, mode: DFMode): Promise<AttentionRead>;
|
|
288
|
+
export declare function collectRegions(ctx: MindContext, query: Uint8Array): Region[];
|
|
289
|
+
export declare function voteRegions(ctx: MindContext, query: Uint8Array, regions: readonly Region[], k: number, mode: DFMode, N: number, reachMemo?: Map<number, AncestorReach>, td?: TraceDraft): Promise<{
|
|
290
|
+
votes: RegionVote[];
|
|
291
|
+
saturated: boolean[];
|
|
292
|
+
voters: Array<{
|
|
293
|
+
id: number;
|
|
294
|
+
score: number;
|
|
295
|
+
w: number;
|
|
296
|
+
} | null>;
|
|
297
|
+
}>;
|
|
298
|
+
/** The consensus vote as EVIDENCE POOLING, not shortest path: each surviving
|
|
299
|
+
* region is an axiom; it contributes to every root it climbed to (or, for a
|
|
300
|
+
* terminal answer node, to the contexts that lead to it) by a `combine:
|
|
301
|
+
* "sum"` rule, so independent regions corroborating the same anchor ADD
|
|
302
|
+
* rather than compete to be the cheapest route (see {@link Rule.combine} in
|
|
303
|
+
* derive/src/deduction.ts). Run through the very engine {@link
|
|
304
|
+
* GraphSearch} covers with — `lightestDerivation` — so a pooled-evidence
|
|
305
|
+
* decision is, like a followed edge or a spliced connector, one weighted
|
|
306
|
+
* rule of the SAME deduction system, not a separate hand-rolled tally that
|
|
307
|
+
* merely logs alongside it. `votesIdf`/`support` are the same two
|
|
308
|
+
* read-outs {@link commitVotes} always gated on; only how they accumulate
|
|
309
|
+
* changed. */
|
|
310
|
+
export declare function poolVotes(ctx: MindContext, regionVotes: readonly RegionVote[], sat: SaturationInfo, N: number, td?: TraceDraft): {
|
|
311
|
+
votes: Map<number, number>;
|
|
312
|
+
votesIdf: Map<number, number>;
|
|
313
|
+
support: Map<number, {
|
|
314
|
+
start: number;
|
|
315
|
+
end: number;
|
|
316
|
+
w: number;
|
|
317
|
+
}>;
|
|
318
|
+
/** Per-anchor SCALE-INVARIANT support: Σ RegionVote.absorbed over the
|
|
319
|
+
* distinct contributing regions — see Attention.breadth. */
|
|
320
|
+
regionSupport: Map<number, number>;
|
|
321
|
+
/** Per-anchor contributing region spans — see Attention.clusters. */
|
|
322
|
+
regionSpans: Map<number, Array<[number, number]>>;
|
|
323
|
+
steps: DerivationStep[];
|
|
324
|
+
};
|
|
325
|
+
export declare function commitVotes(ctx: MindContext, pooled: {
|
|
326
|
+
votes: Map<number, number>;
|
|
327
|
+
votesIdf: Map<number, number>;
|
|
328
|
+
support: Map<number, {
|
|
329
|
+
start: number;
|
|
330
|
+
end: number;
|
|
331
|
+
w: number;
|
|
332
|
+
}>;
|
|
333
|
+
regionSupport: Map<number, number>;
|
|
334
|
+
regionSpans: Map<number, Array<[number, number]>>;
|
|
335
|
+
steps: DerivationStep[];
|
|
336
|
+
}, sat: SaturationInfo, regions: readonly Region[], regionVoter: ReadonlyArray<{
|
|
337
|
+
id: number;
|
|
338
|
+
score: number;
|
|
339
|
+
w: number;
|
|
340
|
+
} | null>, N: number, td?: TraceDraft, cfg?: ClimbConsensusCfg): AttentionRead;
|
|
341
|
+
export declare function detectSaturated(ctx: MindContext, regions: ReadonlyArray<{
|
|
342
|
+
start: number;
|
|
343
|
+
end: number;
|
|
344
|
+
chunk?: boolean;
|
|
345
|
+
}>, saturated: ReadonlyArray<boolean>): SaturationInfo;
|
|
346
|
+
export declare function canonicalChunkId(ctx: MindContext, regionBytes: Uint8Array, N: number, reachMemo?: Map<number, AncestorReach>): number | null;
|
|
347
|
+
export declare function naturalBreak(votes: number[]): number;
|
|
348
|
+
export type CrossRegionTier = "exact" | "single-synonym" | "double-synonym" | "structural-resonance";
|
|
349
|
+
export interface StructuralVariant {
|
|
350
|
+
left: StructuralPart;
|
|
351
|
+
right: StructuralPart;
|
|
352
|
+
kind: "exact-exact" | "left-synonym" | "right-synonym" | "double-synonym";
|
|
353
|
+
semanticConfidence: number;
|
|
354
|
+
leftSiblingId?: number;
|
|
355
|
+
rightSiblingId?: number;
|
|
356
|
+
}
|
|
357
|
+
export interface StructuralResonanceProposal {
|
|
358
|
+
id: number;
|
|
359
|
+
annScore: number;
|
|
360
|
+
semanticConfidence: number;
|
|
361
|
+
effectiveScore: number;
|
|
362
|
+
variant: StructuralVariant["kind"];
|
|
363
|
+
leftSiblingId?: number;
|
|
364
|
+
rightSiblingId?: number;
|
|
365
|
+
}
|
|
366
|
+
/** A sibling gist cached in the shared, climb-wide memo alongside the
|
|
367
|
+
* COMPLETE stored byte length it was reconstructed from — the length is
|
|
368
|
+
* required to tell whether a cache hit is still valid under a probe whose
|
|
369
|
+
* `maxSiblingBytes` bound is smaller than the one that first cached it. */
|
|
370
|
+
interface CachedSiblingGist {
|
|
371
|
+
gist: Vec;
|
|
372
|
+
length: number;
|
|
373
|
+
}
|
|
374
|
+
/** Build, bound and order every mandatory structural variant (§7-8): the
|
|
375
|
+
* exact/exact composition is always kept; up to `ctx.cfg.haloQueryK`
|
|
376
|
+
* synonym variants (single- and double-synonym combined, one shared
|
|
377
|
+
* budget) are appended, ordered by confidence, then kind, then sibling id.
|
|
378
|
+
* Variant selection is entirely lightweight (see {@link
|
|
379
|
+
* buildStructuralVariantSpecs}); a sibling's bytes are read and perceived
|
|
380
|
+
* only for specs actually retained, and at most once per sibling id per
|
|
381
|
+
* climb via `siblingGistMemo`. */
|
|
382
|
+
export declare function buildStructuralVariants(ctx: MindContext, ra: Region, rb: Region, sides: JunctionSynonymSides, siblingGistMemo: Map<number, CachedSiblingGist>): {
|
|
383
|
+
variants: StructuralVariant[];
|
|
384
|
+
exactLeft: StructuralPart;
|
|
385
|
+
exactRight: StructuralPart;
|
|
386
|
+
};
|
|
387
|
+
export declare function structuralResonance(ctx: MindContext, query: Uint8Array, ra: Region, rb: Region, sides: JunctionSynonymSides, siblingGistMemo: Map<number, CachedSiblingGist>, k: number, N: number, reachMemo: Map<number, AncestorReach>,
|
|
388
|
+
/** Each side's OWN individual climb roots (from voteRegions), when it cast
|
|
389
|
+
* one — the self-evidence backstop structural-resonance needs and the
|
|
390
|
+
* exact tier gets for free from literal byte containment (§11's whole
|
|
391
|
+
* premise: recover a JOINT context neither side votes for alone). A
|
|
392
|
+
* candidate whose reach is exactly one side's own conclusion is not new
|
|
393
|
+
* evidence of a joint whole; it is that side's resonance rediscovering
|
|
394
|
+
* itself through a synthetic gist still dominated by its own direction. */
|
|
395
|
+
ownRootsA: readonly number[] | undefined, ownRootsB: readonly number[] | undefined, trace?: StructuralResonanceTrace): Promise<{
|
|
396
|
+
proposal: StructuralResonanceProposal;
|
|
397
|
+
reach: AncestorReach;
|
|
398
|
+
idf: number;
|
|
399
|
+
} | null>;
|
|
400
|
+
/** Emit the "climbConsensus" step — the human-readable note this always
|
|
401
|
+
* produced, now paired (when `ctx.trace` and `cfg` are both present) with
|
|
402
|
+
* the structured {@link ClimbConsensusData} payload on the SAME step's
|
|
403
|
+
* `data` field. Every exit of {@link computeAttention} funnels through
|
|
404
|
+
* here, so instrumentation and the existing rationale text can never drift
|
|
405
|
+
* apart — see the instrumentation spec's §9 "every exit path". */
|
|
406
|
+
export declare function traceAttention(ctx: MindContext, regions: ReadonlyArray<{
|
|
407
|
+
start: number;
|
|
408
|
+
end: number;
|
|
409
|
+
}>, regionVoter: ReadonlyArray<{
|
|
410
|
+
id: number;
|
|
411
|
+
score: number;
|
|
412
|
+
w: number;
|
|
413
|
+
} | null>, roots: ReadonlyArray<Attention>, steps?: ReadonlyArray<DerivationStep>, td?: TraceDraft, cfg?: ClimbConsensusCfg, ranked?: ReadonlyArray<Attention>): void;
|
|
414
|
+
export {};
|