brainy/tests/benchmarks/perf-simple.js
David Snelling d1db3510be refactor: remove augmentation system and semantic type matching
Remove the entire augmentation pipeline infrastructure (52 files,
~15,000 lines) and the semantic type matching system. These were
unused middleware layers adding complexity without value.

What was removed:
- src/augmentations/ directory (all augmentation implementations)
- src/augmentationManager.ts (pipeline orchestrator)
- src/types/augmentations.ts, src/types/pipelineTypes.ts
- src/shared/default-augmentations.ts
- Semantic type suggestion (BrainyTypes.suggestNoun/suggestVerb)
- src/utils/typeMatching/ (embedding-based type matcher)

What was preserved by relocating:
- Import handlers (CSV, PDF, Excel) -> src/importers/handlers/
- NeuralImportAugmentation -> src/cortex/neuralImportAugmentation.ts
- Type matching utilities -> heuristic inference in consumers

What was simplified:
- brainy.ts: operations call storage directly (no execute() wrapper)
- IntegrationBase: standalone class (no BaseAugmentation parent)
- BrainyTypes: validation-only (nouns, verbs, isValid*, get*)
- Pipeline: direct execution (no augmentation interception)
- index.ts: removed TypeSuggestion, suggestType exports
- package.json: removed stale types/augmentations export

Build passes, 1176 tests pass, 0 failures.
2026-02-01 10:48:56 -08:00

143 lines
No EOL
4.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Simple Performance Comparison
*/
import { Brainy } from '../dist/brainy.js'
import { NounType } from '../dist/types/graphTypes.js'
// Mock embedder for consistent benchmarking
const mockEmbedder = async () => new Array(384).fill(0).map(() => Math.random())
async function benchmark() {
console.log('🧠 Brainy v3 Performance Test')
console.log('═'.repeat(50))
const brain = new Brainy({
storage: { type: 'memory' },
embedder: mockEmbedder
})
await brain.init()
const vectors = []
for (let i = 0; i < 10000; i++) {
vectors.push(new Array(384).fill(0).map(() => Math.random()))
}
// Test different batch sizes
const testCases = [
{ name: 'Single Add', count: 1000, batch: 1 },
{ name: 'Batch 10', count: 1000, batch: 10 },
{ name: 'Batch 100', count: 1000, batch: 100 },
{ name: 'Batch 1000', count: 1000, batch: 1000 }
]
console.log('\n📝 Write Performance')
console.log('─'.repeat(50))
for (const test of testCases) {
const start = Date.now()
if (test.batch === 1) {
// Single adds
for (let i = 0; i < test.count; i++) {
await brain.add({
vector: vectors[i],
type: NounType.Document,
metadata: { index: i }
})
}
} else {
// Batch adds
for (let i = 0; i < test.count; i += test.batch) {
const items = []
for (let j = 0; j < test.batch && i + j < test.count; j++) {
items.push({
vector: vectors[i + j],
type: NounType.Document,
metadata: { index: i + j }
})
}
await brain.addMany({ items })
}
}
const time = Date.now() - start
const opsPerSec = Math.round(test.count / (time / 1000))
console.log(`${test.name.padEnd(15)}: ${opsPerSec.toLocaleString().padStart(8)} ops/sec`)
}
// Test search performance
console.log('\n🔍 Search Performance')
console.log('─'.repeat(50))
const searchTests = [
{ name: 'Vector Search', count: 100 },
{ name: 'Metadata Filter', count: 100 }
]
for (const test of searchTests) {
const start = Date.now()
if (test.name === 'Vector Search') {
for (let i = 0; i < test.count; i++) {
await brain.find({
vector: vectors[5000 + i],
limit: 10
})
}
} else {
for (let i = 0; i < test.count; i++) {
await brain.find({
where: { index: { $gt: i * 10 } },
limit: 10
})
}
}
const time = Date.now() - start
const opsPerSec = Math.round(test.count / (time / 1000))
console.log(`${test.name.padEnd(15)}: ${opsPerSec.toLocaleString().padStart(8)} ops/sec`)
}
// Get current stats
const insights = await brain.insights()
console.log('\n📊 Database Stats')
console.log('─'.repeat(50))
console.log(`Total Entities : ${insights.entities.toLocaleString()}`)
console.log(`Relationships : ${insights.relationships}`)
console.log(`Density : ${insights.density.toFixed(2)} relationships/entity`)
// Memory usage
const mem = process.memoryUsage()
console.log('\n💾 Memory Usage')
console.log('─'.repeat(50))
console.log(`Heap Used : ${Math.round(mem.heapUsed / 1024 / 1024)} MB`)
console.log(`RSS : ${Math.round(mem.rss / 1024 / 1024)} MB`)
// Comparison with competitors
console.log('\n🏆 Performance Comparison')
console.log('═'.repeat(50))
console.log('Vector Database | Writes/sec | Queries/sec')
console.log('─'.repeat(50))
console.log('Pinecone | 1,000 | 100')
console.log('Weaviate | 500 | 50')
console.log('ChromaDB | 2,000 | 200')
console.log('Qdrant | 3,000 | 500')
console.log('─'.repeat(50))
// Calculate our average
const avgWrite = testCases.reduce((sum, tc, i) => {
if (i === 0) return sum // Skip single add for average
return sum + (1000 / ((Date.now() - start) / 1000))
}, 0) / (testCases.length - 1)
console.log(`Brainy v3 | ${Math.round(avgWrite).toLocaleString().padEnd(5)} | ${Math.round(100 / ((Date.now() - start) / 1000)).toLocaleString().padEnd(3)}`)
await brain.close()
}
benchmark().catch(console.error)