ruvector 0.2.21 → 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.
- package/README.md +2 -2
- package/bin/cli.js +160 -0
- package/package.json +9 -5
- package/src/decompiler/api-prober.js +302 -0
- package/src/decompiler/model-decompiler.js +423 -0
- package/dist/analysis/complexity.d.ts +0 -52
- package/dist/analysis/complexity.d.ts.map +0 -1
- package/dist/analysis/complexity.js +0 -146
- package/dist/analysis/index.d.ts +0 -15
- package/dist/analysis/index.d.ts.map +0 -1
- package/dist/analysis/index.js +0 -38
- package/dist/analysis/patterns.d.ts +0 -71
- package/dist/analysis/patterns.d.ts.map +0 -1
- package/dist/analysis/patterns.js +0 -243
- package/dist/analysis/security.d.ts +0 -51
- package/dist/analysis/security.d.ts.map +0 -1
- package/dist/analysis/security.js +0 -139
- package/dist/core/adaptive-embedder.d.ts +0 -156
- package/dist/core/adaptive-embedder.d.ts.map +0 -1
- package/dist/core/adaptive-embedder.js +0 -838
- package/dist/core/agentdb-fast.d.ts +0 -149
- package/dist/core/agentdb-fast.d.ts.map +0 -1
- package/dist/core/agentdb-fast.js +0 -301
- package/dist/core/ast-parser.d.ts +0 -108
- package/dist/core/ast-parser.d.ts.map +0 -1
- package/dist/core/ast-parser.js +0 -602
- package/dist/core/attention-fallbacks.d.ts +0 -321
- package/dist/core/attention-fallbacks.d.ts.map +0 -1
- package/dist/core/attention-fallbacks.js +0 -552
- package/dist/core/cluster-wrapper.d.ts +0 -148
- package/dist/core/cluster-wrapper.d.ts.map +0 -1
- package/dist/core/cluster-wrapper.js +0 -271
- package/dist/core/coverage-router.d.ts +0 -88
- package/dist/core/coverage-router.d.ts.map +0 -1
- package/dist/core/coverage-router.js +0 -315
- package/dist/core/diff-embeddings.d.ts +0 -93
- package/dist/core/diff-embeddings.d.ts.map +0 -1
- package/dist/core/diff-embeddings.js +0 -334
- package/dist/core/gnn-wrapper.d.ts +0 -143
- package/dist/core/gnn-wrapper.d.ts.map +0 -1
- package/dist/core/gnn-wrapper.js +0 -213
- package/dist/core/graph-algorithms.d.ts +0 -83
- package/dist/core/graph-algorithms.d.ts.map +0 -1
- package/dist/core/graph-algorithms.js +0 -514
- package/dist/core/graph-wrapper.d.ts +0 -147
- package/dist/core/graph-wrapper.d.ts.map +0 -1
- package/dist/core/graph-wrapper.js +0 -299
- package/dist/core/index.d.ts +0 -48
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -89
- package/dist/core/intelligence-engine.d.ts +0 -258
- package/dist/core/intelligence-engine.d.ts.map +0 -1
- package/dist/core/intelligence-engine.js +0 -1030
- package/dist/core/learning-engine.d.ts +0 -160
- package/dist/core/learning-engine.d.ts.map +0 -1
- package/dist/core/learning-engine.js +0 -589
- package/dist/core/neural-embeddings.d.ts +0 -393
- package/dist/core/neural-embeddings.d.ts.map +0 -1
- package/dist/core/neural-embeddings.js +0 -1091
- package/dist/core/neural-perf.d.ts +0 -331
- package/dist/core/neural-perf.d.ts.map +0 -1
- package/dist/core/neural-perf.js +0 -704
- package/dist/core/onnx/loader.js +0 -348
- package/dist/core/onnx/pkg/LICENSE +0 -21
- package/dist/core/onnx/pkg/loader.js +0 -348
- package/dist/core/onnx/pkg/package.json +0 -3
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.d.ts +0 -112
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.js +0 -5
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.js +0 -638
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm +0 -0
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm.d.ts +0 -29
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_cjs.js +0 -127
- package/dist/core/onnx-embedder.d.ts +0 -105
- package/dist/core/onnx-embedder.d.ts.map +0 -1
- package/dist/core/onnx-embedder.js +0 -410
- package/dist/core/onnx-llm.d.ts +0 -206
- package/dist/core/onnx-llm.d.ts.map +0 -1
- package/dist/core/onnx-llm.js +0 -430
- package/dist/core/onnx-optimized.d.ts +0 -109
- package/dist/core/onnx-optimized.d.ts.map +0 -1
- package/dist/core/onnx-optimized.js +0 -419
- package/dist/core/parallel-intelligence.d.ts +0 -109
- package/dist/core/parallel-intelligence.d.ts.map +0 -1
- package/dist/core/parallel-intelligence.js +0 -340
- package/dist/core/parallel-workers.d.ts +0 -177
- package/dist/core/parallel-workers.d.ts.map +0 -1
- package/dist/core/parallel-workers.js +0 -671
- package/dist/core/router-wrapper.d.ts +0 -62
- package/dist/core/router-wrapper.d.ts.map +0 -1
- package/dist/core/router-wrapper.js +0 -209
- package/dist/core/rvf-wrapper.d.ts +0 -86
- package/dist/core/rvf-wrapper.d.ts.map +0 -1
- package/dist/core/rvf-wrapper.js +0 -102
- package/dist/core/sona-wrapper.d.ts +0 -226
- package/dist/core/sona-wrapper.d.ts.map +0 -1
- package/dist/core/sona-wrapper.js +0 -282
- package/dist/core/tensor-compress.d.ts +0 -134
- package/dist/core/tensor-compress.d.ts.map +0 -1
- package/dist/core/tensor-compress.js +0 -432
- package/dist/index.d.ts +0 -105
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -221
- package/dist/services/embedding-service.d.ts +0 -136
- package/dist/services/embedding-service.d.ts.map +0 -1
- package/dist/services/embedding-service.js +0 -294
- package/dist/services/index.d.ts +0 -6
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/index.js +0 -26
- package/dist/types.d.ts +0 -145
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/workers/benchmark.d.ts +0 -44
- package/dist/workers/benchmark.d.ts.map +0 -1
- package/dist/workers/benchmark.js +0 -230
- package/dist/workers/index.d.ts +0 -10
- package/dist/workers/index.d.ts.map +0 -1
- package/dist/workers/index.js +0 -25
- package/dist/workers/native-worker.d.ts +0 -76
- package/dist/workers/native-worker.d.ts.map +0 -1
- package/dist/workers/native-worker.js +0 -490
- package/dist/workers/types.d.ts +0 -69
- package/dist/workers/types.d.ts.map +0 -1
- package/dist/workers/types.js +0 -7
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* TensorCompress - Adaptive tensor compression for intelligence storage
|
|
4
|
-
* Provides 10x memory savings with access-frequency based compression
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.TensorCompress = void 0;
|
|
8
|
-
const DEFAULT_CONFIG = {
|
|
9
|
-
hotThreshold: 0.8,
|
|
10
|
-
warmThreshold: 0.4,
|
|
11
|
-
coolThreshold: 0.1,
|
|
12
|
-
coldThreshold: 0.01,
|
|
13
|
-
autoCompress: true,
|
|
14
|
-
compressIntervalMs: 60000, // 1 minute
|
|
15
|
-
};
|
|
16
|
-
class TensorCompress {
|
|
17
|
-
constructor(config = {}) {
|
|
18
|
-
this.tensors = new Map();
|
|
19
|
-
this.totalAccesses = 0;
|
|
20
|
-
this.compressTimer = null;
|
|
21
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
22
|
-
if (this.config.autoCompress) {
|
|
23
|
-
this.startAutoCompress();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Store a tensor with automatic compression based on access patterns
|
|
28
|
-
*/
|
|
29
|
-
store(id, tensor, level) {
|
|
30
|
-
const data = tensor instanceof Float32Array ? Array.from(tensor) : tensor;
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
// Check if updating existing tensor
|
|
33
|
-
const existing = this.tensors.get(id);
|
|
34
|
-
const accessCount = existing ? existing.accessCount : 0;
|
|
35
|
-
const compressed = this.compress(data, level || 'none');
|
|
36
|
-
this.tensors.set(id, {
|
|
37
|
-
data: compressed.data,
|
|
38
|
-
level: compressed.level,
|
|
39
|
-
originalDim: data.length,
|
|
40
|
-
accessCount,
|
|
41
|
-
lastAccess: now,
|
|
42
|
-
created: existing?.created || now,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Retrieve and decompress a tensor
|
|
47
|
-
*/
|
|
48
|
-
get(id) {
|
|
49
|
-
const tensor = this.tensors.get(id);
|
|
50
|
-
if (!tensor)
|
|
51
|
-
return null;
|
|
52
|
-
// Update access stats
|
|
53
|
-
tensor.accessCount++;
|
|
54
|
-
tensor.lastAccess = Date.now();
|
|
55
|
-
this.totalAccesses++;
|
|
56
|
-
// Decompress and return
|
|
57
|
-
return this.decompress(tensor);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Check if tensor exists
|
|
61
|
-
*/
|
|
62
|
-
has(id) {
|
|
63
|
-
return this.tensors.has(id);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Delete a tensor
|
|
67
|
-
*/
|
|
68
|
-
delete(id) {
|
|
69
|
-
return this.tensors.delete(id);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Get all tensor IDs
|
|
73
|
-
*/
|
|
74
|
-
keys() {
|
|
75
|
-
return Array.from(this.tensors.keys());
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Compress tensor to specified level
|
|
79
|
-
*/
|
|
80
|
-
compress(data, level) {
|
|
81
|
-
switch (level) {
|
|
82
|
-
case 'none':
|
|
83
|
-
return { data: new Float32Array(data), level };
|
|
84
|
-
case 'half':
|
|
85
|
-
// Float16 simulation using Uint16Array
|
|
86
|
-
return { data: this.toFloat16(data), level };
|
|
87
|
-
case 'pq8':
|
|
88
|
-
// Product quantization to 8-bit
|
|
89
|
-
return { data: this.toPQ8(data), level };
|
|
90
|
-
case 'pq4':
|
|
91
|
-
// Product quantization to 4-bit (packed into Uint8)
|
|
92
|
-
return { data: this.toPQ4(data), level };
|
|
93
|
-
case 'binary':
|
|
94
|
-
// Binary quantization (1-bit per value)
|
|
95
|
-
return { data: this.toBinary(data), level };
|
|
96
|
-
default:
|
|
97
|
-
return { data: new Float32Array(data), level: 'none' };
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Decompress tensor back to Float32Array
|
|
102
|
-
*/
|
|
103
|
-
decompress(tensor) {
|
|
104
|
-
const { data, level, originalDim } = tensor;
|
|
105
|
-
switch (level) {
|
|
106
|
-
case 'none':
|
|
107
|
-
return data instanceof Float32Array ? data : new Float32Array(data);
|
|
108
|
-
case 'half':
|
|
109
|
-
return this.fromFloat16(data, originalDim);
|
|
110
|
-
case 'pq8':
|
|
111
|
-
return this.fromPQ8(data, originalDim);
|
|
112
|
-
case 'pq4':
|
|
113
|
-
return this.fromPQ4(data, originalDim);
|
|
114
|
-
case 'binary':
|
|
115
|
-
return this.fromBinary(data, originalDim);
|
|
116
|
-
default:
|
|
117
|
-
return new Float32Array(data);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Float16 conversion (approximate)
|
|
122
|
-
*/
|
|
123
|
-
toFloat16(data) {
|
|
124
|
-
const result = new Uint16Array(data.length);
|
|
125
|
-
for (let i = 0; i < data.length; i++) {
|
|
126
|
-
result[i] = this.floatToHalf(data[i]);
|
|
127
|
-
}
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
fromFloat16(data, dim) {
|
|
131
|
-
const result = new Float32Array(dim);
|
|
132
|
-
for (let i = 0; i < dim; i++) {
|
|
133
|
-
result[i] = this.halfToFloat(data[i]);
|
|
134
|
-
}
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
|
-
floatToHalf(val) {
|
|
138
|
-
const floatView = new Float32Array(1);
|
|
139
|
-
const int32View = new Int32Array(floatView.buffer);
|
|
140
|
-
floatView[0] = val;
|
|
141
|
-
const x = int32View[0];
|
|
142
|
-
let bits = (x >> 16) & 0x8000;
|
|
143
|
-
let m = (x >> 12) & 0x07ff;
|
|
144
|
-
const e = (x >> 23) & 0xff;
|
|
145
|
-
if (e < 103)
|
|
146
|
-
return bits;
|
|
147
|
-
if (e > 142) {
|
|
148
|
-
bits |= 0x7c00;
|
|
149
|
-
bits |= ((e === 255) ? 0 : 1) && (x & 0x007fffff);
|
|
150
|
-
return bits;
|
|
151
|
-
}
|
|
152
|
-
if (e < 113) {
|
|
153
|
-
m |= 0x0800;
|
|
154
|
-
bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);
|
|
155
|
-
return bits;
|
|
156
|
-
}
|
|
157
|
-
bits |= ((e - 112) << 10) | (m >> 1);
|
|
158
|
-
bits += (m & 1);
|
|
159
|
-
return bits;
|
|
160
|
-
}
|
|
161
|
-
halfToFloat(val) {
|
|
162
|
-
const s = (val & 0x8000) >> 15;
|
|
163
|
-
const e = (val & 0x7C00) >> 10;
|
|
164
|
-
const f = val & 0x03FF;
|
|
165
|
-
if (e === 0) {
|
|
166
|
-
return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));
|
|
167
|
-
}
|
|
168
|
-
else if (e === 0x1F) {
|
|
169
|
-
return f ? NaN : ((s ? -1 : 1) * Infinity);
|
|
170
|
-
}
|
|
171
|
-
return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Product Quantization 8-bit
|
|
175
|
-
*/
|
|
176
|
-
toPQ8(data) {
|
|
177
|
-
const result = new Uint8Array(data.length);
|
|
178
|
-
const min = Math.min(...data);
|
|
179
|
-
const max = Math.max(...data);
|
|
180
|
-
const range = max - min || 1;
|
|
181
|
-
for (let i = 0; i < data.length; i++) {
|
|
182
|
-
result[i] = Math.round(((data[i] - min) / range) * 255);
|
|
183
|
-
}
|
|
184
|
-
// Store min/max in first 8 bytes for reconstruction
|
|
185
|
-
const output = new Uint8Array(data.length + 8);
|
|
186
|
-
const view = new DataView(output.buffer);
|
|
187
|
-
view.setFloat32(0, min, true);
|
|
188
|
-
view.setFloat32(4, max, true);
|
|
189
|
-
output.set(result, 8);
|
|
190
|
-
return output;
|
|
191
|
-
}
|
|
192
|
-
fromPQ8(data, dim) {
|
|
193
|
-
const view = new DataView(data.buffer, data.byteOffset);
|
|
194
|
-
const min = view.getFloat32(0, true);
|
|
195
|
-
const max = view.getFloat32(4, true);
|
|
196
|
-
const range = max - min || 1;
|
|
197
|
-
const result = new Float32Array(dim);
|
|
198
|
-
for (let i = 0; i < dim; i++) {
|
|
199
|
-
result[i] = (data[i + 8] / 255) * range + min;
|
|
200
|
-
}
|
|
201
|
-
return result;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Product Quantization 4-bit (packed)
|
|
205
|
-
*/
|
|
206
|
-
toPQ4(data) {
|
|
207
|
-
const packedLen = Math.ceil(data.length / 2);
|
|
208
|
-
const result = new Uint8Array(packedLen + 8);
|
|
209
|
-
const min = Math.min(...data);
|
|
210
|
-
const max = Math.max(...data);
|
|
211
|
-
const range = max - min || 1;
|
|
212
|
-
const view = new DataView(result.buffer);
|
|
213
|
-
view.setFloat32(0, min, true);
|
|
214
|
-
view.setFloat32(4, max, true);
|
|
215
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
216
|
-
const v1 = Math.round(((data[i] - min) / range) * 15);
|
|
217
|
-
const v2 = i + 1 < data.length ? Math.round(((data[i + 1] - min) / range) * 15) : 0;
|
|
218
|
-
result[8 + i / 2] = (v1 << 4) | v2;
|
|
219
|
-
}
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
fromPQ4(data, dim) {
|
|
223
|
-
const view = new DataView(data.buffer, data.byteOffset);
|
|
224
|
-
const min = view.getFloat32(0, true);
|
|
225
|
-
const max = view.getFloat32(4, true);
|
|
226
|
-
const range = max - min || 1;
|
|
227
|
-
const result = new Float32Array(dim);
|
|
228
|
-
for (let i = 0; i < dim; i += 2) {
|
|
229
|
-
const packed = data[8 + i / 2];
|
|
230
|
-
result[i] = ((packed >> 4) / 15) * range + min;
|
|
231
|
-
if (i + 1 < dim) {
|
|
232
|
-
result[i + 1] = ((packed & 0x0F) / 15) * range + min;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return result;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Binary quantization (1-bit per value)
|
|
239
|
-
*/
|
|
240
|
-
toBinary(data) {
|
|
241
|
-
const packedLen = Math.ceil(data.length / 8);
|
|
242
|
-
const result = new Uint8Array(packedLen + 4);
|
|
243
|
-
// Store mean for reconstruction
|
|
244
|
-
const mean = data.reduce((a, b) => a + b, 0) / data.length;
|
|
245
|
-
const view = new DataView(result.buffer);
|
|
246
|
-
view.setFloat32(0, mean, true);
|
|
247
|
-
for (let i = 0; i < data.length; i++) {
|
|
248
|
-
if (data[i] >= mean) {
|
|
249
|
-
const byteIdx = 4 + Math.floor(i / 8);
|
|
250
|
-
const bitIdx = i % 8;
|
|
251
|
-
result[byteIdx] |= (1 << bitIdx);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return result;
|
|
255
|
-
}
|
|
256
|
-
fromBinary(data, dim) {
|
|
257
|
-
const view = new DataView(data.buffer, data.byteOffset);
|
|
258
|
-
const mean = view.getFloat32(0, true);
|
|
259
|
-
// Use fixed deviation for reconstruction
|
|
260
|
-
const deviation = 0.5;
|
|
261
|
-
const result = new Float32Array(dim);
|
|
262
|
-
for (let i = 0; i < dim; i++) {
|
|
263
|
-
const byteIdx = 4 + Math.floor(i / 8);
|
|
264
|
-
const bitIdx = i % 8;
|
|
265
|
-
const bit = (data[byteIdx] >> bitIdx) & 1;
|
|
266
|
-
result[i] = bit ? mean + deviation : mean - deviation;
|
|
267
|
-
}
|
|
268
|
-
return result;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Calculate access frequency for a tensor
|
|
272
|
-
*/
|
|
273
|
-
getAccessFrequency(tensor) {
|
|
274
|
-
if (this.totalAccesses === 0)
|
|
275
|
-
return 1;
|
|
276
|
-
return tensor.accessCount / this.totalAccesses;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Determine optimal compression level based on access frequency
|
|
280
|
-
*/
|
|
281
|
-
getOptimalLevel(id) {
|
|
282
|
-
const tensor = this.tensors.get(id);
|
|
283
|
-
if (!tensor)
|
|
284
|
-
return 'none';
|
|
285
|
-
const freq = this.getAccessFrequency(tensor);
|
|
286
|
-
if (freq > this.config.hotThreshold)
|
|
287
|
-
return 'none';
|
|
288
|
-
if (freq > this.config.warmThreshold)
|
|
289
|
-
return 'half';
|
|
290
|
-
if (freq > this.config.coolThreshold)
|
|
291
|
-
return 'pq8';
|
|
292
|
-
if (freq > this.config.coldThreshold)
|
|
293
|
-
return 'pq4';
|
|
294
|
-
return 'binary';
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Recompress all tensors based on current access patterns
|
|
298
|
-
*/
|
|
299
|
-
recompressAll() {
|
|
300
|
-
const stats = {
|
|
301
|
-
totalTensors: this.tensors.size,
|
|
302
|
-
byLevel: { none: 0, half: 0, pq8: 0, pq4: 0, binary: 0 },
|
|
303
|
-
originalBytes: 0,
|
|
304
|
-
compressedBytes: 0,
|
|
305
|
-
savingsPercent: 0,
|
|
306
|
-
};
|
|
307
|
-
for (const [id, tensor] of this.tensors) {
|
|
308
|
-
const optimalLevel = this.getOptimalLevel(id);
|
|
309
|
-
if (optimalLevel !== tensor.level) {
|
|
310
|
-
// Decompress and recompress at new level
|
|
311
|
-
const decompressed = this.decompress(tensor);
|
|
312
|
-
const recompressed = this.compress(Array.from(decompressed), optimalLevel);
|
|
313
|
-
tensor.data = recompressed.data;
|
|
314
|
-
tensor.level = recompressed.level;
|
|
315
|
-
}
|
|
316
|
-
stats.byLevel[tensor.level]++;
|
|
317
|
-
stats.originalBytes += tensor.originalDim * 4; // Float32
|
|
318
|
-
stats.compressedBytes += this.getCompressedSize(tensor);
|
|
319
|
-
}
|
|
320
|
-
stats.savingsPercent = stats.originalBytes > 0
|
|
321
|
-
? ((stats.originalBytes - stats.compressedBytes) / stats.originalBytes) * 100
|
|
322
|
-
: 0;
|
|
323
|
-
return stats;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Get compressed size in bytes
|
|
327
|
-
*/
|
|
328
|
-
getCompressedSize(tensor) {
|
|
329
|
-
const { data, level, originalDim } = tensor;
|
|
330
|
-
switch (level) {
|
|
331
|
-
case 'none': return originalDim * 4;
|
|
332
|
-
case 'half': return originalDim * 2;
|
|
333
|
-
case 'pq8': return originalDim + 8;
|
|
334
|
-
case 'pq4': return Math.ceil(originalDim / 2) + 8;
|
|
335
|
-
case 'binary': return Math.ceil(originalDim / 8) + 4;
|
|
336
|
-
default: return originalDim * 4;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Get compression statistics
|
|
341
|
-
*/
|
|
342
|
-
getStats() {
|
|
343
|
-
const stats = {
|
|
344
|
-
totalTensors: this.tensors.size,
|
|
345
|
-
byLevel: { none: 0, half: 0, pq8: 0, pq4: 0, binary: 0 },
|
|
346
|
-
originalBytes: 0,
|
|
347
|
-
compressedBytes: 0,
|
|
348
|
-
savingsPercent: 0,
|
|
349
|
-
};
|
|
350
|
-
for (const tensor of this.tensors.values()) {
|
|
351
|
-
stats.byLevel[tensor.level]++;
|
|
352
|
-
stats.originalBytes += tensor.originalDim * 4;
|
|
353
|
-
stats.compressedBytes += this.getCompressedSize(tensor);
|
|
354
|
-
}
|
|
355
|
-
stats.savingsPercent = stats.originalBytes > 0
|
|
356
|
-
? ((stats.originalBytes - stats.compressedBytes) / stats.originalBytes) * 100
|
|
357
|
-
: 0;
|
|
358
|
-
return stats;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Start auto-compression timer
|
|
362
|
-
*/
|
|
363
|
-
startAutoCompress() {
|
|
364
|
-
if (this.compressTimer)
|
|
365
|
-
return;
|
|
366
|
-
this.compressTimer = setInterval(() => {
|
|
367
|
-
this.recompressAll();
|
|
368
|
-
}, this.config.compressIntervalMs);
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Stop auto-compression
|
|
372
|
-
*/
|
|
373
|
-
stopAutoCompress() {
|
|
374
|
-
if (this.compressTimer) {
|
|
375
|
-
clearInterval(this.compressTimer);
|
|
376
|
-
this.compressTimer = null;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Export all tensors for persistence
|
|
381
|
-
*/
|
|
382
|
-
export() {
|
|
383
|
-
const tensors = {};
|
|
384
|
-
for (const [id, tensor] of this.tensors) {
|
|
385
|
-
tensors[id] = {
|
|
386
|
-
data: Array.from(tensor.data),
|
|
387
|
-
level: tensor.level,
|
|
388
|
-
originalDim: tensor.originalDim,
|
|
389
|
-
accessCount: tensor.accessCount,
|
|
390
|
-
lastAccess: tensor.lastAccess,
|
|
391
|
-
created: tensor.created,
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
return { tensors, totalAccesses: this.totalAccesses };
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Import tensors from persistence
|
|
398
|
-
*/
|
|
399
|
-
import(data) {
|
|
400
|
-
this.totalAccesses = data.totalAccesses || 0;
|
|
401
|
-
for (const [id, tensor] of Object.entries(data.tensors)) {
|
|
402
|
-
const t = tensor;
|
|
403
|
-
this.tensors.set(id, {
|
|
404
|
-
data: this.restoreTypedArray(t.data, t.level),
|
|
405
|
-
level: t.level,
|
|
406
|
-
originalDim: t.originalDim,
|
|
407
|
-
accessCount: t.accessCount || 0,
|
|
408
|
-
lastAccess: t.lastAccess || Date.now(),
|
|
409
|
-
created: t.created || Date.now(),
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
restoreTypedArray(data, level) {
|
|
414
|
-
switch (level) {
|
|
415
|
-
case 'none': return new Float32Array(data);
|
|
416
|
-
case 'half': return new Uint16Array(data);
|
|
417
|
-
case 'pq8':
|
|
418
|
-
case 'pq4':
|
|
419
|
-
case 'binary': return new Uint8Array(data);
|
|
420
|
-
default: return new Float32Array(data);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Clear all tensors
|
|
425
|
-
*/
|
|
426
|
-
clear() {
|
|
427
|
-
this.tensors.clear();
|
|
428
|
-
this.totalAccesses = 0;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
exports.TensorCompress = TensorCompress;
|
|
432
|
-
exports.default = TensorCompress;
|
package/dist/index.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ruvector - High-performance vector database for Node.js
|
|
3
|
-
*
|
|
4
|
-
* This package automatically detects and uses the best available implementation:
|
|
5
|
-
* 1. Native (Rust-based, fastest) - if available for your platform
|
|
6
|
-
* 2. RVF (persistent store) - if @ruvector/rvf is installed
|
|
7
|
-
* 3. Stub (testing fallback) - limited functionality
|
|
8
|
-
*
|
|
9
|
-
* Also provides safe wrappers for GNN and Attention modules that handle
|
|
10
|
-
* array type conversions automatically.
|
|
11
|
-
*/
|
|
12
|
-
export * from './types';
|
|
13
|
-
export * from './core';
|
|
14
|
-
export * from './services';
|
|
15
|
-
declare let implementation: any;
|
|
16
|
-
/**
|
|
17
|
-
* Get the current implementation type
|
|
18
|
-
*/
|
|
19
|
-
export declare function getImplementationType(): 'native' | 'rvf' | 'wasm';
|
|
20
|
-
/**
|
|
21
|
-
* Check if native implementation is being used
|
|
22
|
-
*/
|
|
23
|
-
export declare function isNative(): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Check if RVF implementation is being used
|
|
26
|
-
*/
|
|
27
|
-
export declare function isRvf(): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Check if stub/fallback implementation is being used
|
|
30
|
-
*/
|
|
31
|
-
export declare function isWasm(): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Get version information
|
|
34
|
-
*/
|
|
35
|
-
export declare function getVersion(): {
|
|
36
|
-
version: string;
|
|
37
|
-
implementation: string;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Wrapper class that automatically handles metadata JSON conversion
|
|
41
|
-
*/
|
|
42
|
-
declare class VectorDBWrapper {
|
|
43
|
-
private db;
|
|
44
|
-
constructor(options: {
|
|
45
|
-
dimensions: number;
|
|
46
|
-
storagePath?: string;
|
|
47
|
-
distanceMetric?: string;
|
|
48
|
-
hnswConfig?: any;
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* Insert a vector with optional metadata (objects are auto-converted to JSON)
|
|
52
|
-
*/
|
|
53
|
-
insert(entry: {
|
|
54
|
-
id?: string;
|
|
55
|
-
vector: Float32Array | number[];
|
|
56
|
-
metadata?: Record<string, any>;
|
|
57
|
-
}): Promise<string>;
|
|
58
|
-
/**
|
|
59
|
-
* Insert multiple vectors in batch
|
|
60
|
-
*/
|
|
61
|
-
insertBatch(entries: Array<{
|
|
62
|
-
id?: string;
|
|
63
|
-
vector: Float32Array | number[];
|
|
64
|
-
metadata?: Record<string, any>;
|
|
65
|
-
}>): Promise<string[]>;
|
|
66
|
-
/**
|
|
67
|
-
* Search for similar vectors (metadata is auto-parsed from JSON)
|
|
68
|
-
*/
|
|
69
|
-
search(query: {
|
|
70
|
-
vector: Float32Array | number[];
|
|
71
|
-
k: number;
|
|
72
|
-
filter?: Record<string, any>;
|
|
73
|
-
efSearch?: number;
|
|
74
|
-
}): Promise<Array<{
|
|
75
|
-
id: string;
|
|
76
|
-
score: number;
|
|
77
|
-
vector?: Float32Array;
|
|
78
|
-
metadata?: Record<string, any>;
|
|
79
|
-
}>>;
|
|
80
|
-
/**
|
|
81
|
-
* Get a vector by ID (metadata is auto-parsed from JSON)
|
|
82
|
-
*/
|
|
83
|
-
get(id: string): Promise<{
|
|
84
|
-
id?: string;
|
|
85
|
-
vector: Float32Array;
|
|
86
|
-
metadata?: Record<string, any>;
|
|
87
|
-
} | null>;
|
|
88
|
-
/**
|
|
89
|
-
* Delete a vector by ID
|
|
90
|
-
*/
|
|
91
|
-
delete(id: string): Promise<boolean>;
|
|
92
|
-
/**
|
|
93
|
-
* Get the number of vectors in the database
|
|
94
|
-
*/
|
|
95
|
-
len(): Promise<number>;
|
|
96
|
-
/**
|
|
97
|
-
* Check if the database is empty
|
|
98
|
-
*/
|
|
99
|
-
isEmpty(): Promise<boolean>;
|
|
100
|
-
}
|
|
101
|
-
export declare const VectorDb: typeof VectorDBWrapper;
|
|
102
|
-
export declare const VectorDB: typeof VectorDBWrapper;
|
|
103
|
-
export declare const NativeVectorDb: any;
|
|
104
|
-
export default implementation;
|
|
105
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,SAAS,CAAC;AAGxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAE3B,QAAA,IAAI,cAAc,EAAE,GAAG,CAAC;AA4DxB;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,QAAQ,GAAG,KAAK,GAAG,MAAM,CAEjE;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAElC;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAEhC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAMxE;AAED;;GAEG;AACH,cAAM,eAAe;IACnB,OAAO,CAAC,EAAE,CAAM;gBAEJ,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,GAAG,CAAA;KAAE;IAI5G;;OAEG;IACG,MAAM,CAAC,KAAK,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IActH;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUtI;;OAEG;IACG,MAAM,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,CAAC,CAAC;IAuB1N;;OAEG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,YAAY,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;IAW5G;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1C;;OAEG;IACG,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;CAGlC;AAGD,eAAO,MAAM,QAAQ,wBAAkB,CAAC;AACxC,eAAO,MAAM,QAAQ,wBAAkB,CAAC;AAGxC,eAAO,MAAM,cAAc,KAA0B,CAAC;AAGtD,eAAe,cAAc,CAAC"}
|