ruvector 0.1.85 → 0.1.87

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,329 @@
1
+ /**
2
+ * Neural Performance Optimizations
3
+ *
4
+ * High-performance utilities for neural embedding operations:
5
+ * - O(1) LRU Cache with doubly-linked list + hash map
6
+ * - Parallel batch processing
7
+ * - Pre-allocated Float32Array buffer pools
8
+ * - Tensor buffer reuse
9
+ * - 8x loop unrolling for vector operations
10
+ */
11
+ export declare const PERF_CONSTANTS: {
12
+ readonly DEFAULT_CACHE_SIZE: 1000;
13
+ readonly DEFAULT_BUFFER_POOL_SIZE: 64;
14
+ readonly DEFAULT_BATCH_SIZE: 32;
15
+ readonly MIN_PARALLEL_BATCH_SIZE: 8;
16
+ readonly UNROLL_THRESHOLD: 32;
17
+ };
18
+ /**
19
+ * High-performance LRU Cache with O(1) get, set, and eviction.
20
+ * Uses doubly-linked list for ordering + hash map for O(1) lookup.
21
+ */
22
+ export declare class LRUCache<K, V> {
23
+ private capacity;
24
+ private map;
25
+ private head;
26
+ private tail;
27
+ private hits;
28
+ private misses;
29
+ constructor(capacity?: number);
30
+ /**
31
+ * Get value from cache - O(1)
32
+ */
33
+ get(key: K): V | undefined;
34
+ /**
35
+ * Set value in cache - O(1)
36
+ */
37
+ set(key: K, value: V): void;
38
+ /**
39
+ * Check if key exists - O(1)
40
+ */
41
+ has(key: K): boolean;
42
+ /**
43
+ * Delete key from cache - O(1)
44
+ */
45
+ delete(key: K): boolean;
46
+ /**
47
+ * Clear entire cache - O(1)
48
+ */
49
+ clear(): void;
50
+ /**
51
+ * Get cache size
52
+ */
53
+ get size(): number;
54
+ /**
55
+ * Get cache statistics
56
+ */
57
+ getStats(): {
58
+ size: number;
59
+ capacity: number;
60
+ hits: number;
61
+ misses: number;
62
+ hitRate: number;
63
+ };
64
+ /**
65
+ * Reset statistics
66
+ */
67
+ resetStats(): void;
68
+ private moveToHead;
69
+ private addToHead;
70
+ private removeNode;
71
+ private evictLRU;
72
+ /**
73
+ * Iterate over entries (most recent first)
74
+ */
75
+ entries(): Generator<[K, V]>;
76
+ }
77
+ /**
78
+ * High-performance buffer pool for Float32Arrays.
79
+ * Eliminates GC pressure by reusing pre-allocated buffers.
80
+ */
81
+ export declare class Float32BufferPool {
82
+ private pools;
83
+ private maxPoolSize;
84
+ private allocations;
85
+ private reuses;
86
+ constructor(maxPoolSize?: number);
87
+ /**
88
+ * Acquire a buffer of specified size - O(1) amortized
89
+ */
90
+ acquire(size: number): Float32Array;
91
+ /**
92
+ * Release a buffer back to the pool - O(1)
93
+ */
94
+ release(buffer: Float32Array): void;
95
+ /**
96
+ * Pre-warm the pool with buffers of specific sizes
97
+ */
98
+ prewarm(sizes: number[], count?: number): void;
99
+ /**
100
+ * Clear all pools
101
+ */
102
+ clear(): void;
103
+ /**
104
+ * Get pool statistics
105
+ */
106
+ getStats(): {
107
+ allocations: number;
108
+ reuses: number;
109
+ reuseRate: number;
110
+ pooledBuffers: number;
111
+ };
112
+ }
113
+ /**
114
+ * Manages reusable tensor buffers for intermediate computations.
115
+ * Reduces allocations in hot paths.
116
+ */
117
+ export declare class TensorBufferManager {
118
+ private bufferPool;
119
+ private workingBuffers;
120
+ constructor(pool?: Float32BufferPool);
121
+ /**
122
+ * Get or create a named working buffer
123
+ */
124
+ getWorking(name: string, size: number): Float32Array;
125
+ /**
126
+ * Get a temporary buffer (caller must release)
127
+ */
128
+ getTemp(size: number): Float32Array;
129
+ /**
130
+ * Release a temporary buffer
131
+ */
132
+ releaseTemp(buffer: Float32Array): void;
133
+ /**
134
+ * Release all working buffers
135
+ */
136
+ releaseAll(): void;
137
+ /**
138
+ * Get underlying pool for stats
139
+ */
140
+ getPool(): Float32BufferPool;
141
+ }
142
+ /**
143
+ * High-performance vector operations with 8x loop unrolling.
144
+ * Provides 15-30% speedup on large vectors.
145
+ */
146
+ export declare const VectorOps: {
147
+ /**
148
+ * Dot product with 8x unrolling
149
+ */
150
+ dot(a: Float32Array, b: Float32Array): number;
151
+ /**
152
+ * Squared L2 norm with 8x unrolling
153
+ */
154
+ normSq(a: Float32Array): number;
155
+ /**
156
+ * L2 norm
157
+ */
158
+ norm(a: Float32Array): number;
159
+ /**
160
+ * Cosine similarity with 8x unrolling
161
+ */
162
+ cosine(a: Float32Array, b: Float32Array): number;
163
+ /**
164
+ * Euclidean distance squared with 8x unrolling
165
+ */
166
+ distanceSq(a: Float32Array, b: Float32Array): number;
167
+ /**
168
+ * Euclidean distance
169
+ */
170
+ distance(a: Float32Array, b: Float32Array): number;
171
+ /**
172
+ * Add vectors: out = a + b (with 8x unrolling)
173
+ */
174
+ add(a: Float32Array, b: Float32Array, out: Float32Array): Float32Array;
175
+ /**
176
+ * Subtract vectors: out = a - b (with 8x unrolling)
177
+ */
178
+ sub(a: Float32Array, b: Float32Array, out: Float32Array): Float32Array;
179
+ /**
180
+ * Scale vector: out = a * scalar (with 8x unrolling)
181
+ */
182
+ scale(a: Float32Array, scalar: number, out: Float32Array): Float32Array;
183
+ /**
184
+ * Normalize vector in-place
185
+ */
186
+ normalize(a: Float32Array): Float32Array;
187
+ /**
188
+ * Mean of multiple vectors (with buffer reuse)
189
+ */
190
+ mean(vectors: Float32Array[], out: Float32Array): Float32Array;
191
+ };
192
+ export interface BatchResult<T> {
193
+ results: T[];
194
+ timing: {
195
+ totalMs: number;
196
+ perItemMs: number;
197
+ };
198
+ }
199
+ /**
200
+ * Parallel batch processor for embedding operations.
201
+ * Uses chunking and Promise.all for concurrent processing.
202
+ */
203
+ export declare class ParallelBatchProcessor {
204
+ private batchSize;
205
+ private maxConcurrency;
206
+ constructor(options?: {
207
+ batchSize?: number;
208
+ maxConcurrency?: number;
209
+ });
210
+ /**
211
+ * Process items in parallel batches
212
+ */
213
+ processBatch<T, R>(items: T[], processor: (item: T, index: number) => Promise<R> | R): Promise<BatchResult<R>>;
214
+ /**
215
+ * Process with synchronous function (uses chunking for better cache locality)
216
+ */
217
+ processSync<T, R>(items: T[], processor: (item: T, index: number) => R): BatchResult<R>;
218
+ /**
219
+ * Batch similarity search (optimized for many queries)
220
+ */
221
+ batchSimilarity(queries: Float32Array[], corpus: Float32Array[], k?: number): Array<Array<{
222
+ index: number;
223
+ score: number;
224
+ }>>;
225
+ private chunkArray;
226
+ }
227
+ export interface CachedMemoryEntry {
228
+ id: string;
229
+ embedding: Float32Array;
230
+ content: string;
231
+ score: number;
232
+ }
233
+ /**
234
+ * High-performance memory store with O(1) LRU caching.
235
+ */
236
+ export declare class OptimizedMemoryStore {
237
+ private cache;
238
+ private bufferPool;
239
+ private dimension;
240
+ constructor(options?: {
241
+ cacheSize?: number;
242
+ dimension?: number;
243
+ });
244
+ /**
245
+ * Store embedding - O(1)
246
+ */
247
+ store(id: string, embedding: Float32Array | number[], content: string): void;
248
+ /**
249
+ * Get by ID - O(1)
250
+ */
251
+ get(id: string): CachedMemoryEntry | undefined;
252
+ /**
253
+ * Search by similarity - O(n) but with optimized vector ops
254
+ */
255
+ search(query: Float32Array, k?: number): CachedMemoryEntry[];
256
+ /**
257
+ * Delete entry - O(1)
258
+ */
259
+ delete(id: string): boolean;
260
+ /**
261
+ * Get statistics
262
+ */
263
+ getStats(): {
264
+ cache: ReturnType<LRUCache<string, CachedMemoryEntry>['getStats']>;
265
+ buffers: ReturnType<Float32BufferPool['getStats']>;
266
+ };
267
+ }
268
+ declare const _default: {
269
+ LRUCache: typeof LRUCache;
270
+ Float32BufferPool: typeof Float32BufferPool;
271
+ TensorBufferManager: typeof TensorBufferManager;
272
+ VectorOps: {
273
+ /**
274
+ * Dot product with 8x unrolling
275
+ */
276
+ dot(a: Float32Array, b: Float32Array): number;
277
+ /**
278
+ * Squared L2 norm with 8x unrolling
279
+ */
280
+ normSq(a: Float32Array): number;
281
+ /**
282
+ * L2 norm
283
+ */
284
+ norm(a: Float32Array): number;
285
+ /**
286
+ * Cosine similarity with 8x unrolling
287
+ */
288
+ cosine(a: Float32Array, b: Float32Array): number;
289
+ /**
290
+ * Euclidean distance squared with 8x unrolling
291
+ */
292
+ distanceSq(a: Float32Array, b: Float32Array): number;
293
+ /**
294
+ * Euclidean distance
295
+ */
296
+ distance(a: Float32Array, b: Float32Array): number;
297
+ /**
298
+ * Add vectors: out = a + b (with 8x unrolling)
299
+ */
300
+ add(a: Float32Array, b: Float32Array, out: Float32Array): Float32Array;
301
+ /**
302
+ * Subtract vectors: out = a - b (with 8x unrolling)
303
+ */
304
+ sub(a: Float32Array, b: Float32Array, out: Float32Array): Float32Array;
305
+ /**
306
+ * Scale vector: out = a * scalar (with 8x unrolling)
307
+ */
308
+ scale(a: Float32Array, scalar: number, out: Float32Array): Float32Array;
309
+ /**
310
+ * Normalize vector in-place
311
+ */
312
+ normalize(a: Float32Array): Float32Array;
313
+ /**
314
+ * Mean of multiple vectors (with buffer reuse)
315
+ */
316
+ mean(vectors: Float32Array[], out: Float32Array): Float32Array;
317
+ };
318
+ ParallelBatchProcessor: typeof ParallelBatchProcessor;
319
+ OptimizedMemoryStore: typeof OptimizedMemoryStore;
320
+ PERF_CONSTANTS: {
321
+ readonly DEFAULT_CACHE_SIZE: 1000;
322
+ readonly DEFAULT_BUFFER_POOL_SIZE: 64;
323
+ readonly DEFAULT_BATCH_SIZE: 32;
324
+ readonly MIN_PARALLEL_BATCH_SIZE: 8;
325
+ readonly UNROLL_THRESHOLD: 32;
326
+ };
327
+ };
328
+ export default _default;
329
+ //# sourceMappingURL=neural-perf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neural-perf.d.ts","sourceRoot":"","sources":["../../src/core/neural-perf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAaX;;;GAGG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAoC;IAC/C,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,C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