ruvector 0.1.31 → 0.1.32
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.json +2 -2
- package/ruvector-0.1.1.tgz +0 -0
- package/src/core/agentdb-fast.ts +0 -386
- package/src/core/attention-fallbacks.ts +0 -512
- package/src/core/gnn-wrapper.ts +0 -251
- package/src/core/index.ts +0 -17
- package/src/core/sona-wrapper.ts +0 -367
- package/src/index.ts +0 -80
- package/src/services/embedding-service.ts +0 -386
- package/src/services/index.ts +0 -6
- package/src/types.ts +0 -161
- package/test/benchmark-gnn.js +0 -373
- package/test/integration.js +0 -155
- package/test/mock-implementation.js +0 -151
- package/test/standalone-test.js +0 -214
- package/tsconfig.json +0 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"startTime": 1765245239532,
|
|
3
|
+
"sessionId": "session-1765245239532",
|
|
4
|
+
"lastActivity": 1765245239532,
|
|
5
|
+
"sessionDuration": 0,
|
|
6
|
+
"totalTasks": 1,
|
|
7
|
+
"successfulTasks": 1,
|
|
8
|
+
"failedTasks": 0,
|
|
9
|
+
"totalAgents": 0,
|
|
10
|
+
"activeAgents": 0,
|
|
11
|
+
"neuralEvents": 0,
|
|
12
|
+
"memoryMode": {
|
|
13
|
+
"reasoningbankOperations": 0,
|
|
14
|
+
"basicOperations": 0,
|
|
15
|
+
"autoModeSelections": 0,
|
|
16
|
+
"modeOverrides": 0,
|
|
17
|
+
"currentMode": "auto"
|
|
18
|
+
},
|
|
19
|
+
"operations": {
|
|
20
|
+
"store": {
|
|
21
|
+
"count": 0,
|
|
22
|
+
"totalDuration": 0,
|
|
23
|
+
"errors": 0
|
|
24
|
+
},
|
|
25
|
+
"retrieve": {
|
|
26
|
+
"count": 0,
|
|
27
|
+
"totalDuration": 0,
|
|
28
|
+
"errors": 0
|
|
29
|
+
},
|
|
30
|
+
"query": {
|
|
31
|
+
"count": 0,
|
|
32
|
+
"totalDuration": 0,
|
|
33
|
+
"errors": 0
|
|
34
|
+
},
|
|
35
|
+
"list": {
|
|
36
|
+
"count": 0,
|
|
37
|
+
"totalDuration": 0,
|
|
38
|
+
"errors": 0
|
|
39
|
+
},
|
|
40
|
+
"delete": {
|
|
41
|
+
"count": 0,
|
|
42
|
+
"totalDuration": 0,
|
|
43
|
+
"errors": 0
|
|
44
|
+
},
|
|
45
|
+
"search": {
|
|
46
|
+
"count": 0,
|
|
47
|
+
"totalDuration": 0,
|
|
48
|
+
"errors": 0
|
|
49
|
+
},
|
|
50
|
+
"init": {
|
|
51
|
+
"count": 0,
|
|
52
|
+
"totalDuration": 0,
|
|
53
|
+
"errors": 0
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"performance": {
|
|
57
|
+
"avgOperationDuration": 0,
|
|
58
|
+
"minOperationDuration": null,
|
|
59
|
+
"maxOperationDuration": null,
|
|
60
|
+
"slowOperations": 0,
|
|
61
|
+
"fastOperations": 0,
|
|
62
|
+
"totalOperationTime": 0
|
|
63
|
+
},
|
|
64
|
+
"storage": {
|
|
65
|
+
"totalEntries": 0,
|
|
66
|
+
"reasoningbankEntries": 0,
|
|
67
|
+
"basicEntries": 0,
|
|
68
|
+
"databaseSize": 0,
|
|
69
|
+
"lastBackup": null,
|
|
70
|
+
"growthRate": 0
|
|
71
|
+
},
|
|
72
|
+
"errors": {
|
|
73
|
+
"total": 0,
|
|
74
|
+
"byType": {},
|
|
75
|
+
"byOperation": {},
|
|
76
|
+
"recent": []
|
|
77
|
+
},
|
|
78
|
+
"reasoningbank": {
|
|
79
|
+
"semanticSearches": 0,
|
|
80
|
+
"sqlFallbacks": 0,
|
|
81
|
+
"embeddingGenerated": 0,
|
|
82
|
+
"consolidations": 0,
|
|
83
|
+
"avgQueryTime": 0,
|
|
84
|
+
"cacheHits": 0,
|
|
85
|
+
"cacheMisses": 0
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruvector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32",
|
|
4
4
|
"description": "High-performance vector database for Node.js with automatic native/WASM fallback",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"directory": "npm/packages/ruvector"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@ruvector/core": "^0.1.
|
|
55
|
+
"@ruvector/core": "^0.1.25",
|
|
56
56
|
"@ruvector/attention": "^0.1.3",
|
|
57
57
|
"@ruvector/gnn": "^0.1.22",
|
|
58
58
|
"@ruvector/sona": "^0.1.4",
|
package/ruvector-0.1.1.tgz
DELETED
|
Binary file
|
package/src/core/agentdb-fast.ts
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentDB Fast - High-performance in-process alternative to AgentDB CLI
|
|
3
|
-
*
|
|
4
|
-
* The AgentDB CLI has ~2.3s startup overhead due to npx initialization.
|
|
5
|
-
* This module provides 50-200x faster operations by using in-process calls.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - In-memory episode storage with LRU eviction
|
|
9
|
-
* - Vector similarity search using @ruvector/core
|
|
10
|
-
* - Compatible API with AgentDB's episode/trajectory interfaces
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type {
|
|
14
|
-
VectorEntry,
|
|
15
|
-
SearchResult,
|
|
16
|
-
SearchQuery,
|
|
17
|
-
} from '../types';
|
|
18
|
-
|
|
19
|
-
// Lazy load ruvector core
|
|
20
|
-
let coreModule: any = null;
|
|
21
|
-
|
|
22
|
-
function getCoreModule() {
|
|
23
|
-
if (coreModule) return coreModule;
|
|
24
|
-
try {
|
|
25
|
-
coreModule = require('@ruvector/core');
|
|
26
|
-
return coreModule;
|
|
27
|
-
} catch {
|
|
28
|
-
// Fallback to ruvector if core not available
|
|
29
|
-
try {
|
|
30
|
-
coreModule = require('ruvector');
|
|
31
|
-
return coreModule;
|
|
32
|
-
} catch (e: any) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Neither @ruvector/core nor ruvector is available: ${e.message}`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Episode entry for trajectory storage
|
|
42
|
-
*/
|
|
43
|
-
export interface Episode {
|
|
44
|
-
id: string;
|
|
45
|
-
state: number[];
|
|
46
|
-
action: string | number;
|
|
47
|
-
reward: number;
|
|
48
|
-
nextState: number[];
|
|
49
|
-
done: boolean;
|
|
50
|
-
metadata?: Record<string, any>;
|
|
51
|
-
timestamp?: number;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Trajectory (sequence of episodes)
|
|
56
|
-
*/
|
|
57
|
-
export interface Trajectory {
|
|
58
|
-
id: string;
|
|
59
|
-
episodes: Episode[];
|
|
60
|
-
totalReward: number;
|
|
61
|
-
metadata?: Record<string, any>;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Search result for episode queries
|
|
66
|
-
*/
|
|
67
|
-
export interface EpisodeSearchResult {
|
|
68
|
-
episode: Episode;
|
|
69
|
-
similarity: number;
|
|
70
|
-
trajectoryId?: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Fast in-memory AgentDB implementation
|
|
75
|
-
*/
|
|
76
|
-
export class FastAgentDB {
|
|
77
|
-
private episodes: Map<string, Episode> = new Map();
|
|
78
|
-
private trajectories: Map<string, Trajectory> = new Map();
|
|
79
|
-
private vectorDb: any = null;
|
|
80
|
-
private dimensions: number;
|
|
81
|
-
private maxEpisodes: number;
|
|
82
|
-
private episodeOrder: string[] = []; // For LRU eviction
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Create a new FastAgentDB instance
|
|
86
|
-
*
|
|
87
|
-
* @param dimensions - Vector dimensions for state embeddings
|
|
88
|
-
* @param maxEpisodes - Maximum episodes to store (LRU eviction)
|
|
89
|
-
*/
|
|
90
|
-
constructor(dimensions: number = 128, maxEpisodes: number = 100000) {
|
|
91
|
-
this.dimensions = dimensions;
|
|
92
|
-
this.maxEpisodes = maxEpisodes;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Initialize the vector database
|
|
97
|
-
*/
|
|
98
|
-
private async initVectorDb(): Promise<void> {
|
|
99
|
-
if (this.vectorDb) return;
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const core = getCoreModule();
|
|
103
|
-
this.vectorDb = new core.VectorDB({
|
|
104
|
-
dimensions: this.dimensions,
|
|
105
|
-
distanceMetric: 'Cosine',
|
|
106
|
-
});
|
|
107
|
-
} catch (e: any) {
|
|
108
|
-
// Vector DB not available, use fallback similarity
|
|
109
|
-
console.warn(`VectorDB not available, using fallback similarity: ${e.message}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Store an episode
|
|
115
|
-
*
|
|
116
|
-
* @param episode - Episode to store
|
|
117
|
-
* @returns Episode ID
|
|
118
|
-
*/
|
|
119
|
-
async storeEpisode(episode: Omit<Episode, 'id'> & { id?: string }): Promise<string> {
|
|
120
|
-
await this.initVectorDb();
|
|
121
|
-
|
|
122
|
-
const id = episode.id ?? this.generateId();
|
|
123
|
-
const fullEpisode: Episode = {
|
|
124
|
-
...episode,
|
|
125
|
-
id,
|
|
126
|
-
timestamp: episode.timestamp ?? Date.now(),
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// LRU eviction if needed
|
|
130
|
-
if (this.episodes.size >= this.maxEpisodes) {
|
|
131
|
-
const oldestId = this.episodeOrder.shift();
|
|
132
|
-
if (oldestId) {
|
|
133
|
-
this.episodes.delete(oldestId);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
this.episodes.set(id, fullEpisode);
|
|
138
|
-
this.episodeOrder.push(id);
|
|
139
|
-
|
|
140
|
-
// Index in vector DB if available
|
|
141
|
-
if (this.vectorDb && fullEpisode.state.length === this.dimensions) {
|
|
142
|
-
try {
|
|
143
|
-
await this.vectorDb.insert({
|
|
144
|
-
id,
|
|
145
|
-
vector: new Float32Array(fullEpisode.state),
|
|
146
|
-
});
|
|
147
|
-
} catch {
|
|
148
|
-
// Ignore indexing errors
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return id;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Store multiple episodes in batch
|
|
157
|
-
*/
|
|
158
|
-
async storeEpisodes(episodes: (Omit<Episode, 'id'> & { id?: string })[]): Promise<string[]> {
|
|
159
|
-
const ids: string[] = [];
|
|
160
|
-
for (const episode of episodes) {
|
|
161
|
-
const id = await this.storeEpisode(episode);
|
|
162
|
-
ids.push(id);
|
|
163
|
-
}
|
|
164
|
-
return ids;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Retrieve an episode by ID
|
|
169
|
-
*/
|
|
170
|
-
async getEpisode(id: string): Promise<Episode | null> {
|
|
171
|
-
const episode = this.episodes.get(id);
|
|
172
|
-
if (episode) {
|
|
173
|
-
// Update LRU order
|
|
174
|
-
const idx = this.episodeOrder.indexOf(id);
|
|
175
|
-
if (idx > -1) {
|
|
176
|
-
this.episodeOrder.splice(idx, 1);
|
|
177
|
-
this.episodeOrder.push(id);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return episode ?? null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Search for similar episodes by state
|
|
185
|
-
*
|
|
186
|
-
* @param queryState - State vector to search for
|
|
187
|
-
* @param k - Number of results to return
|
|
188
|
-
* @returns Similar episodes sorted by similarity
|
|
189
|
-
*/
|
|
190
|
-
async searchByState(
|
|
191
|
-
queryState: number[] | Float32Array,
|
|
192
|
-
k: number = 10
|
|
193
|
-
): Promise<EpisodeSearchResult[]> {
|
|
194
|
-
await this.initVectorDb();
|
|
195
|
-
|
|
196
|
-
const query = Array.isArray(queryState) ? queryState : Array.from(queryState);
|
|
197
|
-
|
|
198
|
-
// Use vector DB if available
|
|
199
|
-
if (this.vectorDb && query.length === this.dimensions) {
|
|
200
|
-
try {
|
|
201
|
-
const results: SearchResult[] = await this.vectorDb.search({
|
|
202
|
-
vector: new Float32Array(query),
|
|
203
|
-
k,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
return results
|
|
207
|
-
.map((r) => {
|
|
208
|
-
const episode = this.episodes.get(r.id);
|
|
209
|
-
if (!episode) return null;
|
|
210
|
-
return {
|
|
211
|
-
episode,
|
|
212
|
-
similarity: 1 - r.score, // Convert distance to similarity
|
|
213
|
-
};
|
|
214
|
-
})
|
|
215
|
-
.filter((r): r is EpisodeSearchResult => r !== null);
|
|
216
|
-
} catch {
|
|
217
|
-
// Fall through to fallback
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Fallback: brute-force cosine similarity
|
|
222
|
-
return this.fallbackSearch(query, k);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Fallback similarity search using brute-force cosine similarity
|
|
227
|
-
*/
|
|
228
|
-
private fallbackSearch(query: number[], k: number): EpisodeSearchResult[] {
|
|
229
|
-
const results: EpisodeSearchResult[] = [];
|
|
230
|
-
|
|
231
|
-
for (const episode of this.episodes.values()) {
|
|
232
|
-
if (episode.state.length !== query.length) continue;
|
|
233
|
-
|
|
234
|
-
const similarity = this.cosineSimilarity(query, episode.state);
|
|
235
|
-
results.push({ episode, similarity });
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return results
|
|
239
|
-
.sort((a, b) => b.similarity - a.similarity)
|
|
240
|
-
.slice(0, k);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Compute cosine similarity between two vectors
|
|
245
|
-
*/
|
|
246
|
-
private cosineSimilarity(a: number[], b: number[]): number {
|
|
247
|
-
let dotProduct = 0;
|
|
248
|
-
let normA = 0;
|
|
249
|
-
let normB = 0;
|
|
250
|
-
|
|
251
|
-
for (let i = 0; i < a.length; i++) {
|
|
252
|
-
dotProduct += a[i] * b[i];
|
|
253
|
-
normA += a[i] * a[i];
|
|
254
|
-
normB += b[i] * b[i];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const denom = Math.sqrt(normA) * Math.sqrt(normB);
|
|
258
|
-
return denom === 0 ? 0 : dotProduct / denom;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Store a trajectory (sequence of episodes)
|
|
263
|
-
*/
|
|
264
|
-
async storeTrajectory(
|
|
265
|
-
episodes: (Omit<Episode, 'id'> & { id?: string })[],
|
|
266
|
-
metadata?: Record<string, any>
|
|
267
|
-
): Promise<string> {
|
|
268
|
-
const trajectoryId = this.generateId();
|
|
269
|
-
const storedEpisodes: Episode[] = [];
|
|
270
|
-
let totalReward = 0;
|
|
271
|
-
|
|
272
|
-
for (const episode of episodes) {
|
|
273
|
-
const id = await this.storeEpisode(episode);
|
|
274
|
-
const stored = await this.getEpisode(id);
|
|
275
|
-
if (stored) {
|
|
276
|
-
storedEpisodes.push(stored);
|
|
277
|
-
totalReward += stored.reward;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const trajectory: Trajectory = {
|
|
282
|
-
id: trajectoryId,
|
|
283
|
-
episodes: storedEpisodes,
|
|
284
|
-
totalReward,
|
|
285
|
-
metadata,
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
this.trajectories.set(trajectoryId, trajectory);
|
|
289
|
-
return trajectoryId;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Get a trajectory by ID
|
|
294
|
-
*/
|
|
295
|
-
async getTrajectory(id: string): Promise<Trajectory | null> {
|
|
296
|
-
return this.trajectories.get(id) ?? null;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Get top trajectories by total reward
|
|
301
|
-
*/
|
|
302
|
-
async getTopTrajectories(k: number = 10): Promise<Trajectory[]> {
|
|
303
|
-
return Array.from(this.trajectories.values())
|
|
304
|
-
.sort((a, b) => b.totalReward - a.totalReward)
|
|
305
|
-
.slice(0, k);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Sample random episodes (for experience replay)
|
|
310
|
-
*/
|
|
311
|
-
async sampleEpisodes(n: number): Promise<Episode[]> {
|
|
312
|
-
const allEpisodes = Array.from(this.episodes.values());
|
|
313
|
-
const sampled: Episode[] = [];
|
|
314
|
-
|
|
315
|
-
for (let i = 0; i < Math.min(n, allEpisodes.length); i++) {
|
|
316
|
-
const idx = Math.floor(Math.random() * allEpisodes.length);
|
|
317
|
-
sampled.push(allEpisodes[idx]);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return sampled;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Get database statistics
|
|
325
|
-
*/
|
|
326
|
-
getStats(): {
|
|
327
|
-
episodeCount: number;
|
|
328
|
-
trajectoryCount: number;
|
|
329
|
-
dimensions: number;
|
|
330
|
-
maxEpisodes: number;
|
|
331
|
-
vectorDbAvailable: boolean;
|
|
332
|
-
} {
|
|
333
|
-
return {
|
|
334
|
-
episodeCount: this.episodes.size,
|
|
335
|
-
trajectoryCount: this.trajectories.size,
|
|
336
|
-
dimensions: this.dimensions,
|
|
337
|
-
maxEpisodes: this.maxEpisodes,
|
|
338
|
-
vectorDbAvailable: this.vectorDb !== null,
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Clear all data
|
|
344
|
-
*/
|
|
345
|
-
clear(): void {
|
|
346
|
-
this.episodes.clear();
|
|
347
|
-
this.trajectories.clear();
|
|
348
|
-
this.episodeOrder = [];
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Generate a unique ID
|
|
353
|
-
*/
|
|
354
|
-
private generateId(): string {
|
|
355
|
-
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Create a fast AgentDB instance
|
|
361
|
-
*/
|
|
362
|
-
export function createFastAgentDB(
|
|
363
|
-
dimensions: number = 128,
|
|
364
|
-
maxEpisodes: number = 100000
|
|
365
|
-
): FastAgentDB {
|
|
366
|
-
return new FastAgentDB(dimensions, maxEpisodes);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// Singleton instance for convenience
|
|
370
|
-
let defaultInstance: FastAgentDB | null = null;
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Get the default FastAgentDB instance
|
|
374
|
-
*/
|
|
375
|
-
export function getDefaultAgentDB(): FastAgentDB {
|
|
376
|
-
if (!defaultInstance) {
|
|
377
|
-
defaultInstance = new FastAgentDB();
|
|
378
|
-
}
|
|
379
|
-
return defaultInstance;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export default {
|
|
383
|
-
FastAgentDB,
|
|
384
|
-
createFastAgentDB,
|
|
385
|
-
getDefaultAgentDB,
|
|
386
|
-
};
|