brainy/src/utils
David Snelling f898f0ce7b feat\!: migrate from TensorFlow.js to Transformers.js with ONNX Runtime
BREAKING CHANGE: Complete migration from TensorFlow.js to Transformers.js for embedding generation

This is a major architectural change that replaces TensorFlow.js (USE model) with Transformers.js (all-MiniLM-L6-v2) for significantly improved performance and reduced complexity.

Key Changes:
- Replace TensorFlow.js Universal Sentence Encoder with Transformers.js all-MiniLM-L6-v2
- Reduce model size from 525MB to 87MB (83% reduction)
- Reduce embedding dimensions from 512 to 384 (faster distance calculations)
- Remove TensorFlow.js Float32Array patching (caused ONNX conflicts)
- Implement smart bundled model detection for offline operation
- Add explicit model download script for Docker deployments
- Remove complex environment variables in favor of simple configuration
- Update all distance functions to use optimized pure JavaScript
- Remove TensorFlow-specific utilities and type definitions

Performance Improvements:
- Model loading: 5x faster (87MB vs 525MB)
- Memory usage: 75% reduction (~200-400MB vs ~1.5GB)
- Distance calculations: Faster pure JS vs GPU overhead for small vectors
- Cold start performance: Significantly improved

Files Changed:
- Updated package.json: New dependencies, simplified scripts
- Rewrote src/utils/embedding.ts: Complete Transformers.js implementation
- Updated src/utils/distance.ts: Optimized JavaScript distance functions
- Simplified src/setup.ts: Removed TensorFlow-specific patching
- Simplified src/utils/textEncoding.ts: Only Node.js TextEncoder/Decoder patches
- Deleted src/utils/robustModelLoader.ts: TensorFlow-specific loader
- Deleted src/types/tensorflowTypes.ts: TensorFlow type definitions
- Added scripts/download-models.cjs: Docker-compatible model downloader
- Added comprehensive documentation: README.md, OFFLINE_MODELS.md, analysis docs

Testing:
- All 19 tests passing
- Removed test mocking in favor of real implementation testing
- Updated test environment for Transformers.js compatibility
- Performance tests validate improved efficiency

This migration resolves production issues with Docker egress limitations and provides a more robust, performant foundation for vector operations.
2025-08-05 19:29:59 -07:00
..
autoConfiguration.ts feat(auto-configuration): implement automatic configuration system for optimal settings 2025-08-03 17:27:01 -07:00
cacheAutoConfig.ts feat(pagination): implement cursor-based pagination and enhance search caching 2025-08-04 14:25:05 -07:00
crypto.ts feat(distributed): add distributed mode with multi-instance coordination 2025-08-04 12:18:58 -07:00
distance.ts feat\!: migrate from TensorFlow.js to Transformers.js with ONNX Runtime 2025-08-05 19:29:59 -07:00
embedding.ts feat\!: migrate from TensorFlow.js to Transformers.js with ONNX Runtime 2025-08-05 19:29:59 -07:00
environment.ts **feat(core): enhance vector handling, model loading, and compatibility** 2025-07-16 13:51:00 -07:00
fieldNameTracking.ts **feat(search): enhance JSON document search with field-level filtering and prioritization** 2025-08-01 08:27:39 -07:00
index.ts refactor: clean up deprecated functions and unused code 2025-08-05 10:16:05 -07:00
jsonProcessing.ts **feat(search): enhance JSON document search with field-level filtering and prioritization** 2025-08-01 08:27:39 -07:00
logger.ts fix(storage): resolve pagination warnings and improve S3 adapter performance 2025-08-05 07:22:05 -07:00
operationUtils.ts **feat: implement robust error-handling and operation utilities for storage adapters** 2025-07-30 11:35:09 -07:00
searchCache.ts feat(pagination): implement cursor-based pagination and enhance search caching 2025-08-04 14:25:05 -07:00
statistics.ts **feat(core, storage, tests): add service-level statistics tracking and storage adapter enhancements** 2025-07-24 11:35:52 -07:00
statisticsCollector.ts fix(core): resolve TypeScript compilation errors and test failures 2025-08-04 20:00:38 -07:00
textEncoding.ts feat\!: migrate from TensorFlow.js to Transformers.js with ONNX Runtime 2025-08-05 19:29:59 -07:00
typeUtils.ts **feat(utils): add type utility functions and examples for runtime type management** 2025-07-31 14:24:16 -07:00
version.ts refactor: clean up deprecated functions and unused code 2025-08-05 10:16:05 -07:00
workerUtils.ts **feat(tests): add tests for TextEncoder, TensorFlow.js, and fallback mechanisms** 2025-07-11 11:11:56 -07:00