feat: migrate embeddings to Candle WASM + remove semantic type inference

Major architectural changes:

1. EMBEDDINGS ENGINE (ONNX → Candle WASM):
   - Replace ONNX Runtime with Rust Candle compiled to WASM
   - Embedded model in WASM binary (no external downloads)
   - Quantized Q8 precision with <50MB memory footprint
   - Zero-download, offline-first operation
   - Same embedding quality (all-MiniLM-L6-v2)

2. REMOVE SEMANTIC TYPE INFERENCE:
   - Delete embeddedKeywordEmbeddings.ts (14MB of pre-computed embeddings)
   - Remove typeAwareQueryPlanner.ts and semanticTypeInference.ts
   - Remove VerbExactMatchSignal (uses keyword embeddings)
   - Update SmartRelationshipExtractor to 3 signals (55%/30%/15% weights)

API CHANGES (requires v7.0.0):
- Removed: inferTypes(), inferNouns(), inferVerbs(), inferIntent()
- Removed: getSemanticTypeInference(), SemanticTypeInference class
- Removed: TypeInference, SemanticTypeInferenceOptions types

Users can still use natural language queries in find() - they just
need to specify type explicitly for type-optimized searches.

PACKAGE SIZE IMPACT:
- Compressed: 90.1 MB → 86.2 MB (-4.3%)
- Uncompressed: 114.4 MB → 100.3 MB (-12%)
- ~448K lines of code removed

🤖 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 12:52:34 -08:00
parent 81cd16e41b
commit da7d2ed29d
60 changed files with 3887 additions and 448557 deletions

View file

@ -1,6 +1,8 @@
# Production Service Architecture Guide
**How to use Brainy optimally in production Express/Node.js services**
**How to use Brainy optimally in production services (Bun, Node.js, Deno)**
> **Recommended Runtime:** [Bun](https://bun.sh) provides best performance with Brainy's Candle WASM engine. All examples work with both Bun and Node.js.
---
@ -168,7 +170,57 @@ process.on('SIGTERM', async () => {
---
### Pattern 3: Express Middleware
### Pattern 3: Bun Server (Recommended)
```typescript
// server.ts - Clean Bun implementation
import { Brainy } from '@soulcraft/brainy'
let brain: Brainy | null = null
async function getBrain(): Promise<Brainy> {
if (!brain) {
brain = new Brainy({ storage: { path: './brainy-data' } })
await brain.init()
}
return brain
}
// Initialize before server starts
await getBrain()
Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url)
if (url.pathname === '/api/entities') {
const b = await getBrain()
const entities = await b.find({})
return Response.json(entities)
}
if (url.pathname === '/api/entity' && req.method === 'POST') {
const b = await getBrain()
const body = await req.json()
const id = await b.add(body)
return Response.json({ id })
}
return new Response('Not Found', { status: 404 })
}
})
console.log('Server running on http://localhost:3000')
```
**Benefits:**
- ✅ Native Bun performance (~2x faster than Node.js)
- ✅ No framework dependencies
- ✅ Works with `bun --compile` for single-binary deployment
- ✅ Built-in TypeScript support
### Pattern 4: Express/Node.js Middleware (Legacy)
```typescript
// middleware/brainy.ts