refactor: simplify build system and improve model loading flexibility
- Remove Rollup bundling in favor of direct TypeScript compilation - Move from bundled models to dynamic model loading with configurable paths - Add Docker deployment examples and documentation - Implement robust model loader with fallback mechanisms - Update storage adapters for better cross-environment compatibility - Add comprehensive tests for model loading and package installation - Simplify package.json scripts and remove complex build configurations - Clean up deprecated demo files and old bundling scripts BREAKING CHANGE: Models are no longer bundled with the package. They are now loaded dynamically from CDN or custom paths.
This commit is contained in:
parent
89413ebec2
commit
52a43d51d4
51 changed files with 4835 additions and 8007 deletions
86
examples/docker-deployment/example-app.js
Normal file
86
examples/docker-deployment/example-app.js
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Example Brainy application for Docker deployment
|
||||
* Demonstrates custom models path usage
|
||||
*/
|
||||
|
||||
import { BrainyData } from '@soulcraft/brainy'
|
||||
|
||||
async function main() {
|
||||
console.log('🚀 Starting Brainy Docker Example App...')
|
||||
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`)
|
||||
console.log(`Models Path: ${process.env.BRAINY_MODELS_PATH || 'default (node_modules)'}`)
|
||||
|
||||
const db = new BrainyData({
|
||||
forceMemoryStorage: true,
|
||||
dimensions: 512,
|
||||
// Don't skip embeddings - let it try to load models
|
||||
skipEmbeddings: false
|
||||
})
|
||||
|
||||
try {
|
||||
console.log('\n📊 Initializing BrainyData...')
|
||||
await db.init()
|
||||
console.log('✅ BrainyData initialized successfully!')
|
||||
|
||||
// Add some test data
|
||||
console.log('\n📝 Adding test data...')
|
||||
const testItems = [
|
||||
'Artificial intelligence is transforming the world',
|
||||
'Machine learning enables computers to learn without being explicitly programmed',
|
||||
'Docker containers provide a consistent environment for applications',
|
||||
'Cloud deployment makes applications scalable and reliable'
|
||||
]
|
||||
|
||||
const ids = []
|
||||
for (const text of testItems) {
|
||||
const id = await db.add({ content: text })
|
||||
ids.push(id)
|
||||
console.log(` Added: "${text}" (ID: ${id})`)
|
||||
}
|
||||
|
||||
// Search for similar content
|
||||
console.log('\n🔍 Searching for AI-related content...')
|
||||
const searchResults = await db.search('artificial intelligence and machine learning', 2)
|
||||
|
||||
console.log(`Found ${searchResults.length} results:`)
|
||||
searchResults.forEach((result, index) => {
|
||||
console.log(` ${index + 1}. "${result.content}" (Score: ${result.similarity?.toFixed(3)})`)
|
||||
})
|
||||
|
||||
// Get database statistics
|
||||
console.log('\n📈 Database Statistics:')
|
||||
const stats = await db.getStatistics()
|
||||
console.log(` Total items: ${stats.totalVectors}`)
|
||||
console.log(` Storage type: ${stats.storageType}`)
|
||||
console.log(` Index type: ${stats.indexType}`)
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error:', error.message)
|
||||
console.error('\n💡 Troubleshooting tips:')
|
||||
console.error(' 1. Ensure models are available in BRAINY_MODELS_PATH')
|
||||
console.error(' 2. Check that @soulcraft/brainy-models is installed')
|
||||
console.error(' 3. Verify network connectivity for remote model loading')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('\n🎉 Example completed successfully!')
|
||||
}
|
||||
|
||||
// Handle graceful shutdown
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n👋 Shutting down gracefully...')
|
||||
process.exit(0)
|
||||
})
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
console.log('\n👋 Received SIGTERM, shutting down...')
|
||||
process.exit(0)
|
||||
})
|
||||
|
||||
// Run the example
|
||||
main().catch(error => {
|
||||
console.error('Fatal error:', error)
|
||||
process.exit(1)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue