ruvector 0.1.25 → 0.1.27

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.
@@ -0,0 +1,124 @@
1
+ /**
2
+ * GNN Wrapper - Safe wrapper around @ruvector/gnn with automatic array conversion
3
+ *
4
+ * This wrapper handles the array type conversion automatically, allowing users
5
+ * to pass either regular arrays or Float32Arrays.
6
+ *
7
+ * @ruvector/gnn requires regular JavaScript arrays, NOT Float32Array.
8
+ * This wrapper handles the conversion automatically.
9
+ */
10
+ /**
11
+ * Search result from differentiable search
12
+ */
13
+ export interface DifferentiableSearchResult {
14
+ /** Indices of top-k candidates */
15
+ indices: number[];
16
+ /** Soft weights for top-k candidates */
17
+ weights: number[];
18
+ }
19
+ /**
20
+ * Differentiable search using soft attention mechanism
21
+ *
22
+ * This wrapper automatically converts Float32Array inputs to regular arrays.
23
+ *
24
+ * @param query - Query vector (array or Float32Array)
25
+ * @param candidates - List of candidate vectors (arrays or Float32Arrays)
26
+ * @param k - Number of top results to return
27
+ * @param temperature - Temperature for softmax (lower = sharper, higher = smoother)
28
+ * @returns Search result with indices and soft weights
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { differentiableSearch } from 'ruvector/core/gnn-wrapper';
33
+ *
34
+ * // Works with regular arrays
35
+ * const result1 = differentiableSearch([1, 0, 0], [[1, 0, 0], [0, 1, 0]], 2, 1.0);
36
+ *
37
+ * // Also works with Float32Array
38
+ * const query = new Float32Array([1, 0, 0]);
39
+ * const candidates = [new Float32Array([1, 0, 0]), new Float32Array([0, 1, 0])];
40
+ * const result2 = differentiableSearch(query, candidates, 2, 1.0);
41
+ * ```
42
+ */
43
+ export declare function differentiableSearch(query: number[] | Float32Array | Float64Array, candidates: (number[] | Float32Array | Float64Array)[], k: number, temperature?: number): DifferentiableSearchResult;
44
+ /**
45
+ * GNN Layer for HNSW topology
46
+ */
47
+ export declare class RuvectorLayer {
48
+ private inner;
49
+ /**
50
+ * Create a new Ruvector GNN layer
51
+ *
52
+ * @param inputDim - Dimension of input node embeddings
53
+ * @param hiddenDim - Dimension of hidden representations
54
+ * @param heads - Number of attention heads
55
+ * @param dropout - Dropout rate (0.0 to 1.0)
56
+ */
57
+ constructor(inputDim: number, hiddenDim: number, heads: number, dropout?: number);
58
+ /**
59
+ * Forward pass through the GNN layer
60
+ *
61
+ * @param nodeEmbedding - Current node's embedding
62
+ * @param neighborEmbeddings - Embeddings of neighbor nodes
63
+ * @param edgeWeights - Weights of edges to neighbors
64
+ * @returns Updated node embedding
65
+ */
66
+ forward(nodeEmbedding: number[] | Float32Array, neighborEmbeddings: (number[] | Float32Array)[], edgeWeights: number[] | Float32Array): number[];
67
+ /**
68
+ * Serialize the layer to JSON
69
+ */
70
+ toJson(): string;
71
+ /**
72
+ * Deserialize the layer from JSON
73
+ */
74
+ static fromJson(json: string): RuvectorLayer;
75
+ }
76
+ /**
77
+ * Tensor compressor with adaptive level selection
78
+ */
79
+ export declare class TensorCompress {
80
+ private inner;
81
+ constructor();
82
+ /**
83
+ * Compress an embedding based on access frequency
84
+ *
85
+ * @param embedding - Input embedding vector
86
+ * @param accessFreq - Access frequency (0.0 to 1.0)
87
+ * @returns Compressed tensor as JSON string
88
+ */
89
+ compress(embedding: number[] | Float32Array, accessFreq: number): string;
90
+ /**
91
+ * Decompress a compressed tensor
92
+ *
93
+ * @param compressedJson - Compressed tensor JSON
94
+ * @returns Decompressed embedding
95
+ */
96
+ decompress(compressedJson: string): number[];
97
+ }
98
+ /**
99
+ * Hierarchical forward pass through GNN layers
100
+ *
101
+ * @param query - Query vector
102
+ * @param layerEmbeddings - Embeddings organized by layer
103
+ * @param gnnLayersJson - JSON array of serialized GNN layers
104
+ * @returns Final embedding after hierarchical processing
105
+ */
106
+ export declare function hierarchicalForward(query: number[] | Float32Array, layerEmbeddings: (number[] | Float32Array)[][], gnnLayersJson: string[]): number[];
107
+ /**
108
+ * Get compression level for a given access frequency
109
+ */
110
+ export declare function getCompressionLevel(accessFreq: number): string;
111
+ /**
112
+ * Check if GNN module is available
113
+ */
114
+ export declare function isGnnAvailable(): boolean;
115
+ declare const _default: {
116
+ differentiableSearch: typeof differentiableSearch;
117
+ RuvectorLayer: typeof RuvectorLayer;
118
+ TensorCompress: typeof TensorCompress;
119
+ hierarchicalForward: typeof hierarchicalForward;
120
+ getCompressionLevel: typeof getCompressionLevel;
121
+ isGnnAvailable: typeof isGnnAvailable;
122
+ };
123
+ export default _default;
124
+ //# sourceMappingURL=gnn-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gnn-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/gnn-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAuCH;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kCAAkC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,wCAAwC;IACxC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EAAE,GAAG,YAAY,GAAG,YAAY,EAC7C,UAAU,EAAE,CAAC,MAAM,EAAE,GAAG,YAAY,GAAG,YAAY,CAAC,EAAE,EACtD,CAAC,EAAE,MAAM,EACT,WAAW,GAAE,MAAY,GACxB,0BAA0B,CAQ5B;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAM;IAEnB;;;;;;;OAOG;gBACS,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,MAAY;IAKrF;;;;;;;OAOG;IACH,OAAO,CACL,aAAa,EAAE,MAAM,EAAE,GAAG,YAAY,EACtC,kBAAkB,EAAE,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,EAC/C,WAAW,EAAE,MAAM,EAAE,GAAG,YAAY,GACnC,MAAM,EAAE;IAQX;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAM7C;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAM;;IAOnB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAIxE;;;;;OAKG;IACH,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE;CAG7C;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EAAE,GAAG,YAAY,EAC9B,eAAe,EAAE,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,EAAE,EAC9C,aAAa,EAAE,MAAM,EAAE,GACtB,MAAM,EAAE,CAOV;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAOxC;;;;;;;;;AAED,wBAOE"}
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ /**
3
+ * GNN Wrapper - Safe wrapper around @ruvector/gnn with automatic array conversion
4
+ *
5
+ * This wrapper handles the array type conversion automatically, allowing users
6
+ * to pass either regular arrays or Float32Arrays.
7
+ *
8
+ * @ruvector/gnn requires regular JavaScript arrays, NOT Float32Array.
9
+ * This wrapper handles the conversion automatically.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TensorCompress = exports.RuvectorLayer = void 0;
13
+ exports.differentiableSearch = differentiableSearch;
14
+ exports.hierarchicalForward = hierarchicalForward;
15
+ exports.getCompressionLevel = getCompressionLevel;
16
+ exports.isGnnAvailable = isGnnAvailable;
17
+ // Lazy load to avoid import errors if not installed
18
+ let gnnModule = null;
19
+ let loadError = null;
20
+ function getGnnModule() {
21
+ if (gnnModule)
22
+ return gnnModule;
23
+ if (loadError)
24
+ throw loadError;
25
+ try {
26
+ gnnModule = require('@ruvector/gnn');
27
+ return gnnModule;
28
+ }
29
+ catch (e) {
30
+ loadError = new Error(`@ruvector/gnn is not installed or failed to load: ${e.message}\n` +
31
+ `Install with: npm install @ruvector/gnn`);
32
+ throw loadError;
33
+ }
34
+ }
35
+ /**
36
+ * Convert any array-like input to a regular JavaScript array
37
+ */
38
+ function toArray(input) {
39
+ if (Array.isArray(input)) {
40
+ return input;
41
+ }
42
+ return Array.from(input);
43
+ }
44
+ /**
45
+ * Convert nested arrays/typed arrays to regular JavaScript arrays
46
+ */
47
+ function toNestedArray(input) {
48
+ return input.map(arr => toArray(arr));
49
+ }
50
+ /**
51
+ * Differentiable search using soft attention mechanism
52
+ *
53
+ * This wrapper automatically converts Float32Array inputs to regular arrays.
54
+ *
55
+ * @param query - Query vector (array or Float32Array)
56
+ * @param candidates - List of candidate vectors (arrays or Float32Arrays)
57
+ * @param k - Number of top results to return
58
+ * @param temperature - Temperature for softmax (lower = sharper, higher = smoother)
59
+ * @returns Search result with indices and soft weights
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import { differentiableSearch } from 'ruvector/core/gnn-wrapper';
64
+ *
65
+ * // Works with regular arrays
66
+ * const result1 = differentiableSearch([1, 0, 0], [[1, 0, 0], [0, 1, 0]], 2, 1.0);
67
+ *
68
+ * // Also works with Float32Array
69
+ * const query = new Float32Array([1, 0, 0]);
70
+ * const candidates = [new Float32Array([1, 0, 0]), new Float32Array([0, 1, 0])];
71
+ * const result2 = differentiableSearch(query, candidates, 2, 1.0);
72
+ * ```
73
+ */
74
+ function differentiableSearch(query, candidates, k, temperature = 1.0) {
75
+ const gnn = getGnnModule();
76
+ // Convert to regular arrays (required by @ruvector/gnn)
77
+ const queryArray = toArray(query);
78
+ const candidatesArray = toNestedArray(candidates);
79
+ return gnn.differentiableSearch(queryArray, candidatesArray, k, temperature);
80
+ }
81
+ /**
82
+ * GNN Layer for HNSW topology
83
+ */
84
+ class RuvectorLayer {
85
+ /**
86
+ * Create a new Ruvector GNN layer
87
+ *
88
+ * @param inputDim - Dimension of input node embeddings
89
+ * @param hiddenDim - Dimension of hidden representations
90
+ * @param heads - Number of attention heads
91
+ * @param dropout - Dropout rate (0.0 to 1.0)
92
+ */
93
+ constructor(inputDim, hiddenDim, heads, dropout = 0.1) {
94
+ const gnn = getGnnModule();
95
+ this.inner = new gnn.RuvectorLayer(inputDim, hiddenDim, heads, dropout);
96
+ }
97
+ /**
98
+ * Forward pass through the GNN layer
99
+ *
100
+ * @param nodeEmbedding - Current node's embedding
101
+ * @param neighborEmbeddings - Embeddings of neighbor nodes
102
+ * @param edgeWeights - Weights of edges to neighbors
103
+ * @returns Updated node embedding
104
+ */
105
+ forward(nodeEmbedding, neighborEmbeddings, edgeWeights) {
106
+ return this.inner.forward(toArray(nodeEmbedding), toNestedArray(neighborEmbeddings), toArray(edgeWeights));
107
+ }
108
+ /**
109
+ * Serialize the layer to JSON
110
+ */
111
+ toJson() {
112
+ return this.inner.toJson();
113
+ }
114
+ /**
115
+ * Deserialize the layer from JSON
116
+ */
117
+ static fromJson(json) {
118
+ const gnn = getGnnModule();
119
+ const layer = new RuvectorLayer(1, 1, 1, 0); // Dummy constructor
120
+ layer.inner = gnn.RuvectorLayer.fromJson(json);
121
+ return layer;
122
+ }
123
+ }
124
+ exports.RuvectorLayer = RuvectorLayer;
125
+ /**
126
+ * Tensor compressor with adaptive level selection
127
+ */
128
+ class TensorCompress {
129
+ constructor() {
130
+ const gnn = getGnnModule();
131
+ this.inner = new gnn.TensorCompress();
132
+ }
133
+ /**
134
+ * Compress an embedding based on access frequency
135
+ *
136
+ * @param embedding - Input embedding vector
137
+ * @param accessFreq - Access frequency (0.0 to 1.0)
138
+ * @returns Compressed tensor as JSON string
139
+ */
140
+ compress(embedding, accessFreq) {
141
+ return this.inner.compress(toArray(embedding), accessFreq);
142
+ }
143
+ /**
144
+ * Decompress a compressed tensor
145
+ *
146
+ * @param compressedJson - Compressed tensor JSON
147
+ * @returns Decompressed embedding
148
+ */
149
+ decompress(compressedJson) {
150
+ return this.inner.decompress(compressedJson);
151
+ }
152
+ }
153
+ exports.TensorCompress = TensorCompress;
154
+ /**
155
+ * Hierarchical forward pass through GNN layers
156
+ *
157
+ * @param query - Query vector
158
+ * @param layerEmbeddings - Embeddings organized by layer
159
+ * @param gnnLayersJson - JSON array of serialized GNN layers
160
+ * @returns Final embedding after hierarchical processing
161
+ */
162
+ function hierarchicalForward(query, layerEmbeddings, gnnLayersJson) {
163
+ const gnn = getGnnModule();
164
+ return gnn.hierarchicalForward(toArray(query), layerEmbeddings.map(layer => toNestedArray(layer)), gnnLayersJson);
165
+ }
166
+ /**
167
+ * Get compression level for a given access frequency
168
+ */
169
+ function getCompressionLevel(accessFreq) {
170
+ const gnn = getGnnModule();
171
+ return gnn.getCompressionLevel(accessFreq);
172
+ }
173
+ /**
174
+ * Check if GNN module is available
175
+ */
176
+ function isGnnAvailable() {
177
+ try {
178
+ getGnnModule();
179
+ return true;
180
+ }
181
+ catch {
182
+ return false;
183
+ }
184
+ }
185
+ exports.default = {
186
+ differentiableSearch,
187
+ RuvectorLayer,
188
+ TensorCompress,
189
+ hierarchicalForward,
190
+ getCompressionLevel,
191
+ isGnnAvailable,
192
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Core module exports
3
+ *
4
+ * These wrappers provide safe, type-flexible interfaces to the underlying
5
+ * native packages, handling array type conversions automatically.
6
+ */
7
+ export * from './gnn-wrapper';
8
+ export * from './attention-fallbacks';
9
+ export * from './agentdb-fast';
10
+ export * from './sona-wrapper';
11
+ export { default as gnnWrapper } from './gnn-wrapper';
12
+ export { default as attentionFallbacks } from './attention-fallbacks';
13
+ export { default as agentdbFast } from './agentdb-fast';
14
+ export { default as Sona } from './sona-wrapper';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAG/B,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Core module exports
4
+ *
5
+ * These wrappers provide safe, type-flexible interfaces to the underlying
6
+ * native packages, handling array type conversions automatically.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Sona = exports.agentdbFast = exports.attentionFallbacks = exports.gnnWrapper = void 0;
27
+ __exportStar(require("./gnn-wrapper"), exports);
28
+ __exportStar(require("./attention-fallbacks"), exports);
29
+ __exportStar(require("./agentdb-fast"), exports);
30
+ __exportStar(require("./sona-wrapper"), exports);
31
+ // Re-export default objects for convenience
32
+ var gnn_wrapper_1 = require("./gnn-wrapper");
33
+ Object.defineProperty(exports, "gnnWrapper", { enumerable: true, get: function () { return __importDefault(gnn_wrapper_1).default; } });
34
+ var attention_fallbacks_1 = require("./attention-fallbacks");
35
+ Object.defineProperty(exports, "attentionFallbacks", { enumerable: true, get: function () { return __importDefault(attention_fallbacks_1).default; } });
36
+ var agentdb_fast_1 = require("./agentdb-fast");
37
+ Object.defineProperty(exports, "agentdbFast", { enumerable: true, get: function () { return __importDefault(agentdb_fast_1).default; } });
38
+ var sona_wrapper_1 = require("./sona-wrapper");
39
+ Object.defineProperty(exports, "Sona", { enumerable: true, get: function () { return __importDefault(sona_wrapper_1).default; } });
@@ -0,0 +1,215 @@
1
+ /**
2
+ * SONA Wrapper - Self-Optimizing Neural Architecture
3
+ *
4
+ * Provides a safe, flexible interface to @ruvector/sona with:
5
+ * - Automatic array type conversion (Array <-> Float64Array)
6
+ * - Graceful handling when sona is not installed
7
+ * - TypeScript types for all APIs
8
+ *
9
+ * SONA Features:
10
+ * - Micro-LoRA: Ultra-fast rank-1/2 adaptations (~0.1ms)
11
+ * - Base-LoRA: Deeper adaptations for complex patterns
12
+ * - EWC++: Elastic Weight Consolidation to prevent catastrophic forgetting
13
+ * - ReasoningBank: Pattern storage and retrieval
14
+ * - Trajectory tracking: Record and learn from execution paths
15
+ */
16
+ /** Array input type - accepts both regular arrays and typed arrays */
17
+ export type ArrayInput = number[] | Float32Array | Float64Array;
18
+ /** SONA configuration options */
19
+ export interface SonaConfig {
20
+ /** Hidden dimension size (required) */
21
+ hiddenDim: number;
22
+ /** Embedding dimension (defaults to hiddenDim) */
23
+ embeddingDim?: number;
24
+ /** Micro-LoRA rank (1-2, default: 1) */
25
+ microLoraRank?: number;
26
+ /** Base LoRA rank (default: 8) */
27
+ baseLoraRank?: number;
28
+ /** Micro-LoRA learning rate (default: 0.001) */
29
+ microLoraLr?: number;
30
+ /** Base LoRA learning rate (default: 0.0001) */
31
+ baseLoraLr?: number;
32
+ /** EWC lambda regularization (default: 1000.0) */
33
+ ewcLambda?: number;
34
+ /** Number of pattern clusters (default: 50) */
35
+ patternClusters?: number;
36
+ /** Trajectory buffer capacity (default: 10000) */
37
+ trajectoryCapacity?: number;
38
+ /** Background learning interval in ms (default: 3600000 = 1 hour) */
39
+ backgroundIntervalMs?: number;
40
+ /** Quality threshold for learning (default: 0.5) */
41
+ qualityThreshold?: number;
42
+ /** Enable SIMD optimizations (default: true) */
43
+ enableSimd?: boolean;
44
+ }
45
+ /** Learned pattern from ReasoningBank */
46
+ export interface LearnedPattern {
47
+ /** Pattern identifier */
48
+ id: string;
49
+ /** Cluster centroid embedding */
50
+ centroid: number[];
51
+ /** Number of trajectories in cluster */
52
+ clusterSize: number;
53
+ /** Total weight of trajectories */
54
+ totalWeight: number;
55
+ /** Average quality of member trajectories */
56
+ avgQuality: number;
57
+ /** Creation timestamp */
58
+ createdAt: string;
59
+ /** Last access timestamp */
60
+ lastAccessed: string;
61
+ /** Total access count */
62
+ accessCount: number;
63
+ /** Pattern type */
64
+ patternType: string;
65
+ }
66
+ /** SONA engine statistics */
67
+ export interface SonaStats {
68
+ trajectoriesRecorded: number;
69
+ patternsLearned: number;
70
+ microLoraUpdates: number;
71
+ baseLoraUpdates: number;
72
+ ewcConsolidations: number;
73
+ avgLearningTimeMs: number;
74
+ }
75
+ /** Check if sona is available */
76
+ export declare function isSonaAvailable(): boolean;
77
+ /**
78
+ * SONA Engine - Self-Optimizing Neural Architecture
79
+ *
80
+ * Provides runtime-adaptive learning with:
81
+ * - Micro-LoRA for instant adaptations
82
+ * - Base-LoRA for deeper learning
83
+ * - EWC++ for preventing forgetting
84
+ * - ReasoningBank for pattern storage
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * import { Sona } from 'ruvector';
89
+ *
90
+ * // Create engine with hidden dimension
91
+ * const engine = new Sona.Engine(256);
92
+ *
93
+ * // Or with custom config
94
+ * const engine = Sona.Engine.withConfig({
95
+ * hiddenDim: 256,
96
+ * microLoraRank: 2,
97
+ * patternClusters: 100
98
+ * });
99
+ *
100
+ * // Record a trajectory
101
+ * const trajId = engine.beginTrajectory([0.1, 0.2, ...]);
102
+ * engine.addStep(trajId, activations, attentionWeights, 0.8);
103
+ * engine.endTrajectory(trajId, 0.9);
104
+ *
105
+ * // Apply learned adaptations
106
+ * const adapted = engine.applyMicroLora(input);
107
+ * ```
108
+ */
109
+ export declare class SonaEngine {
110
+ private _native;
111
+ /**
112
+ * Create a new SONA engine
113
+ * @param hiddenDim Hidden dimension size (e.g., 256, 512, 768)
114
+ */
115
+ constructor(hiddenDim: number);
116
+ /**
117
+ * Create engine with custom configuration
118
+ * @param config SONA configuration options
119
+ */
120
+ static withConfig(config: SonaConfig): SonaEngine;
121
+ /**
122
+ * Begin recording a new trajectory
123
+ * @param queryEmbedding Initial query embedding
124
+ * @returns Trajectory ID for subsequent operations
125
+ */
126
+ beginTrajectory(queryEmbedding: ArrayInput): number;
127
+ /**
128
+ * Add a step to an active trajectory
129
+ * @param trajectoryId Trajectory ID from beginTrajectory
130
+ * @param activations Layer activations
131
+ * @param attentionWeights Attention weights
132
+ * @param reward Reward signal for this step (0.0 - 1.0)
133
+ */
134
+ addStep(trajectoryId: number, activations: ArrayInput, attentionWeights: ArrayInput, reward: number): void;
135
+ /**
136
+ * Alias for addStep for API compatibility
137
+ */
138
+ addTrajectoryStep(trajectoryId: number, activations: ArrayInput, attentionWeights: ArrayInput, reward: number): void;
139
+ /**
140
+ * Set the model route for a trajectory
141
+ * @param trajectoryId Trajectory ID
142
+ * @param route Model route identifier (e.g., "gpt-4", "claude-3")
143
+ */
144
+ setRoute(trajectoryId: number, route: string): void;
145
+ /**
146
+ * Add context to a trajectory
147
+ * @param trajectoryId Trajectory ID
148
+ * @param contextId Context identifier
149
+ */
150
+ addContext(trajectoryId: number, contextId: string): void;
151
+ /**
152
+ * Complete a trajectory and submit for learning
153
+ * @param trajectoryId Trajectory ID
154
+ * @param quality Final quality score (0.0 - 1.0)
155
+ */
156
+ endTrajectory(trajectoryId: number, quality: number): void;
157
+ /**
158
+ * Apply micro-LoRA transformation (ultra-fast, ~0.1ms)
159
+ * @param input Input vector
160
+ * @returns Transformed output vector
161
+ */
162
+ applyMicroLora(input: ArrayInput): number[];
163
+ /**
164
+ * Apply base-LoRA transformation to a specific layer
165
+ * @param layerIdx Layer index
166
+ * @param input Input vector
167
+ * @returns Transformed output vector
168
+ */
169
+ applyBaseLora(layerIdx: number, input: ArrayInput): number[];
170
+ /**
171
+ * Run background learning cycle if due
172
+ * Call this periodically (e.g., every few seconds)
173
+ * @returns Status message if learning occurred, null otherwise
174
+ */
175
+ tick(): string | null;
176
+ /**
177
+ * Force immediate background learning cycle
178
+ * @returns Status message with learning results
179
+ */
180
+ forceLearn(): string;
181
+ /**
182
+ * Flush pending instant loop updates
183
+ */
184
+ flush(): void;
185
+ /**
186
+ * Find similar learned patterns to a query
187
+ * @param queryEmbedding Query embedding
188
+ * @param k Number of patterns to return
189
+ * @returns Array of similar patterns
190
+ */
191
+ findPatterns(queryEmbedding: ArrayInput, k: number): LearnedPattern[];
192
+ /**
193
+ * Get engine statistics
194
+ * @returns Statistics object
195
+ */
196
+ getStats(): SonaStats;
197
+ /**
198
+ * Enable or disable the engine
199
+ * @param enabled Whether to enable
200
+ */
201
+ setEnabled(enabled: boolean): void;
202
+ /**
203
+ * Check if engine is enabled
204
+ */
205
+ isEnabled(): boolean;
206
+ }
207
+ /**
208
+ * SONA namespace with all exports
209
+ */
210
+ export declare const Sona: {
211
+ Engine: typeof SonaEngine;
212
+ isAvailable: typeof isSonaAvailable;
213
+ };
214
+ export default Sona;
215
+ //# sourceMappingURL=sona-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sona-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/sona-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,sEAAsE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