ruvector 0.1.37 → 0.1.39
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/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude-flow/metrics/performance.json +87 -0
- package/.claude-flow/metrics/task-metrics.json +10 -0
- package/PACKAGE_SUMMARY.md +409 -0
- package/README.md +1706 -455
- package/bin/cli.js +2427 -0
- package/dist/core/agentdb-fast.d.ts +149 -0
- package/dist/core/agentdb-fast.d.ts.map +1 -0
- package/dist/core/agentdb-fast.js +301 -0
- package/dist/core/attention-fallbacks.d.ts +221 -0
- package/dist/core/attention-fallbacks.d.ts.map +1 -0
- package/dist/core/attention-fallbacks.js +361 -0
- package/dist/core/gnn-wrapper.d.ts +143 -0
- package/dist/core/gnn-wrapper.d.ts.map +1 -0
- package/dist/core/gnn-wrapper.js +213 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +39 -0
- package/dist/core/sona-wrapper.d.ts +215 -0
- package/dist/core/sona-wrapper.d.ts.map +1 -0
- package/dist/core/sona-wrapper.js +258 -0
- package/dist/index.d.ts +87 -82
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -89
- package/dist/services/embedding-service.d.ts +136 -0
- package/dist/services/embedding-service.d.ts.map +1 -0
- package/dist/services/embedding-service.js +294 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +26 -0
- package/dist/types.d.ts +145 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/examples/api-usage.js +211 -0
- package/examples/cli-demo.sh +85 -0
- package/package.json +41 -93
- package/bin/ruvector.js +0 -1150
- package/dist/index.d.mts +0 -95
- package/dist/index.mjs +0 -5
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
* The native @ruvector/gnn requires Float32Array for maximum performance.
|
|
9
|
+
* This wrapper converts any input type to Float32Array automatically.
|
|
10
|
+
*
|
|
11
|
+
* Performance Tips:
|
|
12
|
+
* - Pass Float32Array directly for zero-copy performance
|
|
13
|
+
* - Use toFloat32Array/toFloat32ArrayBatch for pre-conversion
|
|
14
|
+
* - Avoid repeated conversions in hot paths
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TensorCompress = exports.RuvectorLayer = void 0;
|
|
18
|
+
exports.toFloat32Array = toFloat32Array;
|
|
19
|
+
exports.toFloat32ArrayBatch = toFloat32ArrayBatch;
|
|
20
|
+
exports.differentiableSearch = differentiableSearch;
|
|
21
|
+
exports.hierarchicalForward = hierarchicalForward;
|
|
22
|
+
exports.getCompressionLevel = getCompressionLevel;
|
|
23
|
+
exports.isGnnAvailable = isGnnAvailable;
|
|
24
|
+
// Lazy load to avoid import errors if not installed
|
|
25
|
+
let gnnModule = null;
|
|
26
|
+
let loadError = null;
|
|
27
|
+
function getGnnModule() {
|
|
28
|
+
if (gnnModule)
|
|
29
|
+
return gnnModule;
|
|
30
|
+
if (loadError)
|
|
31
|
+
throw loadError;
|
|
32
|
+
try {
|
|
33
|
+
gnnModule = require('@ruvector/gnn');
|
|
34
|
+
return gnnModule;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
loadError = new Error(`@ruvector/gnn is not installed or failed to load: ${e.message}\n` +
|
|
38
|
+
`Install with: npm install @ruvector/gnn`);
|
|
39
|
+
throw loadError;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convert any array-like input to Float32Array (native requires Float32Array)
|
|
44
|
+
* Optimized paths:
|
|
45
|
+
* - Float32Array: zero-copy return
|
|
46
|
+
* - Float64Array: efficient typed array copy
|
|
47
|
+
* - Array: direct Float32Array construction
|
|
48
|
+
*/
|
|
49
|
+
function toFloat32Array(input) {
|
|
50
|
+
if (input instanceof Float32Array)
|
|
51
|
+
return input;
|
|
52
|
+
if (input instanceof Float64Array)
|
|
53
|
+
return new Float32Array(input);
|
|
54
|
+
if (Array.isArray(input))
|
|
55
|
+
return new Float32Array(input);
|
|
56
|
+
return new Float32Array(Array.from(input));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Convert array of arrays to array of Float32Arrays
|
|
60
|
+
*/
|
|
61
|
+
function toFloat32ArrayBatch(input) {
|
|
62
|
+
const result = new Array(input.length);
|
|
63
|
+
for (let i = 0; i < input.length; i++) {
|
|
64
|
+
result[i] = toFloat32Array(input[i]);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Differentiable search using soft attention mechanism
|
|
70
|
+
*
|
|
71
|
+
* This wrapper automatically converts Float32Array inputs to regular arrays.
|
|
72
|
+
*
|
|
73
|
+
* @param query - Query vector (array or Float32Array)
|
|
74
|
+
* @param candidates - List of candidate vectors (arrays or Float32Arrays)
|
|
75
|
+
* @param k - Number of top results to return
|
|
76
|
+
* @param temperature - Temperature for softmax (lower = sharper, higher = smoother)
|
|
77
|
+
* @returns Search result with indices and soft weights
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { differentiableSearch } from 'ruvector/core/gnn-wrapper';
|
|
82
|
+
*
|
|
83
|
+
* // Works with regular arrays (auto-converted to Float32Array)
|
|
84
|
+
* const result1 = differentiableSearch([1, 0, 0], [[1, 0, 0], [0, 1, 0]], 2, 1.0);
|
|
85
|
+
*
|
|
86
|
+
* // For best performance, use Float32Array directly (zero-copy)
|
|
87
|
+
* const query = new Float32Array([1, 0, 0]);
|
|
88
|
+
* const candidates = [new Float32Array([1, 0, 0]), new Float32Array([0, 1, 0])];
|
|
89
|
+
* const result2 = differentiableSearch(query, candidates, 2, 1.0);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
function differentiableSearch(query, candidates, k, temperature = 1.0) {
|
|
93
|
+
const gnn = getGnnModule();
|
|
94
|
+
// Convert to Float32Array (native Rust expects Float32Array for performance)
|
|
95
|
+
const queryFloat32 = toFloat32Array(query);
|
|
96
|
+
const candidatesFloat32 = toFloat32ArrayBatch(candidates);
|
|
97
|
+
return gnn.differentiableSearch(queryFloat32, candidatesFloat32, k, temperature);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* GNN Layer for HNSW topology
|
|
101
|
+
*/
|
|
102
|
+
class RuvectorLayer {
|
|
103
|
+
/**
|
|
104
|
+
* Create a new Ruvector GNN layer
|
|
105
|
+
*
|
|
106
|
+
* @param inputDim - Dimension of input node embeddings
|
|
107
|
+
* @param hiddenDim - Dimension of hidden representations
|
|
108
|
+
* @param heads - Number of attention heads
|
|
109
|
+
* @param dropout - Dropout rate (0.0 to 1.0)
|
|
110
|
+
*/
|
|
111
|
+
constructor(inputDim, hiddenDim, heads, dropout = 0.1) {
|
|
112
|
+
const gnn = getGnnModule();
|
|
113
|
+
this.inner = new gnn.RuvectorLayer(inputDim, hiddenDim, heads, dropout);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Forward pass through the GNN layer
|
|
117
|
+
*
|
|
118
|
+
* @param nodeEmbedding - Current node's embedding
|
|
119
|
+
* @param neighborEmbeddings - Embeddings of neighbor nodes
|
|
120
|
+
* @param edgeWeights - Weights of edges to neighbors
|
|
121
|
+
* @returns Updated node embedding as Float32Array
|
|
122
|
+
*/
|
|
123
|
+
forward(nodeEmbedding, neighborEmbeddings, edgeWeights) {
|
|
124
|
+
return this.inner.forward(toFloat32Array(nodeEmbedding), toFloat32ArrayBatch(neighborEmbeddings), toFloat32Array(edgeWeights));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Serialize the layer to JSON
|
|
128
|
+
*/
|
|
129
|
+
toJson() {
|
|
130
|
+
return this.inner.toJson();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Deserialize the layer from JSON
|
|
134
|
+
*/
|
|
135
|
+
static fromJson(json) {
|
|
136
|
+
const gnn = getGnnModule();
|
|
137
|
+
const layer = new RuvectorLayer(1, 1, 1, 0); // Dummy constructor
|
|
138
|
+
layer.inner = gnn.RuvectorLayer.fromJson(json);
|
|
139
|
+
return layer;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.RuvectorLayer = RuvectorLayer;
|
|
143
|
+
/**
|
|
144
|
+
* Tensor compressor with adaptive level selection
|
|
145
|
+
*/
|
|
146
|
+
class TensorCompress {
|
|
147
|
+
constructor() {
|
|
148
|
+
const gnn = getGnnModule();
|
|
149
|
+
this.inner = new gnn.TensorCompress();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Compress an embedding based on access frequency
|
|
153
|
+
*
|
|
154
|
+
* @param embedding - Input embedding vector
|
|
155
|
+
* @param accessFreq - Access frequency (0.0 to 1.0)
|
|
156
|
+
* @returns Compressed tensor as JSON string
|
|
157
|
+
*/
|
|
158
|
+
compress(embedding, accessFreq) {
|
|
159
|
+
return this.inner.compress(toFloat32Array(embedding), accessFreq);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Decompress a compressed tensor
|
|
163
|
+
*
|
|
164
|
+
* @param compressedJson - Compressed tensor JSON
|
|
165
|
+
* @returns Decompressed embedding
|
|
166
|
+
*/
|
|
167
|
+
decompress(compressedJson) {
|
|
168
|
+
return this.inner.decompress(compressedJson);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.TensorCompress = TensorCompress;
|
|
172
|
+
/**
|
|
173
|
+
* Hierarchical forward pass through GNN layers
|
|
174
|
+
*
|
|
175
|
+
* @param query - Query vector
|
|
176
|
+
* @param layerEmbeddings - Embeddings organized by layer
|
|
177
|
+
* @param gnnLayersJson - JSON array of serialized GNN layers
|
|
178
|
+
* @returns Final embedding after hierarchical processing as Float32Array
|
|
179
|
+
*/
|
|
180
|
+
function hierarchicalForward(query, layerEmbeddings, gnnLayersJson) {
|
|
181
|
+
const gnn = getGnnModule();
|
|
182
|
+
return gnn.hierarchicalForward(toFloat32Array(query), layerEmbeddings.map(layer => toFloat32ArrayBatch(layer)), gnnLayersJson);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get compression level for a given access frequency
|
|
186
|
+
*/
|
|
187
|
+
function getCompressionLevel(accessFreq) {
|
|
188
|
+
const gnn = getGnnModule();
|
|
189
|
+
return gnn.getCompressionLevel(accessFreq);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Check if GNN module is available
|
|
193
|
+
*/
|
|
194
|
+
function isGnnAvailable() {
|
|
195
|
+
try {
|
|
196
|
+
getGnnModule();
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.default = {
|
|
204
|
+
differentiableSearch,
|
|
205
|
+
RuvectorLayer,
|
|
206
|
+
TensorCompress,
|
|
207
|
+
hierarchicalForward,
|
|
208
|
+
getCompressionLevel,
|
|
209
|
+
isGnnAvailable,
|
|
210
|
+
// Export conversion helpers for performance optimization
|
|
211
|
+
toFloat32Array,
|
|
212
|
+
toFloat32ArrayBatch,
|
|
213
|
+
};
|
|
@@ -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;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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