agentdb 1.0.9 → 1.0.11

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/bin/agentdb.js CHANGED
@@ -402,65 +402,65 @@ function initDatabase(path) {
402
402
  }
403
403
  }
404
404
 
405
- function runBenchmark() {
406
- console.log('šŸ“Š Running AgentDB Performance Benchmarks...');
407
- console.log('');
408
- console.log('This will test:');
409
- console.log(' - Native & WASM backend performance');
410
- console.log(' - Insert operations (single & batch)');
411
- console.log(' - Search operations (various metrics)');
412
- console.log(' - Memory usage');
413
- console.log(' - Backend comparison');
414
- console.log('');
415
-
405
+ async function runBenchmark(...args) {
416
406
  try {
417
- // Try to run compiled benchmark first
418
- const benchmarkPath = require.resolve('../dist/benchmarks/comprehensive-performance.bench.js');
419
- const { PerformanceBenchmark } = require(benchmarkPath);
420
-
421
- const benchmark = new PerformanceBenchmark();
422
- benchmark.runAll()
423
- .then(() => {
424
- console.log('\nāœ… All benchmarks completed successfully');
425
- process.exit(0);
426
- })
427
- .catch((error) => {
428
- console.error('\nāŒ Benchmark failed:', error);
429
- process.exit(1);
430
- });
431
- } catch (error) {
432
- // If compiled version doesn't exist, try TypeScript version with ts-node
433
- try {
434
- console.error('āš ļø Compiled benchmarks not found, trying TypeScript version...');
435
- console.error('');
436
-
437
- const { spawn } = require('child_process');
438
- const benchmarkProcess = spawn('npx', ['ts-node', 'benchmarks/comprehensive-performance.bench.ts'], {
439
- stdio: 'inherit',
440
- cwd: require('path').resolve(__dirname, '..')
441
- });
442
-
443
- benchmarkProcess.on('close', (code) => {
444
- process.exit(code);
445
- });
446
- } catch (tsError) {
447
- console.error('āŒ Benchmarks not available in npm package');
448
- console.error('');
449
- console.error('To run benchmarks, clone the source repository:');
450
- console.error('');
451
- console.error(' git clone https://github.com/ruvnet/agentic-flow.git');
452
- console.error(' cd agentic-flow/packages/agentdb');
453
- console.error(' npm install');
454
- console.error(' npm run bench:comprehensive');
455
- console.error('');
456
- console.error('Or create a custom benchmark script:');
457
- console.error('');
458
- console.error(' const { SQLiteVectorDB } = require("agentdb");');
459
- console.error(' const db = new SQLiteVectorDB({ memoryMode: true });');
460
- console.error(' // Add your benchmark code here');
461
- console.error('');
462
- process.exit(1);
407
+ // Convert arguments to array
408
+ const argArray = Array.isArray(args[0]) ? args[0] : Array.from(args);
409
+
410
+ // Parse arguments
411
+ const options = {
412
+ quick: argArray.includes('--quick') || argArray.includes('-q'),
413
+ vectors: null
414
+ };
415
+
416
+ // Parse custom vector count
417
+ const vectorsIndex = argArray.findIndex(arg => arg === '--vectors' || arg === '-v');
418
+ if (vectorsIndex !== -1 && argArray[vectorsIndex + 1]) {
419
+ options.vectors = parseInt(argArray[vectorsIndex + 1], 10);
420
+ }
421
+
422
+ // Show help if requested
423
+ if (argArray.includes('--help') || argArray.includes('-h')) {
424
+ console.log('');
425
+ console.log('AgentDB Benchmark');
426
+ console.log('');
427
+ console.log('USAGE');
428
+ console.log(' npx agentdb benchmark [options]');
429
+ console.log('');
430
+ console.log('OPTIONS');
431
+ console.log(' --quick, -q Run quick benchmark (500/1000 vectors)');
432
+ console.log(' --vectors, -v <n> Custom batch size (default: 5000, quick: 1000)');
433
+ console.log(' --help, -h Show this help');
434
+ console.log('');
435
+ console.log('EXAMPLES');
436
+ console.log(' npx agentdb benchmark # Standard benchmark (5K vectors)');
437
+ console.log(' npx agentdb benchmark --quick # Quick benchmark (1K vectors)');
438
+ console.log(' npx agentdb benchmark -v 10000 # Custom 10K vectors');
439
+ console.log('');
440
+ console.log('For comprehensive benchmarks with WASM comparison:');
441
+ console.log(' git clone https://github.com/ruvnet/agentic-flow.git');
442
+ console.log(' cd agentic-flow/packages/agentdb');
443
+ console.log(' npm install && npm run bench:comprehensive');
444
+ console.log('');
445
+ return;
463
446
  }
447
+
448
+ // Run the included benchmark
449
+ const benchmarkPath = require.resolve('./benchmark.js');
450
+ const { runBenchmark } = require(benchmarkPath);
451
+ await runBenchmark(options);
452
+ } catch (error) {
453
+ console.error('');
454
+ console.error('āŒ Benchmark failed:', error.message);
455
+ console.error('');
456
+ console.error('For comprehensive benchmarks, clone the source repository:');
457
+ console.error('');
458
+ console.error(' git clone https://github.com/ruvnet/agentic-flow.git');
459
+ console.error(' cd agentic-flow/packages/agentdb');
460
+ console.error(' npm install');
461
+ console.error(' npm run bench:comprehensive');
462
+ console.error('');
463
+ process.exit(1);
464
464
  }
465
465
  }
466
466
 
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * AgentDB Quick Benchmark
4
+ * Simple performance test that works with the published npm package
5
+ */
6
+
7
+ const { performance } = require('perf_hooks');
8
+
9
+ /**
10
+ * Format throughput for display
11
+ */
12
+ function formatThroughput(opsPerSec) {
13
+ if (opsPerSec >= 1000000) {
14
+ return `${(opsPerSec / 1000000).toFixed(2)}M/sec`;
15
+ } else if (opsPerSec >= 1000) {
16
+ return `${(opsPerSec / 1000).toFixed(2)}K/sec`;
17
+ } else {
18
+ return `${opsPerSec.toFixed(2)}/sec`;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Generate random vectors for testing
24
+ */
25
+ function generateVectors(count, dimensions = 128) {
26
+ const vectors = [];
27
+ for (let i = 0; i < count; i++) {
28
+ vectors.push({
29
+ id: `vec-${i}`,
30
+ embedding: Array.from({ length: dimensions }, () => Math.random()),
31
+ metadata: {
32
+ index: i,
33
+ category: `cat-${i % 10}`,
34
+ timestamp: Date.now()
35
+ }
36
+ });
37
+ }
38
+ return vectors;
39
+ }
40
+
41
+ /**
42
+ * Run benchmark suite
43
+ */
44
+ async function runBenchmark(options = {}) {
45
+ const { quick = false, vectors = null } = options;
46
+
47
+ // Determine test sizes based on mode
48
+ const sizes = quick ? {
49
+ single: 300,
50
+ batch: 500,
51
+ queries: 10
52
+ } : {
53
+ single: 1000,
54
+ batch: vectors || 5000,
55
+ queries: 50
56
+ };
57
+
58
+ console.log('šŸš€ AgentDB Performance Benchmark\n');
59
+ console.log(`Mode: ${quick ? 'Quick' : 'Standard'}`);
60
+ console.log('Testing Native SQLite backend with vector operations...\n');
61
+
62
+ try {
63
+ const { SQLiteVectorDB } = require('../dist/index.js');
64
+
65
+ // Test 1: Database Initialization
66
+ console.log('šŸ“Š Test 1: Database Initialization');
67
+ const initStart = performance.now();
68
+ const db = new SQLiteVectorDB({ memoryMode: true });
69
+ const initDuration = performance.now() - initStart;
70
+ console.log(` āœ… Initialized in ${initDuration.toFixed(2)}ms\n`);
71
+
72
+ // Test 2: Single Insert Performance
73
+ console.log(`šŸ“Š Test 2: Single Insert (${sizes.single.toLocaleString()} vectors)`);
74
+ const singleVectors = generateVectors(sizes.single, 128);
75
+ const singleStart = performance.now();
76
+ for (const vector of singleVectors) {
77
+ db.insert(vector);
78
+ }
79
+ const singleDuration = performance.now() - singleStart;
80
+ const singleOps = (sizes.single / singleDuration) * 1000;
81
+ console.log(` āœ… Duration: ${singleDuration.toFixed(2)}ms`);
82
+ console.log(` āœ… Throughput: ${formatThroughput(singleOps)}\n`);
83
+
84
+ // Close and recreate database for next test
85
+ db.close();
86
+ const db2 = new SQLiteVectorDB({ memoryMode: true });
87
+
88
+ // Test 3: Batch Insert Performance
89
+ console.log(`šŸ“Š Test 3: Batch Insert (${sizes.batch.toLocaleString()} vectors)`);
90
+ const batchVectors = generateVectors(sizes.batch, 128);
91
+ const batchStart = performance.now();
92
+ db2.insertBatch(batchVectors);
93
+ const batchDuration = performance.now() - batchStart;
94
+ const batchOps = (sizes.batch / batchDuration) * 1000;
95
+ console.log(` āœ… Duration: ${batchDuration.toFixed(2)}ms`);
96
+ console.log(` āœ… Throughput: ${formatThroughput(batchOps)}\n`);
97
+
98
+ // Test 4: Search Performance
99
+ console.log(`šŸ“Š Test 4: Vector Search (${sizes.queries} queries on ${sizes.batch.toLocaleString()} vectors)`);
100
+ const queryVector = Array.from({ length: 128 }, () => Math.random());
101
+ const searchStart = performance.now();
102
+ for (let i = 0; i < sizes.queries; i++) {
103
+ db2.search(queryVector, 10, 'cosine');
104
+ }
105
+ const searchDuration = performance.now() - searchStart;
106
+ const avgSearchLatency = searchDuration / sizes.queries;
107
+ console.log(` āœ… Total: ${searchDuration.toFixed(2)}ms`);
108
+ console.log(` āœ… Average: ${avgSearchLatency.toFixed(2)}ms per query\n`);
109
+
110
+ // Test 5: Different Similarity Metrics
111
+ console.log(`šŸ“Š Test 5: Similarity Metrics Comparison (${sizes.batch.toLocaleString()} vectors)`);
112
+ const metrics = ['cosine', 'euclidean', 'dot'];
113
+ for (const metric of metrics) {
114
+ const metricStart = performance.now();
115
+ for (let i = 0; i < sizes.queries; i++) {
116
+ db2.search(queryVector, 10, metric);
117
+ }
118
+ const metricDuration = performance.now() - metricStart;
119
+ console.log(` āœ… ${metric}: ${(metricDuration / sizes.queries).toFixed(2)}ms per query`);
120
+ }
121
+
122
+ // Test 6: Database Stats
123
+ console.log('\nšŸ“Š Test 6: Database Statistics');
124
+ const stats = db2.stats();
125
+ console.log(` āœ… Total Vectors: ${stats.count.toLocaleString()}`);
126
+ console.log(` āœ… DB Size: ${(stats.size / 1024 / 1024).toFixed(2)} MB`);
127
+ console.log(` āœ… Size per 1K vectors: ${((stats.size / stats.count) * 1000 / 1024 / 1024).toFixed(3)} MB\n`);
128
+
129
+ db2.close();
130
+
131
+ // Print Summary
132
+ console.log('\n\n═══════════════════════════════════════════════════════════');
133
+ console.log('šŸ“ˆ BENCHMARK SUMMARY');
134
+ console.log('═══════════════════════════════════════════════════════════\n');
135
+
136
+ console.log('Insert Performance:');
137
+ console.log(` - Single Insert: ${formatThroughput(singleOps)}`);
138
+ console.log(` - Batch ${sizes.batch.toLocaleString()}: ${formatThroughput(batchOps)}`);
139
+
140
+ console.log('\nSearch Performance:');
141
+ console.log(` - ${sizes.batch.toLocaleString()} vectors: ${avgSearchLatency.toFixed(2)}ms/query`);
142
+
143
+ console.log('\nMemory Efficiency:');
144
+ console.log(` - Size per 1K vectors: ${((stats.size / stats.count) * 1000 / 1024 / 1024).toFixed(3)} MB`);
145
+
146
+ console.log('\n═══════════════════════════════════════════════════════════\n');
147
+ console.log('āœ… Benchmark completed successfully!\n');
148
+
149
+ process.exit(0);
150
+ } catch (error) {
151
+ console.error('\nāŒ Benchmark failed:', error.message);
152
+ console.error('\nStack trace:', error.stack);
153
+ process.exit(1);
154
+ }
155
+ }
156
+
157
+ // Run if executed directly
158
+ if (require.main === module) {
159
+ runBenchmark();
160
+ }
161
+
162
+ module.exports = { runBenchmark };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentdb",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Ultra-fast agent memory and vector database with ReasoningBank for AI agents. Built on SQLite with QUIC sync. From ruv.io - Advanced AI Infrastructure.",
5
5
  "keywords": [
6
6
  "agent",