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

@ -18,7 +18,6 @@ import { TypeAwareHNSWIndex } from '../hnsw/typeAwareHNSWIndex.js'
import { MetadataIndexManager } from '../utils/metadataIndex.js'
import { Vector } from '../coreTypes.js'
import { NounType } from '../types/graphTypes.js'
import { getQueryPlanner, TypeAwareQueryPlan } from '../query/typeAwareQueryPlanner.js'
// Triple Intelligence types
export interface TripleQuery {
@ -277,7 +276,6 @@ export class TripleIntelligenceSystem {
/**
* Main find method - executes Triple Intelligence queries
* Phase 3: Now with automatic type inference for 40% latency reduction
*/
async find(query: TripleQuery, options?: TripleOptions): Promise<TripleResult[]> {
const startTime = performance.now()
@ -285,27 +283,6 @@ export class TripleIntelligenceSystem {
// Validate query
this.validateQuery(query)
// Phase 3: Infer types from natural language if not explicitly provided
let typeAwarePlan: TypeAwareQueryPlan | undefined
if (!query.types && (query.similar || query.like) && this.hnswIndex instanceof TypeAwareHNSWIndex) {
const queryText = query.similar || query.like!
const planner = getQueryPlanner()
typeAwarePlan = await planner.planQuery(queryText)
// Use inferred types if confidence is sufficient
if (typeAwarePlan.confidence > 0.6) {
query.types = typeAwarePlan.targetTypes
// Log for analytics
console.log(
`[Phase 3] Type inference: ${typeAwarePlan.routing} ` +
`(${typeAwarePlan.targetTypes.length} types, ` +
`confidence: ${(typeAwarePlan.confidence * 100).toFixed(0)}%, ` +
`estimated ${typeAwarePlan.estimatedSpeedup.toFixed(1)}x speedup)`
)
}
}
// Build optimized query plan
const plan = this.planner.buildPlan(query)
@ -319,14 +296,6 @@ export class TripleIntelligenceSystem {
const elapsed = performance.now() - startTime
this.metrics.recordOperation('find_query', elapsed, results.length)
// Log Phase 3 performance impact
if (typeAwarePlan && typeAwarePlan.confidence > 0.6) {
console.log(
`[Phase 3] Query completed in ${elapsed.toFixed(2)}ms ` +
`(${results.length} results, ${typeAwarePlan.routing})`
)
}
// ASSERT performance guarantees
this.assertPerformance(elapsed, results.length)