brainy/docs/architecture/augmentations-actual.md
David Snelling da7d2ed29d 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>
2026-01-06 12:52:34 -08:00

7.2 KiB

Augmentations System - What Actually Exists

Important Update: Investigation reveals Brainy has MORE augmentations than documented!

Actually Implemented Augmentations (12+)

Full implementation with crash recovery, checkpointing, and replay.

// Fully working with all features documented

2. Entity Registry Augmentation

High-performance deduplication using bloom filters.

import { EntityRegistryAugmentation } from 'brainy'
// Complete with all features

3. Auto-Register Entities Augmentation

Automatic entity extraction from text.

import { AutoRegisterEntitiesAugmentation } from 'brainy'
// Extracts and registers entities automatically

4. Intelligent Verb Scoring Augmentation

Multi-factor relationship strength calculation.

import { IntelligentVerbScoringAugmentation } from 'brainy'
// Semantic, temporal, frequency scoring

5. Batch Processing Augmentation

Dynamic batching with adaptive backpressure.

import { BatchProcessingAugmentation } from 'brainy'
// Smart batching with flow control

6. Connection Pool Augmentation

Intelligent connection management.

import { ConnectionPoolAugmentation } from 'brainy'
// Auto-scaling connection pools

7. Request Deduplicator Augmentation

Prevents duplicate operations.

import { RequestDeduplicatorAugmentation } from 'brainy'
// In-flight request deduplication

8. WebSocket Conduit Augmentation

Real-time bidirectional streaming.

import { WebSocketConduitAugmentation } from 'brainy'
// Full WebSocket support

9. WebRTC Conduit Augmentation

Peer-to-peer communication.

import { WebRTCConduitAugmentation } from 'brainy'
// P2P data channels

10. Memory Storage Augmentation

Optimized in-memory operations.

import { MemoryStorageAugmentation } from 'brainy'
// Memory-specific optimizations

11. Server Search Augmentation

Distributed search capabilities.

import { ServerSearchConduitAugmentation } from 'brainy'
// Distributed query execution

12. Neural Import Augmentation

AI-powered data understanding and import.

import { NeuralImportAugmentation } from 'brainy'
// Full entity detection and classification

🎯 Hidden Features in Augmentations

Neural Import Capabilities (Fully Implemented!)

const neuralImport = new NeuralImport(brain)

// These ALL work:
await neuralImport.neuralImport('data.csv')
await neuralImport.detectEntitiesWithNeuralAnalysis(data)
await neuralImport.detectNounType(entity)
await neuralImport.detectRelationships(entities)
await neuralImport.generateInsights(data)

Distributed Operation Modes (Fully Implemented!)

// Read-only mode with optimized caching
const readerMode = new ReaderMode()
// 80% cache, aggressive prefetch, 1hr TTL

// Write-only mode with batching
const writerMode = new WriterMode()
// Large write buffer, batch writes, minimal cache

// Hybrid mode
const hybridMode = new HybridMode()
// Balanced for mixed workloads

Advanced Caching (3-Level System!)

const cacheManager = new CacheManager({
  hotCache: { size: 1000, ttl: 60000 },    // L1 - RAM
  warmCache: { size: 10000, ttl: 300000 }, // L2 - Fast storage
  coldCache: { size: 100000, ttl: null }   // L3 - Persistent
})

Performance Monitoring (Complete!)

const monitor = new PerformanceMonitor(brain)

// All these metrics work:
monitor.getMetrics() // Returns comprehensive stats
monitor.getQueryPatterns() // Query analysis
monitor.getCacheStats() // Cache performance
monitor.getThrottlingMetrics() // Rate limiting info

📊 Statistics System (Fully Working!)

const stats = await brain.getStats()
// Returns comprehensive metrics:
{
  nouns: {
    count: number,
    created: number,
    updated: number,
    deleted: number,
    size: number,
    avgSize: number
  },
  verbs: {
    count: number,
    created: number,
    types: Record<string, number>,
    weights: { min, max, avg }
  },
  vectors: {
    dimensions: 384,
    indexSize: number,
    partitions: number,
    avgSearchTime: number
  },
  cache: {
    hits: number,
    misses: number,
    evictions: number,
    hitRate: number,
    hotCacheSize: number,
    warmCacheSize: number
  },
  performance: {
    operations: number,
    avgAddTime: number,
    avgSearchTime: number,
    avgUpdateTime: number,
    p95Latency: number,
    p99Latency: number
  },
  storage: {
    used: number,
    available: number,
    compression: number,
    files: number
  },
  throttling: {
    delays: number,
    rateLimited: number,
    backoffMs: number,
    retries: number
  }
}

🚀 GPU Support (Partial but Real!)

// GPU detection WORKS:
const device = await detectBestDevice()
// Returns: 'cpu' | 'webgpu' | 'cuda'

// WebGPU support in browser:
if (device === 'webgpu') {
  // Transformer models can use WebGPU
}

// CUDA detection in Node:
if (device === 'cuda') {
  // Future: GPU acceleration support
}

🔄 Adaptive Systems (All Working!)

Adaptive Backpressure

const backpressure = new AdaptiveBackpressure()
// Automatically adjusts flow based on system load

Adaptive Socket Manager

const socketManager = new AdaptiveSocketManager()
// Dynamic connection pooling based on traffic

Cache Auto-Configuration

const cacheConfig = await getCacheAutoConfig()
// Sizes cache based on available memory

S3 Throttling Protection

// Built into S3 storage adapter
// Automatic exponential backoff
// Rate limit detection and adaptation

🎨 How to Use Hidden Features

Enable Distributed Modes

const brain = new Brainy({
  mode: 'reader', // or 'writer' or 'hybrid'
  distributed: {
    role: 'reader',
    cacheStrategy: 'aggressive',
    prefetch: true
  }
})

Use Neural Import

const brain = new Brainy({
  augmentations: [
    new NeuralImportAugmentation({
      confidenceThreshold: 0.7,
      autoDetect: true
    })
  ]
})

// Import with AI understanding
await brain.neuralImport('data.csv')

Access Statistics

// Get comprehensive stats
const stats = await brain.getStats()

// Get specific service stats
const nounStats = await brain.getStatistics({ 
  service: 'nouns' 
})

// Force refresh
const freshStats = await brain.getStatistics({ 
  forceRefresh: true 
})

📝 What Needs Documentation

These features EXIST but need better docs:

  1. Distributed operation modes
  2. Neural import full API
  3. 3-level cache configuration
  4. Performance monitoring API
  5. GPU acceleration setup
  6. Advanced statistics queries
  7. Throttling configuration
  8. Backpressure tuning

💡 The Truth

Brainy is MORE powerful than its own documentation suggests! Most "missing" features are actually implemented but hidden or not properly exposed. The codebase contains sophisticated systems for:

  • Distributed operations
  • AI-powered import
  • Advanced caching
  • Performance monitoring
  • GPU support
  • Adaptive optimization

The main work needed is integration and documentation, not implementation!