perf: 580x faster embedding init - separate model from WASM

Cloud Run cold starts taking 139 seconds due to 90MB WASM file with
embedded 87MB model weights. WASM compilation scales with file size.

Solution: Split into 2.4MB WASM (code only) + external model files.
- WASM compile: 139,000ms → 6-8ms
- Model load: N/A → 30-115ms
- Total init: 139,000ms → 136-240ms

New modelLoader.ts handles all environments:
- Node.js: fs.readFile()
- Bun: Bun.file()
- Bun --compile: auto-embedded assets
- Browser: fetch()

Zero config - same API, npm package includes model files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
David Snelling 2026-01-06 17:18:58 -08:00
parent 4fc1fb7340
commit 677e2d6624
7 changed files with 360 additions and 38 deletions

View file

@ -685,6 +685,14 @@ export interface BrainyConfig {
maxQueryLimit?: number // Override auto-detected query result limit (max: 100000)
reservedQueryMemory?: number // Memory reserved for queries in bytes (e.g., 1073741824 = 1GB)
// Embedding initialization (v7.1.2)
// Controls when the WASM embedding engine is initialized
// - false (default): Lazy initialization on first embed() call
// - true: Eager initialization during brain.init()
// Set to true for cloud deployments (Cloud Run, Lambda) where you want
// WASM compilation to happen during container startup, not on first request
eagerEmbeddings?: boolean
// Logging configuration
verbose?: boolean // Enable verbose logging
silent?: boolean // Suppress all logging output