Skip to content

Conversation

@ruvnet
Copy link
Owner

@ruvnet ruvnet commented Oct 25, 2025

Summary

Implements local embedding generation using transformers.js, eliminating API key requirements and enabling completely offline semantic search.

Changes

Core Implementation (v1.8.6-1.8.10)

Local Transformer Model:

  • Uses @xenova/transformers with Xenova/all-MiniLM-L6-v2
  • 384-dimensional embeddings (optimized from 1024)
  • Completely free and offline after initial 23MB model download
  • 50-100ms per embedding with LRU caching

NPX Environment Detection:

  • Automatically detects npx execution (npm_lifecycle_event === 'npx')
  • Skips transformer initialization in npx (avoids ONNX/WASM errors)
  • Shows helpful message for semantic search via global install
  • Can force transformers with FORCE_TRANSFORMERS=true

Files Modified:

  • src/reasoningbank/utils/embeddings.ts - Complete rewrite with transformers.js
  • src/reasoningbank/config/reasoningbank.yaml - Updated to local provider
  • package.json - Added @xenova/transformers, updated build
  • .npmignore - Excluded Rust artifacts (package: 166MB → 1.6MB)

Features

✅ WASM backend configuration for Node.js compatibility
✅ NPX environment detection (clean UX, no confusing errors)
✅ LRU cache (1000 entries) with TTL expiration
✅ Graceful fallback to hash-based embeddings
✅ Lazy initialization (no startup delay)

Configuration

embeddings:
  provider: "local"
  model: "Xenova/all-MiniLM-L6-v2"
  dimensions: 384
  cache_ttl_seconds: 3600

Usage

# NPX (hash-based fallback - clean experience)
npx claude-flow@alpha memory store "key" "value"
# Output: [Embeddings] NPX environment detected - using hash-based embeddings

# Global install (true semantic search)
npm install -g claude-flow
claude-flow memory store "key" "value"
# Output: [Embeddings] Local model ready! (384 dimensions)

Benefits

  • 🆓 Zero Cost: No API fees
  • 🔒 Privacy: All processing local
  • 📴 Offline: Works without internet (after download)
  • ⚡ Fast: 50-100ms inference
  • 💾 Efficient: Smart caching
  • 🛡️ Reliable: Automatic fallback

Testing

  • ✅ Model initialization and download
  • ✅ Embedding generation (384 dims)
  • ✅ NPX detection and clean fallback
  • ✅ Cache functionality
  • ✅ Semantic similarity search

Version History

  • v1.8.6: Initial local embeddings
  • v1.8.7: Config file copying, WASM fixes
  • v1.8.8: WASM backend proxy config
  • v1.8.9: NPX detection (user_agent)
  • v1.8.10: Improved NPX detection (lifecycle_event) ✅

Closes #38

ruvnet and others added 9 commits October 25, 2025 20:55
- Added better-sqlite3 and @types/better-sqlite3 to dependencies
- Fixed broken import in src/reasoningbank/db/queries.ts
- Replaced stub `const BetterSqlite3 = null` with proper import
- Updated all Database constructor calls
- Resolves ReasoningBank initialization errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Changed misleading env variable check to hardcoded true
- Fixed in 3 files: index.ts, index.js, index-new.ts
- Users were confused by 'Enabled: false' when ReasoningBank was working
- Affects npx users who see this message during initialization

Related to v1.8.4 better-sqlite3 fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…s compatibility

- Add env.backends.onnx.wasm.numThreads configuration
- Import env from @xenova/transformers
- Fixes ONNX runtime error in Node.js environments
- Enables hash-based fallback when model loading fails
…ibility (v1.8.7)

- Add env.backends.onnx.wasm.numThreads configuration
- Import env from @xenova/transformers
- Fixes ONNX runtime error in Node.js environments
- Enables hash-based fallback when model loading fails
Reduces package size from 166.9 MB to 1.6 MB by excluding:
- reasoningbank/target/
- All Rust build artifacts (*.rlib, *.rmeta)
- Fixes E415 hardlink error during npm publish
- Set env.backends.onnx.wasm.proxy = false to avoid DefaultLogger errors
- Fixes 'no available backend found' error in Node.js environments
- Local embeddings now work without fallback to hash-based system
- Verified: 384-dimensional embeddings generating successfully
…ialization

- Automatically detects npx execution environment
- Skips transformer model loading in npx (avoids ONNX/WASM errors)
- Shows helpful message suggesting global install for semantic search
- Falls back cleanly to hash-based embeddings
- Can force transformers with FORCE_TRANSFORMERS=true environment variable

Resolves confusing error messages in npx while maintaining full functionality.
Users who want true semantic search can install globally.
- Check npm_lifecycle_event === 'npx' (most reliable)
- Check npm_execpath for 'npx' string
- Fallback to cwd checks for _npx directories
- More robust NPX environment detection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Local embeddings with transformers.js - no API key required

1 participant