ruvector 0.2.22 → 0.2.23

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.
Files changed (108) hide show
  1. package/README.md +2 -2
  2. package/package.json +9 -5
  3. package/dist/analysis/complexity.d.ts +0 -52
  4. package/dist/analysis/complexity.d.ts.map +0 -1
  5. package/dist/analysis/complexity.js +0 -146
  6. package/dist/analysis/index.d.ts +0 -15
  7. package/dist/analysis/index.d.ts.map +0 -1
  8. package/dist/analysis/index.js +0 -38
  9. package/dist/analysis/patterns.d.ts +0 -71
  10. package/dist/analysis/patterns.d.ts.map +0 -1
  11. package/dist/analysis/patterns.js +0 -243
  12. package/dist/analysis/security.d.ts +0 -51
  13. package/dist/analysis/security.d.ts.map +0 -1
  14. package/dist/analysis/security.js +0 -139
  15. package/dist/core/adaptive-embedder.d.ts +0 -156
  16. package/dist/core/adaptive-embedder.d.ts.map +0 -1
  17. package/dist/core/adaptive-embedder.js +0 -838
  18. package/dist/core/agentdb-fast.d.ts +0 -149
  19. package/dist/core/agentdb-fast.d.ts.map +0 -1
  20. package/dist/core/agentdb-fast.js +0 -301
  21. package/dist/core/ast-parser.d.ts +0 -108
  22. package/dist/core/ast-parser.d.ts.map +0 -1
  23. package/dist/core/ast-parser.js +0 -602
  24. package/dist/core/attention-fallbacks.d.ts +0 -321
  25. package/dist/core/attention-fallbacks.d.ts.map +0 -1
  26. package/dist/core/attention-fallbacks.js +0 -552
  27. package/dist/core/cluster-wrapper.d.ts +0 -148
  28. package/dist/core/cluster-wrapper.d.ts.map +0 -1
  29. package/dist/core/cluster-wrapper.js +0 -271
  30. package/dist/core/coverage-router.d.ts +0 -88
  31. package/dist/core/coverage-router.d.ts.map +0 -1
  32. package/dist/core/coverage-router.js +0 -315
  33. package/dist/core/diff-embeddings.d.ts +0 -93
  34. package/dist/core/diff-embeddings.d.ts.map +0 -1
  35. package/dist/core/diff-embeddings.js +0 -334
  36. package/dist/core/gnn-wrapper.d.ts +0 -143
  37. package/dist/core/gnn-wrapper.d.ts.map +0 -1
  38. package/dist/core/gnn-wrapper.js +0 -213
  39. package/dist/core/graph-algorithms.d.ts +0 -83
  40. package/dist/core/graph-algorithms.d.ts.map +0 -1
  41. package/dist/core/graph-algorithms.js +0 -514
  42. package/dist/core/graph-wrapper.d.ts +0 -147
  43. package/dist/core/graph-wrapper.d.ts.map +0 -1
  44. package/dist/core/graph-wrapper.js +0 -299
  45. package/dist/core/index.d.ts +0 -48
  46. package/dist/core/index.d.ts.map +0 -1
  47. package/dist/core/index.js +0 -89
  48. package/dist/core/intelligence-engine.d.ts +0 -258
  49. package/dist/core/intelligence-engine.d.ts.map +0 -1
  50. package/dist/core/intelligence-engine.js +0 -1030
  51. package/dist/core/learning-engine.d.ts +0 -160
  52. package/dist/core/learning-engine.d.ts.map +0 -1
  53. package/dist/core/learning-engine.js +0 -589
  54. package/dist/core/neural-embeddings.d.ts +0 -393
  55. package/dist/core/neural-embeddings.d.ts.map +0 -1
  56. package/dist/core/neural-embeddings.js +0 -1091
  57. package/dist/core/neural-perf.d.ts +0 -331
  58. package/dist/core/neural-perf.d.ts.map +0 -1
  59. package/dist/core/neural-perf.js +0 -704
  60. package/dist/core/onnx/pkg/package.json +0 -3
  61. package/dist/core/onnx-embedder.d.ts +0 -105
  62. package/dist/core/onnx-embedder.d.ts.map +0 -1
  63. package/dist/core/onnx-embedder.js +0 -410
  64. package/dist/core/onnx-optimized.d.ts +0 -109
  65. package/dist/core/onnx-optimized.d.ts.map +0 -1
  66. package/dist/core/onnx-optimized.js +0 -419
  67. package/dist/core/parallel-intelligence.d.ts +0 -109
  68. package/dist/core/parallel-intelligence.d.ts.map +0 -1
  69. package/dist/core/parallel-intelligence.js +0 -340
  70. package/dist/core/parallel-workers.d.ts +0 -177
  71. package/dist/core/parallel-workers.d.ts.map +0 -1
  72. package/dist/core/parallel-workers.js +0 -671
  73. package/dist/core/router-wrapper.d.ts +0 -75
  74. package/dist/core/router-wrapper.d.ts.map +0 -1
  75. package/dist/core/router-wrapper.js +0 -243
  76. package/dist/core/rvf-wrapper.d.ts +0 -86
  77. package/dist/core/rvf-wrapper.d.ts.map +0 -1
  78. package/dist/core/rvf-wrapper.js +0 -102
  79. package/dist/core/sona-wrapper.d.ts +0 -226
  80. package/dist/core/sona-wrapper.d.ts.map +0 -1
  81. package/dist/core/sona-wrapper.js +0 -282
  82. package/dist/core/tensor-compress.d.ts +0 -134
  83. package/dist/core/tensor-compress.d.ts.map +0 -1
  84. package/dist/core/tensor-compress.js +0 -432
  85. package/dist/index.d.ts +0 -105
  86. package/dist/index.d.ts.map +0 -1
  87. package/dist/index.js +0 -221
  88. package/dist/services/embedding-service.d.ts +0 -136
  89. package/dist/services/embedding-service.d.ts.map +0 -1
  90. package/dist/services/embedding-service.js +0 -294
  91. package/dist/services/index.d.ts +0 -6
  92. package/dist/services/index.d.ts.map +0 -1
  93. package/dist/services/index.js +0 -26
  94. package/dist/types.d.ts +0 -145
  95. package/dist/types.d.ts.map +0 -1
  96. package/dist/types.js +0 -2
  97. package/dist/workers/benchmark.d.ts +0 -44
  98. package/dist/workers/benchmark.d.ts.map +0 -1
  99. package/dist/workers/benchmark.js +0 -230
  100. package/dist/workers/index.d.ts +0 -10
  101. package/dist/workers/index.d.ts.map +0 -1
  102. package/dist/workers/index.js +0 -25
  103. package/dist/workers/native-worker.d.ts +0 -76
  104. package/dist/workers/native-worker.d.ts.map +0 -1
  105. package/dist/workers/native-worker.js +0 -490
  106. package/dist/workers/types.d.ts +0 -69
  107. package/dist/workers/types.d.ts.map +0 -1
  108. package/dist/workers/types.js +0 -7
@@ -1,226 +0,0 @@
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
- * Save engine state to JSON string for persistence across restarts (fixes #274)
199
- * @returns State JSON that can be stored to disk/database
200
- */
201
- saveState(): string;
202
- /**
203
- * Restore engine state from JSON saved by saveState() (fixes #274)
204
- * @param stateJson - JSON string from a previous saveState() call
205
- * @returns Number of patterns restored
206
- */
207
- loadState(stateJson: string): number;
208
- /**
209
- * Enable or disable the engine
210
- * @param enabled Whether to enable
211
- */
212
- setEnabled(enabled: boolean): void;
213
- /**
214
- * Check if engine is enabled
215
- */
216
- isEnabled(): boolean;
217
- }
218
- /**
219
- * SONA namespace with all exports
220
- */
221
- export declare const Sona: {
222
- Engine: typeof SonaEngine;
223
- isAvailable: typeof isSonaAvailable;
224
- };
225
- export default Sona;
226
- //# sourceMappingURL=sona-wrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sona-wrapper.d.ts","sourceRoot":"","sources":["../../src/core/sona-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,sEAAsE;AACtE,MAAM,MAAM,UAAU,GAAG,MAAM,EAAE,GAAG,YAAY,GAAG,YAAY,CAAC;AAEhE,iCAAiC;AACjC,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qEAAqE;IACrE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gDAAgD;IAChD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,yCAAyC;AACzC,MAAM,WAAW,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B,MAAM,EAAE,MAAM,GACb,IAAI;IAIP;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAInD;;;;OAIG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAIzD;;;;OAIG;IACH,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAQ1D;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAI3C;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAQ5D;;;;OAIG;IACH,IAAI,IAAI,MAAM,GAAG,IAAI;IAIrB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,KAAK,IAAI,IAAI;IAQb;;;;;OAKG;IACH,YAAY,CAAC,cAAc,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,GAAG,cAAc,EAAE;IAQrE;;;OAGG;IACH,QAAQ,IAAI,SAAS;IAcrB;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;;OAIG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAIpC;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC;;OAEG;IACH,SAAS,IAAI,OAAO;CAGrB;AAMD;;GAEG;AACH,eAAO,MAAM,IAAI;;;CAGhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1,282 +0,0 @@
1
- "use strict";
2
- /**
3
- * SONA Wrapper - Self-Optimizing Neural Architecture
4
- *
5
- * Provides a safe, flexible interface to @ruvector/sona with:
6
- * - Automatic array type conversion (Array <-> Float64Array)
7
- * - Graceful handling when sona is not installed
8
- * - TypeScript types for all APIs
9
- *
10
- * SONA Features:
11
- * - Micro-LoRA: Ultra-fast rank-1/2 adaptations (~0.1ms)
12
- * - Base-LoRA: Deeper adaptations for complex patterns
13
- * - EWC++: Elastic Weight Consolidation to prevent catastrophic forgetting
14
- * - ReasoningBank: Pattern storage and retrieval
15
- * - Trajectory tracking: Record and learn from execution paths
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.Sona = exports.SonaEngine = void 0;
19
- exports.isSonaAvailable = isSonaAvailable;
20
- // ============================================================================
21
- // Helper Functions
22
- // ============================================================================
23
- /** Convert any array-like to regular Array (SONA expects number[]) */
24
- function toArray(input) {
25
- if (Array.isArray(input))
26
- return input;
27
- return Array.from(input);
28
- }
29
- // ============================================================================
30
- // Lazy Loading
31
- // ============================================================================
32
- let sonaModule = null;
33
- let sonaLoadError = null;
34
- function getSonaModule() {
35
- if (sonaModule)
36
- return sonaModule;
37
- if (sonaLoadError)
38
- throw sonaLoadError;
39
- try {
40
- sonaModule = require('@ruvector/sona');
41
- return sonaModule;
42
- }
43
- catch (e) {
44
- sonaLoadError = new Error(`@ruvector/sona is not installed. Install it with:\n` +
45
- ` npm install @ruvector/sona\n\n` +
46
- `Original error: ${e.message}`);
47
- throw sonaLoadError;
48
- }
49
- }
50
- /** Check if sona is available */
51
- function isSonaAvailable() {
52
- try {
53
- getSonaModule();
54
- return true;
55
- }
56
- catch {
57
- return false;
58
- }
59
- }
60
- // ============================================================================
61
- // SONA Engine Wrapper
62
- // ============================================================================
63
- /**
64
- * SONA Engine - Self-Optimizing Neural Architecture
65
- *
66
- * Provides runtime-adaptive learning with:
67
- * - Micro-LoRA for instant adaptations
68
- * - Base-LoRA for deeper learning
69
- * - EWC++ for preventing forgetting
70
- * - ReasoningBank for pattern storage
71
- *
72
- * @example
73
- * ```typescript
74
- * import { Sona } from 'ruvector';
75
- *
76
- * // Create engine with hidden dimension
77
- * const engine = new Sona.Engine(256);
78
- *
79
- * // Or with custom config
80
- * const engine = Sona.Engine.withConfig({
81
- * hiddenDim: 256,
82
- * microLoraRank: 2,
83
- * patternClusters: 100
84
- * });
85
- *
86
- * // Record a trajectory
87
- * const trajId = engine.beginTrajectory([0.1, 0.2, ...]);
88
- * engine.addStep(trajId, activations, attentionWeights, 0.8);
89
- * engine.endTrajectory(trajId, 0.9);
90
- *
91
- * // Apply learned adaptations
92
- * const adapted = engine.applyMicroLora(input);
93
- * ```
94
- */
95
- class SonaEngine {
96
- /**
97
- * Create a new SONA engine
98
- * @param hiddenDim Hidden dimension size (e.g., 256, 512, 768)
99
- */
100
- constructor(hiddenDim) {
101
- const mod = getSonaModule();
102
- this._native = new mod.SonaEngine(hiddenDim);
103
- }
104
- /**
105
- * Create engine with custom configuration
106
- * @param config SONA configuration options
107
- */
108
- static withConfig(config) {
109
- const mod = getSonaModule();
110
- const engine = new SonaEngine(config.hiddenDim);
111
- // Replace native with configured version
112
- engine._native = mod.SonaEngine.withConfig(config);
113
- return engine;
114
- }
115
- // -------------------------------------------------------------------------
116
- // Trajectory Recording
117
- // -------------------------------------------------------------------------
118
- /**
119
- * Begin recording a new trajectory
120
- * @param queryEmbedding Initial query embedding
121
- * @returns Trajectory ID for subsequent operations
122
- */
123
- beginTrajectory(queryEmbedding) {
124
- return this._native.beginTrajectory(toArray(queryEmbedding));
125
- }
126
- /**
127
- * Add a step to an active trajectory
128
- * @param trajectoryId Trajectory ID from beginTrajectory
129
- * @param activations Layer activations
130
- * @param attentionWeights Attention weights
131
- * @param reward Reward signal for this step (0.0 - 1.0)
132
- */
133
- addStep(trajectoryId, activations, attentionWeights, reward) {
134
- this._native.addTrajectoryStep(trajectoryId, toArray(activations), toArray(attentionWeights), reward);
135
- }
136
- /**
137
- * Alias for addStep for API compatibility
138
- */
139
- addTrajectoryStep(trajectoryId, activations, attentionWeights, reward) {
140
- this.addStep(trajectoryId, activations, attentionWeights, reward);
141
- }
142
- /**
143
- * Set the model route for a trajectory
144
- * @param trajectoryId Trajectory ID
145
- * @param route Model route identifier (e.g., "gpt-4", "claude-3")
146
- */
147
- setRoute(trajectoryId, route) {
148
- this._native.setTrajectoryRoute(trajectoryId, route);
149
- }
150
- /**
151
- * Add context to a trajectory
152
- * @param trajectoryId Trajectory ID
153
- * @param contextId Context identifier
154
- */
155
- addContext(trajectoryId, contextId) {
156
- this._native.addTrajectoryContext(trajectoryId, contextId);
157
- }
158
- /**
159
- * Complete a trajectory and submit for learning
160
- * @param trajectoryId Trajectory ID
161
- * @param quality Final quality score (0.0 - 1.0)
162
- */
163
- endTrajectory(trajectoryId, quality) {
164
- this._native.endTrajectory(trajectoryId, quality);
165
- }
166
- // -------------------------------------------------------------------------
167
- // LoRA Transformations
168
- // -------------------------------------------------------------------------
169
- /**
170
- * Apply micro-LoRA transformation (ultra-fast, ~0.1ms)
171
- * @param input Input vector
172
- * @returns Transformed output vector
173
- */
174
- applyMicroLora(input) {
175
- return this._native.applyMicroLora(toArray(input));
176
- }
177
- /**
178
- * Apply base-LoRA transformation to a specific layer
179
- * @param layerIdx Layer index
180
- * @param input Input vector
181
- * @returns Transformed output vector
182
- */
183
- applyBaseLora(layerIdx, input) {
184
- return this._native.applyBaseLora(layerIdx, toArray(input));
185
- }
186
- // -------------------------------------------------------------------------
187
- // Learning Control
188
- // -------------------------------------------------------------------------
189
- /**
190
- * Run background learning cycle if due
191
- * Call this periodically (e.g., every few seconds)
192
- * @returns Status message if learning occurred, null otherwise
193
- */
194
- tick() {
195
- return this._native.tick();
196
- }
197
- /**
198
- * Force immediate background learning cycle
199
- * @returns Status message with learning results
200
- */
201
- forceLearn() {
202
- return this._native.forceLearn();
203
- }
204
- /**
205
- * Flush pending instant loop updates
206
- */
207
- flush() {
208
- this._native.flush();
209
- }
210
- // -------------------------------------------------------------------------
211
- // Pattern Retrieval
212
- // -------------------------------------------------------------------------
213
- /**
214
- * Find similar learned patterns to a query
215
- * @param queryEmbedding Query embedding
216
- * @param k Number of patterns to return
217
- * @returns Array of similar patterns
218
- */
219
- findPatterns(queryEmbedding, k) {
220
- return this._native.findPatterns(toArray(queryEmbedding), k);
221
- }
222
- // -------------------------------------------------------------------------
223
- // Engine Control
224
- // -------------------------------------------------------------------------
225
- /**
226
- * Get engine statistics
227
- * @returns Statistics object
228
- */
229
- getStats() {
230
- const statsJson = this._native.getStats();
231
- const raw = JSON.parse(statsJson);
232
- // Map snake_case Rust fields to camelCase TypeScript (fixes #273)
233
- return {
234
- trajectoriesRecorded: raw.trajectories_recorded ?? raw.trajectoriesRecorded ?? (raw.trajectories_buffered ?? 0) + (raw.trajectories_dropped ?? 0),
235
- patternsLearned: raw.patterns_learned ?? raw.patternsLearned ?? raw.patterns_stored ?? 0,
236
- microLoraUpdates: raw.micro_lora_updates ?? raw.microLoraUpdates ?? 0,
237
- baseLoraUpdates: raw.base_lora_updates ?? raw.baseLoraUpdates ?? 0,
238
- ewcConsolidations: raw.ewc_tasks ?? raw.ewcConsolidations ?? 0,
239
- avgLearningTimeMs: raw.avg_learning_time_ms ?? raw.avgLearningTimeMs ?? 0,
240
- };
241
- }
242
- /**
243
- * Save engine state to JSON string for persistence across restarts (fixes #274)
244
- * @returns State JSON that can be stored to disk/database
245
- */
246
- saveState() {
247
- return this._native.saveState();
248
- }
249
- /**
250
- * Restore engine state from JSON saved by saveState() (fixes #274)
251
- * @param stateJson - JSON string from a previous saveState() call
252
- * @returns Number of patterns restored
253
- */
254
- loadState(stateJson) {
255
- return this._native.loadState(stateJson);
256
- }
257
- /**
258
- * Enable or disable the engine
259
- * @param enabled Whether to enable
260
- */
261
- setEnabled(enabled) {
262
- this._native.setEnabled(enabled);
263
- }
264
- /**
265
- * Check if engine is enabled
266
- */
267
- isEnabled() {
268
- return this._native.isEnabled();
269
- }
270
- }
271
- exports.SonaEngine = SonaEngine;
272
- // ============================================================================
273
- // Convenience Exports
274
- // ============================================================================
275
- /**
276
- * SONA namespace with all exports
277
- */
278
- exports.Sona = {
279
- Engine: SonaEngine,
280
- isAvailable: isSonaAvailable,
281
- };
282
- exports.default = exports.Sona;
@@ -1,134 +0,0 @@
1
- /**
2
- * TensorCompress - Adaptive tensor compression for intelligence storage
3
- * Provides 10x memory savings with access-frequency based compression
4
- */
5
- export type CompressionLevel = 'none' | 'half' | 'pq8' | 'pq4' | 'binary';
6
- export interface CompressedTensor {
7
- data: number[] | Uint8Array | Uint16Array | Float32Array;
8
- level: CompressionLevel;
9
- originalDim: number;
10
- accessCount: number;
11
- lastAccess: number;
12
- created: number;
13
- }
14
- export interface CompressionStats {
15
- totalTensors: number;
16
- byLevel: Record<CompressionLevel, number>;
17
- originalBytes: number;
18
- compressedBytes: number;
19
- savingsPercent: number;
20
- }
21
- export interface CompressionConfig {
22
- hotThreshold: number;
23
- warmThreshold: number;
24
- coolThreshold: number;
25
- coldThreshold: number;
26
- autoCompress: boolean;
27
- compressIntervalMs: number;
28
- }
29
- export declare class TensorCompress {
30
- private config;
31
- private tensors;
32
- private totalAccesses;
33
- private compressTimer;
34
- constructor(config?: Partial<CompressionConfig>);
35
- /**
36
- * Store a tensor with automatic compression based on access patterns
37
- */
38
- store(id: string, tensor: Float32Array | number[], level?: CompressionLevel): void;
39
- /**
40
- * Retrieve and decompress a tensor
41
- */
42
- get(id: string): Float32Array | null;
43
- /**
44
- * Check if tensor exists
45
- */
46
- has(id: string): boolean;
47
- /**
48
- * Delete a tensor
49
- */
50
- delete(id: string): boolean;
51
- /**
52
- * Get all tensor IDs
53
- */
54
- keys(): string[];
55
- /**
56
- * Compress tensor to specified level
57
- */
58
- private compress;
59
- /**
60
- * Decompress tensor back to Float32Array
61
- */
62
- private decompress;
63
- /**
64
- * Float16 conversion (approximate)
65
- */
66
- private toFloat16;
67
- private fromFloat16;
68
- private floatToHalf;
69
- private halfToFloat;
70
- /**
71
- * Product Quantization 8-bit
72
- */
73
- private toPQ8;
74
- private fromPQ8;
75
- /**
76
- * Product Quantization 4-bit (packed)
77
- */
78
- private toPQ4;
79
- private fromPQ4;
80
- /**
81
- * Binary quantization (1-bit per value)
82
- */
83
- private toBinary;
84
- private fromBinary;
85
- /**
86
- * Calculate access frequency for a tensor
87
- */
88
- private getAccessFrequency;
89
- /**
90
- * Determine optimal compression level based on access frequency
91
- */
92
- getOptimalLevel(id: string): CompressionLevel;
93
- /**
94
- * Recompress all tensors based on current access patterns
95
- */
96
- recompressAll(): CompressionStats;
97
- /**
98
- * Get compressed size in bytes
99
- */
100
- private getCompressedSize;
101
- /**
102
- * Get compression statistics
103
- */
104
- getStats(): CompressionStats;
105
- /**
106
- * Start auto-compression timer
107
- */
108
- private startAutoCompress;
109
- /**
110
- * Stop auto-compression
111
- */
112
- stopAutoCompress(): void;
113
- /**
114
- * Export all tensors for persistence
115
- */
116
- export(): {
117
- tensors: Record<string, any>;
118
- totalAccesses: number;
119
- };
120
- /**
121
- * Import tensors from persistence
122
- */
123
- import(data: {
124
- tensors: Record<string, any>;
125
- totalAccesses: number;
126
- }): void;
127
- private restoreTypedArray;
128
- /**
129
- * Clear all tensors
130
- */
131
- clear(): void;
132
- }
133
- export default TensorCompress;
134
- //# sourceMappingURL=tensor-compress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tensor-compress.d.ts","sourceRoot":"","sources":["../../src/core/tensor-compress.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;IACzD,KAAK,EAAE,gBAAgB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC1C,aAAa,EAAE,MAAM,CAAC;IACt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