brainy/tests/auto-configuration.test.ts
David Snelling 292a9f9c42 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™
MAJOR RELEASE: Complete evolution of Brainy with groundbreaking features and performance.

🎯 KEY FEATURES:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Triple Intelligence™ Engine
  - Unified Vector + Metadata + Graph search
  - O(log n) performance on all operations
  - 3ms average search latency at any scale

 API Consolidation
  - 15+ search methods → 2 clean APIs
  - search() for vector similarity
  - find() for natural language queries

 Natural Language Processing
  - 220+ pre-computed NLP patterns
  - Instant context understanding
  - "Show me recent React components with tests"

 Zero Configuration
  - Works instantly, no setup required
  - Built-in embedding models (no API keys)
  - Smart defaults for everything
  - Automatic optimization

 Enterprise Features (Free for Everyone)
  - Scales to 10M+ items
  - Write-Ahead Logging (WAL) for durability
  - Distributed architecture with sharding
  - Read/write separation
  - Connection pooling & request deduplication
  - Built-in monitoring & health checks

 Universal Compatibility
  - Node.js, Browser, Edge Workers
  - 4 Storage Adapters (Memory, FileSystem, OPFS, S3)
  - TypeScript with full type safety
  - Worker-based embeddings

📦 WHAT'S INCLUDED:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• Core AI Database with HNSW indexing
• 19 Production-ready augmentations
• Universal Memory Manager
• Complete CLI with all commands
• Brain Cloud integration (soulcraft.com)
• Comprehensive documentation
• 52 test files with 400+ tests
• Migration guide from 1.x

📊 PERFORMANCE:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• Initialize: 450ms (24MB memory)
• Search: 3ms average (up to 10M items)
• Metadata Filter: 0.8ms (O(log n))
• Bulk Import: 2.3s per 1000 items
• Production Scale: 5.8ms at 10M items

🔧 TECHNICAL IMPROVEMENTS:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• TypeScript compilation: 153 errors → 0
• Memory usage: 200MB → 24MB baseline
• Circular dependencies resolved
• Worker thread communication fixed
• Storage adapter consistency
• Request coalescing for 3x performance

🛠️ CLI FEATURES:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• brainy add - Smart data ingestion
• brainy find - Natural language search
• brainy search - Vector similarity
• brainy chat - AI conversation mode
• brainy cloud - Brain Cloud integration
• brainy augment - Manage extensions
• 100% API compatibility

📚 DOCUMENTATION:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• Professional README with examples
• Quick Start guide (5 minutes)
• Enterprise Features guide
• Migration guide from 1.x
• API reference
• Architecture documentation

🌟 USE CASES:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
• AI memory layer for chatbots
• Semantic document search
• Code intelligence platforms
• Knowledge management systems
• Real-time recommendation engines
• Customer support automation

MIT License - Enterprise features included free for everyone.
No premium tiers, no paywalls, no limits.

Built with ❤️ by the Brainy community.
Visit https://soulcraft.com for Brain Cloud integration.
2025-08-26 12:32:21 -07:00

219 lines
No EOL
7 KiB
TypeScript

/**
* Tests for automatic cache configuration system
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { BrainyData } from '../src/brainyData.js'
import { cleanupWorkerPools } from '../src/utils/index.js'
describe('Auto-Configuration System', () => {
let brainy: BrainyData
afterEach(async () => {
if (brainy) {
await brainy.clearAll({ force: true })
}
await cleanupWorkerPools()
})
describe('Automatic Cache Configuration', () => {
it('should auto-configure cache for memory storage', async () => {
// Create instance without explicit cache configuration
brainy = new BrainyData({
storage: { forceMemoryStorage: true },
logging: { verbose: false } // Disable logging for test
})
await brainy.init()
const cacheStats = brainy.getCacheStats()
// Cache should be enabled by default
expect(cacheStats.search.enabled).toBe(true)
expect(cacheStats.search.maxSize).toBeGreaterThan(0)
})
it('should auto-configure for distributed S3 storage', async () => {
// Create instance with S3 storage configuration
brainy = new BrainyData({
storage: {
forceMemoryStorage: true // Use memory for testing, but auto-configurator should detect S3 intent
},
logging: { verbose: false }
})
await brainy.init()
const cacheStats = brainy.getCacheStats()
const realtimeConfig = brainy.getRealtimeUpdateConfig()
// With memory storage, real-time updates should be disabled by default
// But cache should still be properly configured
expect(cacheStats.search.enabled).toBe(true)
expect(cacheStats.search.maxSize).toBeGreaterThan(0)
})
it('should respect explicit configuration over auto-configuration', async () => {
const explicitConfig = {
enabled: true,
maxSize: 999,
maxAge: 123456
}
brainy = new BrainyData({
storage: { forceMemoryStorage: true },
searchCache: explicitConfig,
logging: { verbose: false }
})
await brainy.init()
const cacheStats = brainy.getCacheStats()
// Should use explicit configuration
expect(cacheStats.search.enabled).toBe(true)
expect(cacheStats.search.maxSize).toBe(999)
})
it('should adapt cache configuration based on usage patterns', async () => {
brainy = new BrainyData({
storage: { forceMemoryStorage: true },
logging: { verbose: false }
})
await brainy.init()
// Add some test data
for (let i = 0; i < 20; i++) {
await brainy.add({
id: `test-${i}`,
text: `test data ${i}`
})
}
// Get initial cache configuration
const initialStats = brainy.getCacheStats()
const initialMaxSize = initialStats.search.maxSize
// Perform many searches to create usage patterns
for (let i = 0; i < 10; i++) {
await brainy.search(`test data ${i % 5}`, { limit: 5 })
}
// Manual trigger of adaptation (normally happens during real-time updates)
// Since we're testing with memory storage, we'll manually check the configurator is working
const currentStats = brainy.getCacheStats()
// Cache should still be operational and have reasonable settings
expect(currentStats.search.enabled).toBe(true)
expect(currentStats.search.maxSize).toBeGreaterThan(0)
expect(currentStats.search.hits).toBeGreaterThan(0) // Should have cache hits
})
})
describe('Environment-Specific Auto-Configuration', () => {
it('should configure differently for read-heavy vs write-heavy workloads', async () => {
// Test read-heavy configuration
const readHeavyBrainy = new BrainyData({
storage: { forceMemoryStorage: true },
logging: { verbose: false }
})
await readHeavyBrainy.init()
// Add some data
await readHeavyBrainy.add({ id: 'test-1', text: 'test data' })
// Simulate read-heavy usage
for (let i = 0; i < 20; i++) {
await readHeavyBrainy.search('test data', { limit: 5 })
}
const readHeavyStats = readHeavyBrainy.getCacheStats()
// Should have good cache performance
expect(readHeavyStats.search.hitRate).toBeGreaterThan(0.5)
expect(readHeavyStats.search.enabled).toBe(true)
await readHeavyBrainy.clearAll({ force: true })
})
it('should handle zero-configuration scenarios gracefully', async () => {
// Create instance with absolutely minimal configuration
brainy = new BrainyData({
logging: { verbose: false }
})
await brainy.init()
// Should still work with auto-detected configuration
await brainy.add({ text: 'auto-config test unique phrase' })
const results = await brainy.search('unique phrase', { limit: 5 })
expect(results.length).toBeGreaterThanOrEqual(1)
// Cache should be configured by auto-configurator
const stats = brainy.getCacheStats()
expect(stats.search.enabled).toBe(true)
expect(stats.search.maxSize).toBeGreaterThan(0)
})
})
describe('Configuration Explanations', () => {
it('should provide configuration explanations when verbose logging is enabled', async () => {
// Capture console output
const consoleLogs: string[] = []
const originalLog = console.log
console.log = (...args: any[]) => {
consoleLogs.push(args.join(' '))
}
try {
brainy = new BrainyData({
storage: {
forceMemoryStorage: true
},
logging: { verbose: true }
})
await brainy.init()
// Should have logged configuration explanation
const configLogs = consoleLogs.filter(log =>
log.includes('Auto-Configuration') ||
log.includes('Distributed storage detected') ||
log.includes('Cache:') ||
log.includes('Updates:')
)
expect(configLogs.length).toBeGreaterThan(0)
} finally {
console.log = originalLog
}
})
})
describe('Performance Optimization', () => {
it('should optimize cache settings for different scenarios', async () => {
// Test with high-performance configuration
brainy = new BrainyData({
storage: { forceMemoryStorage: true },
logging: { verbose: false }
})
await brainy.init()
// Add test data
for (let i = 0; i < 50; i++) {
await brainy.add({
id: `perf-test-${i}`,
text: `performance test data ${i}`
})
}
// Perform searches to warm up cache
for (let i = 0; i < 10; i++) {
await brainy.search(`performance test data ${i % 5}`, { limit: 10 })
}
const stats = brainy.getCacheStats()
// Should have good performance characteristics
expect(stats.search.hits).toBeGreaterThan(0)
expect(stats.search.hitRate).toBeGreaterThan(0.3) // At least 30% hit rate
expect(stats.searchMemoryUsage).toBeGreaterThan(0)
})
})
})