claude-flow 2.7.23 → 2.7.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,362 @@
1
+ # Transformer Model Initialization Issue in npx
2
+
3
+ ## Status: ⚠️ Known Issue with Graceful Fallback
4
+
5
+ **Date:** October 25, 2025
6
+ **Versions:** claude-flow@2.7.24, agentic-flow@1.8.7
7
+ **Impact:** Low - System works with hash-based embeddings fallback
8
+
9
+ ---
10
+
11
+ ## Summary
12
+
13
+ When using `npx claude-flow@alpha memory` commands, the local transformer model (Xenova/all-MiniLM-L6-v2) fails to initialize in npx temporary directories due to ONNX runtime and WASM backend issues. The system gracefully falls back to hash-based embeddings, maintaining full functionality.
14
+
15
+ ## Error Output
16
+
17
+ ```bash
18
+ npx claude-flow@alpha memory store "test" "Local embeddings working!"
19
+
20
+ [Embeddings] Initializing local embedding model (Xenova/all-MiniLM-L6-v2)...
21
+ [Embeddings] First run will download ~23MB model...
22
+
23
+ Error: /onnxruntime_src/include/onnxruntime/core/common/logging/logging.h:371
24
+ static const onnxruntime::logging::Logger& onnxruntime::logging::LoggingManager::DefaultLogger()
25
+ Attempt to use DefaultLogger but none has been registered.
26
+
27
+ Something went wrong during model construction (most likely a missing operation).
28
+ Using `wasm` as a fallback.
29
+
30
+ [Embeddings] Failed to initialize: no available backend found. ERR:
31
+ [Embeddings] Falling back to hash-based embeddings
32
+
33
+ ✅ ✅ Stored successfully in ReasoningBank ← Still works!
34
+ ```
35
+
36
+ ## Root Causes
37
+
38
+ ### 1. ONNX Runtime Issue
39
+ **Error:** `Attempt to use DefaultLogger but none has been registered`
40
+
41
+ **Location:** `onnxruntime-node` backend initialization
42
+
43
+ **Why it happens:**
44
+ - ONNX runtime expects a logger to be registered before use
45
+ - In npx temporary directories, initialization order may be different
46
+ - The logger registration doesn't happen before model loading
47
+
48
+ ### 2. WASM Fallback Issue
49
+ **Error:** `no available backend found`
50
+
51
+ **Why it happens:**
52
+ - After ONNX fails, @xenova/transformers tries WASM backend
53
+ - WASM backend also fails in npx environment
54
+ - Likely due to missing WASM files or incorrect paths in temporary directory
55
+
56
+ ### 3. NPX Environment Constraints
57
+ - Temporary installation directories
58
+ - Limited file system access
59
+ - Different initialization order than local installs
60
+ - Optional dependencies may not install
61
+
62
+ ---
63
+
64
+ ## Current Behavior (Working as Designed)
65
+
66
+ ### ✅ What Works
67
+
68
+ 1. **Memory system fully functional**
69
+ - Store, query, list, export, import all work
70
+ - SQLite database persistence
71
+ - ReasoningBank integration
72
+
73
+ 2. **Graceful degradation**
74
+ - Automatic fallback to hash-based embeddings
75
+ - No crashes or errors that break functionality
76
+ - Clear logging of what's happening
77
+
78
+ 3. **Hash-based embeddings**
79
+ - Deterministic similarity based on text content
80
+ - Fast (no model loading time)
81
+ - Works offline without any dependencies
82
+
83
+ ### ⚠️ What's Limited
84
+
85
+ 1. **Semantic search quality**
86
+ - Hash-based embeddings don't capture semantic meaning
87
+ - "authentication" won't match "JWT" or "OAuth" semantically
88
+ - Still provides basic text similarity
89
+
90
+ 2. **True vector similarity**
91
+ - Can't find conceptually similar content
92
+ - Limited to exact or partial text matching
93
+
94
+ ---
95
+
96
+ ## Workarounds
97
+
98
+ ### Option 1: Local Installation (Best Results)
99
+
100
+ ```bash
101
+ # Install globally (not via npx)
102
+ npm install -g claude-flow@alpha
103
+
104
+ # Now transformers work better
105
+ claude-flow memory store "test" "value"
106
+ # ✅ Real transformer embeddings may work
107
+ ```
108
+
109
+ ### Option 2: Use Hash-Based Embeddings (Current Default)
110
+
111
+ ```bash
112
+ # Just use it - fallback works automatically
113
+ npx claude-flow@alpha memory store "key" "value"
114
+ npx claude-flow@alpha memory query "search"
115
+ # ✅ Works with hash-based similarity
116
+ ```
117
+
118
+ ### Option 3: Disable Embedding Attempts
119
+
120
+ Set environment variable to skip transformer initialization:
121
+
122
+ ```bash
123
+ export SKIP_TRANSFORMERS=true
124
+ npx claude-flow@alpha memory store "key" "value"
125
+ # ✅ Skips transformer loading, uses hash directly
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Proposed Fixes
131
+
132
+ ### Short-Term: Improve Error Handling
133
+
134
+ **File:** `agentic-flow/src/reasoningbank/utils/embeddings.ts`
135
+
136
+ ```typescript
137
+ async function initializeEmbeddings(): Promise<boolean> {
138
+ // Skip if in npx environment (known issue)
139
+ const isNpx = process.env.npm_config_user_agent?.includes('npx') ||
140
+ process.cwd().includes('_npx');
141
+
142
+ if (isNpx && !process.env.FORCE_TRANSFORMERS) {
143
+ console.log('[Embeddings] Detected npx environment');
144
+ console.log('[Embeddings] Using hash-based embeddings (set FORCE_TRANSFORMERS=true to try local model)');
145
+ return false;
146
+ }
147
+
148
+ // Try to initialize...
149
+ }
150
+ ```
151
+
152
+ ### Mid-Term: Fix ONNX Logger Registration
153
+
154
+ **File:** `agentic-flow/src/reasoningbank/utils/embeddings.ts`
155
+
156
+ ```typescript
157
+ import { env } from '@xenova/transformers';
158
+
159
+ async function initializeEmbeddings(): Promise<boolean> {
160
+ try {
161
+ // Configure ONNX runtime before loading
162
+ if (env.backends?.onnx) {
163
+ // Disable ONNX runtime in npx (use WASM instead)
164
+ env.backends.onnx = false;
165
+ }
166
+
167
+ // Force WASM backend with proper configuration
168
+ if (env.backends?.wasm) {
169
+ env.backends.wasm.numThreads = 1;
170
+ env.backends.wasm.simd = false; // Disable SIMD for compatibility
171
+ }
172
+
173
+ // Now load pipeline
174
+ embeddingPipeline = await pipeline(
175
+ 'feature-extraction',
176
+ 'Xenova/all-MiniLM-L6-v2',
177
+ { device: 'wasm' } // Force WASM backend
178
+ );
179
+
180
+ return true;
181
+ } catch (error) {
182
+ console.log('[Embeddings] Transformer initialization failed, using hash-based embeddings');
183
+ return false;
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### Long-Term: Make Transformers Truly Optional
189
+
190
+ **File:** `agentic-flow/package.json`
191
+
192
+ ```json
193
+ {
194
+ "dependencies": {
195
+ "better-sqlite3": "^11.10.0",
196
+ // ... other deps
197
+ },
198
+ "optionalDependencies": {
199
+ "@xenova/transformers": "^3.2.0"
200
+ },
201
+ "peerDependencies": {
202
+ "@xenova/transformers": "^3.0.0"
203
+ },
204
+ "peerDependenciesMeta": {
205
+ "@xenova/transformers": {
206
+ "optional": true
207
+ }
208
+ }
209
+ }
210
+ ```
211
+
212
+ Then update embeddings.ts to check if module exists:
213
+
214
+ ```typescript
215
+ let transformersAvailable = false;
216
+
217
+ try {
218
+ await import('@xenova/transformers');
219
+ transformersAvailable = true;
220
+ } catch {
221
+ console.log('[Embeddings] @xenova/transformers not installed - using hash-based embeddings');
222
+ transformersAvailable = false;
223
+ }
224
+ ```
225
+
226
+ ---
227
+
228
+ ## Testing
229
+
230
+ ### Verify Fallback Works
231
+
232
+ ```bash
233
+ # Test with npx (uses fallback)
234
+ npx claude-flow@alpha memory store "test" "value"
235
+ npx claude-flow@alpha memory query "test"
236
+ # ✅ Should work with hash-based embeddings
237
+
238
+ # Test with local install (may use transformers)
239
+ npm install -g claude-flow@alpha
240
+ claude-flow memory store "test" "value"
241
+ # ✅ May use real transformers if environment supports it
242
+ ```
243
+
244
+ ### Verify Database Integrity
245
+
246
+ ```bash
247
+ # Store data
248
+ npx claude-flow@alpha memory store "key1" "value1"
249
+ npx claude-flow@alpha memory store "key2" "value2"
250
+
251
+ # List data
252
+ npx claude-flow@alpha memory list
253
+ # ✅ Should show both entries
254
+
255
+ # Query data
256
+ npx claude-flow@alpha memory query "key"
257
+ # ✅ Should find both (text matching)
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Impact Analysis
263
+
264
+ ### User Experience
265
+
266
+ ✅ **Positive:**
267
+ - Memory system works out of the box with npx
268
+ - No crashes or broken functionality
269
+ - Clear error messages explaining fallback
270
+ - Hash-based embeddings provide basic similarity
271
+
272
+ ⚠️ **Limitations:**
273
+ - Not true semantic search (can't find "JWT" when searching "authentication")
274
+ - Users may expect better semantic matching
275
+ - Documentation should clarify this limitation
276
+
277
+ ### Performance
278
+
279
+ ✅ **Faster startup:**
280
+ - No 23MB model download
281
+ - Instant hash-based embedding generation
282
+ - Lower memory usage
283
+
284
+ ⚠️ **Lower quality:**
285
+ - Less accurate similarity matching
286
+ - Misses conceptual relationships
287
+ - Limited to text overlap
288
+
289
+ ---
290
+
291
+ ## Documentation Updates
292
+
293
+ ### README.md
294
+
295
+ Add section:
296
+
297
+ ```markdown
298
+ ## Memory System: Semantic Search
299
+
300
+ The memory system includes semantic search capabilities with automatic fallback:
301
+
302
+ ### Local Installation (Recommended for Semantic Search)
303
+ ```bash
304
+ npm install -g claude-flow@alpha
305
+ claude-flow memory query "authentication"
306
+ # ✅ Attempts to use local transformer model
307
+ ```
308
+
309
+ ### NPX Usage (Hash-Based Similarity)
310
+ ```bash
311
+ npx claude-flow@alpha memory query "authentication"
312
+ # ✅ Uses hash-based text matching (fallback)
313
+ ```
314
+
315
+ **Note:** Due to npx environment limitations, local transformer models
316
+ may not initialize. The system automatically falls back to hash-based
317
+ embeddings which provide basic text similarity matching.
318
+
319
+ For best semantic search quality, install globally instead of using npx.
320
+ ```
321
+
322
+ ---
323
+
324
+ ## Related Issues
325
+
326
+ - GitHub Issue #840: SQLite memory command fixes (resolved)
327
+ - GitHub Issue (NEW): Transformer initialization in npx environments
328
+ - Upstream: @xenova/transformers ONNX/WASM initialization in temporary directories
329
+
330
+ ---
331
+
332
+ ## Recommendations
333
+
334
+ ### For Users:
335
+
336
+ 1. **Use local installation** if semantic search quality matters
337
+ 2. **Use npx** if basic text matching is sufficient
338
+ 3. **Be aware** that "semantic search enabled" message appears even with fallback
339
+
340
+ ### For Developers:
341
+
342
+ 1. **Document fallback behavior** clearly in user-facing messages
343
+ 2. **Make transformers optional** in package.json
344
+ 3. **Add environment detection** to skip transformer loading in npx
345
+ 4. **Fix ONNX logger registration** for environments where it's possible
346
+ 5. **Test in npx** as part of CI/CD to catch these issues
347
+
348
+ ---
349
+
350
+ ## Conclusion
351
+
352
+ The transformer initialization issue in npx is a known limitation that's being
353
+ handled gracefully. The system remains fully functional with hash-based embeddings
354
+ as a fallback. Users who need true semantic search can install globally.
355
+
356
+ **Priority:** Medium - System works, but semantic search quality is reduced in npx
357
+
358
+ **Next Steps:**
359
+ 1. Make @xenova/transformers truly optional
360
+ 2. Add environment detection for npx
361
+ 3. Improve WASM backend initialization
362
+ 4. Update documentation to clarify behavior
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "2.7.23",
3
+ "version": "2.7.25",
4
4
  "description": "Enterprise-grade AI agent orchestration with WASM-powered ReasoningBank memory and AgentDB vector database (always uses latest agentic-flow)",
5
5
  "mcpName": "io.github.ruvnet/claude-flow",
6
6
  "main": "cli.mjs",
@@ -120,7 +120,7 @@
120
120
  "@anthropic-ai/claude-code": "^2.0.1",
121
121
  "@anthropic-ai/sdk": "^0.65.0",
122
122
  "@modelcontextprotocol/sdk": "^1.0.4",
123
- "agentic-flow": "^1.8.5",
123
+ "agentic-flow": "^1.8.9",
124
124
  "blessed": "^0.1.81",
125
125
  "chalk": "^4.1.2",
126
126
  "cli-table3": "^0.6.3",
@@ -143,6 +143,7 @@
143
143
  },
144
144
  "optionalDependencies": {
145
145
  "@types/better-sqlite3": "^7.6.13",
146
+ "@xenova/transformers": "^3.2.0",
146
147
  "agentdb": "^1.3.9",
147
148
  "better-sqlite3": "^12.2.0",
148
149
  "diskusage": "^1.1.3",