brainy/test-with-8gb.js
David Snelling 4949b6a629 CHECKPOINT: Industry-standard 3-tier testing implemented
 MAJOR BREAKTHROUGH - Session 5 Success:
- Unit tests: 18/19 passing with mocked AI (<500MB RAM)
- Integration tests: Real AI models loading successfully
- Core features: Real embeddings, CRUD operations verified
- Architecture: All 11 augmentations, worker threads operational

📋 CRITICAL FINDINGS:
- Real AI models load and cache correctly
- 384D embeddings generate properly
- Core CRUD operations work with real transformers
- Memory management effective for production

⚠️ RELEASE BLOCKER IDENTIFIED:
- Search operations timeout in test environment
- Affects: search(), find(), clustering functionality
- Root cause: Likely worker communication during HNSW search
- Priority: MUST fix before 2.0.0 release

🎯 NEXT SESSION PRIORITIES:
1. Debug and fix search timeout issue
2. Verify search/find/clustering work in production
3. Final documentation cleanup
4. Release preparation

Confidence: 90% ready (pending search functionality verification)
2025-08-25 17:12:58 -07:00

136 lines
No EOL
5 KiB
JavaScript

#!/usr/bin/env node
/**
* Test Brainy with REAL search and embeddings
* Requires 6-8GB RAM (ONNX runtime requirement)
*/
import { BrainyData } from './dist/index.js'
import v8 from 'v8'
// Check if we have enough memory allocated
const maxHeap = v8.getHeapStatistics().heap_size_limit / (1024 * 1024 * 1024)
console.log(`🧠 Node.js heap limit: ${maxHeap.toFixed(1)}GB`)
if (maxHeap < 6) {
console.error('⚠️ WARNING: Less than 6GB heap allocated')
console.error('Please run with: NODE_OPTIONS="--max-old-space-size=8192" node test-with-8gb.js')
console.error('Or use: npm run test:memory')
}
console.log('\n🧪 Testing Brainy with REAL Search & Embeddings')
console.log('='.repeat(50))
async function testRealSearch() {
try {
const brain = new BrainyData({
storage: { forceMemoryStorage: true },
verbose: false
})
console.log('\n1. Initializing Brainy...')
await brain.init()
console.log('✅ Initialized successfully')
// Add test data
console.log('\n2. Adding test data...')
const items = [
{ name: 'JavaScript', type: 'programming language', year: 1995, paradigm: 'multi-paradigm' },
{ name: 'Python', type: 'programming language', year: 1991, paradigm: 'object-oriented' },
{ name: 'TypeScript', type: 'programming language', year: 2012, paradigm: 'typed' },
{ name: 'React', type: 'library', year: 2013, language: 'JavaScript' },
{ name: 'Vue', type: 'framework', year: 2014, language: 'JavaScript' },
{ name: 'Django', type: 'framework', year: 2005, language: 'Python' },
{ name: 'Node.js', type: 'runtime', year: 2009, language: 'JavaScript' }
]
const ids = []
for (const item of items) {
const id = await brain.addNoun(item)
ids.push(id)
console.log(` Added: ${item.name}`)
}
console.log(`✅ Added ${ids.length} items`)
// Test 1: Semantic search
console.log('\n3. Testing SEMANTIC SEARCH...')
console.log(' Searching for "web development"...')
const semanticResults = await brain.search('web development', 3)
console.log(` ✅ Found ${semanticResults.length} semantic matches`)
semanticResults.forEach(r => {
console.log(` - ${r.metadata?.name || r.id} (score: ${r.score?.toFixed(3)})`)
})
// Test 2: Natural language search
console.log('\n4. Testing NATURAL LANGUAGE...')
console.log(' Query: "JavaScript frameworks from recent years"')
const nlpResults = await brain.find('JavaScript frameworks from recent years')
console.log(` ✅ Found ${nlpResults.length} NLP matches`)
nlpResults.forEach(r => {
console.log(` - ${r.metadata?.name || r.id}`)
})
// Test 3: Triple Intelligence with Brain Patterns
console.log('\n5. Testing TRIPLE INTELLIGENCE with Brain Patterns...')
console.log(' Query: Similar to "React", year > 2010, type = framework')
const tripleResults = await brain.triple.search({
like: 'React',
where: {
year: { greaterThan: 2010 },
type: 'framework'
},
limit: 5
})
console.log(` ✅ Found ${tripleResults.length} triple matches`)
tripleResults.forEach(r => {
console.log(` - ${r.metadata?.name || r.id} (fusion score: ${r.fusionScore?.toFixed(3)})`)
})
// Test 4: Range queries with metadata
console.log('\n6. Testing RANGE QUERIES...')
console.log(' Query: Languages from 1990-2000')
const rangeResults = await brain.search('*', 10, {
metadata: {
year: { greaterThan: 1990, lessThan: 2000 },
type: 'programming language'
}
})
console.log(` ✅ Found ${rangeResults.length} range matches`)
rangeResults.forEach(r => {
console.log(` - ${r.metadata?.name} (${r.metadata?.year})`)
})
// Memory check
console.log('\n7. Memory Usage:')
const mem = process.memoryUsage()
console.log(` Heap Used: ${(mem.heapUsed / 1024 / 1024).toFixed(2)} MB`)
console.log(` Heap Total: ${(mem.heapTotal / 1024 / 1024).toFixed(2)} MB`)
console.log(` RSS: ${(mem.rss / 1024 / 1024).toFixed(2)} MB`)
// Success!
console.log('\n' + '='.repeat(50))
console.log('🎉 SUCCESS! All Brainy features working:')
console.log('✅ Semantic Search (embeddings)')
console.log('✅ Natural Language (NLP)')
console.log('✅ Triple Intelligence')
console.log('✅ Brain Patterns (range queries)')
console.log('✅ Zero Configuration')
console.log('\n📝 Note: Required ~4-6GB RAM for transformer model')
console.log('This is normal and expected for AI features.')
process.exit(0)
} catch (error) {
console.error('\n❌ Test failed:', error.message)
console.error(error.stack)
if (error.message.includes('heap') || error.message.includes('memory')) {
console.error('\n💡 TIP: Increase memory allocation:')
console.error('NODE_OPTIONS="--max-old-space-size=8192" node test-with-8gb.js')
}
process.exit(1)
}
}
// Run the test
testRealSearch()