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

@ -68,16 +68,16 @@
"bun": ">=1.0.0"
},
"scripts": {
"build": "npm run build:types:if-needed && npm run build:patterns:if-needed && npm run build:keywords:if-needed && tsc && tsc -p tsconfig.cli.json",
"build": "npm run build:types:if-needed && npm run build:patterns:if-needed && tsc && tsc -p tsconfig.cli.json && npm run build:copy-wasm",
"build:copy-wasm": "node -e \"const fs=require('fs');const src='src/embeddings/wasm/pkg';const dst='dist/embeddings/wasm/pkg';if(fs.existsSync(src)){fs.mkdirSync(dst,{recursive:true});fs.readdirSync(src).forEach(f=>fs.copyFileSync(src+'/'+f,dst+'/'+f));console.log('Copied WASM pkg to dist')}\"",
"build:types": "tsx scripts/buildTypeEmbeddings.ts",
"build:types:if-needed": "node scripts/check-type-embeddings.cjs || npm run build:types",
"build:types:force": "npm run build:types",
"build:patterns": "tsx scripts/buildEmbeddedPatterns.ts",
"build:patterns:if-needed": "node scripts/check-patterns.cjs || npm run build:patterns",
"build:patterns:force": "npm run build:patterns",
"build:keywords": "tsx scripts/buildKeywordEmbeddings.ts",
"build:keywords:if-needed": "node scripts/check-keyword-embeddings.cjs || npm run build:keywords",
"build:keywords:force": "npm run build:keywords",
"build:candle": "./scripts/build-candle-wasm.sh",
"build:candle:dev": "./scripts/build-candle-wasm.sh --dev",
"prepare": "npm run build",
"test": "npm run test:unit",
"test:watch": "NODE_OPTIONS='--max-old-space-size=8192' vitest --config tests/configs/vitest.unit.config.ts",
@ -94,10 +94,7 @@
"test:bun": "bun tests/integration/bun-compile-test.ts",
"test:bun:compile": "bun build tests/integration/bun-compile-test.ts --compile --outfile /tmp/brainy-bun-test && /tmp/brainy-bun-test",
"test:wasm": "npx vitest run tests/integration/wasm-embeddings.test.ts",
"download-model": "node scripts/download-model.cjs",
"download-models": "node scripts/download-models.cjs",
"download-models:q8": "node scripts/download-models.cjs",
"models:verify": "node scripts/ensure-models.js",
"typecheck": "tsc --noEmit",
"lint": "eslint --ext .ts,.js src/",
"lint:fix": "eslint --ext .ts,.js src/ --fix",
"format": "prettier --write \"src/**/*.{ts,js}\"",
@ -146,12 +143,8 @@
"files": [
"dist/**/*.js",
"dist/**/*.d.ts",
"dist/**/*.wasm",
"bin/",
"assets/models/**/*",
"scripts/download-models.cjs",
"scripts/download-model.cjs",
"scripts/ensure-models.js",
"scripts/prepare-models.js",
"brainy.png",
"LICENSE",
"README.md",
@ -187,7 +180,6 @@
"@azure/identity": "^4.0.0",
"@azure/storage-blob": "^12.17.0",
"@google-cloud/storage": "^7.14.0",
"onnxruntime-web": "^1.22.0",
"@msgpack/msgpack": "^3.1.2",
"@types/js-yaml": "^4.0.9",
"boxen": "^8.0.1",