@soulcraft/brainy 2.7.0 → 2.7.2

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.
@@ -23,7 +23,7 @@ export declare class UniversalMemoryManager {
23
23
  embed(data: string | string[]): Promise<Vector>;
24
24
  private checkMemoryLimits;
25
25
  private ensureEmbeddingFunction;
26
- private initNodeWorker;
26
+ private initNodeDirect;
27
27
  private initServerless;
28
28
  private initBrowser;
29
29
  private initFallback;
@@ -13,18 +13,21 @@ const isServerless = typeof process !== 'undefined' && (process.env.VERCEL ||
13
13
  process.env.FUNCTIONS_WORKER_RUNTIME);
14
14
  export class UniversalMemoryManager {
15
15
  constructor() {
16
+ // CRITICAL FIX: Never use worker threads with ONNX Runtime
17
+ // Worker threads cause HandleScope V8 API errors due to isolate issues
18
+ // Always use direct embedding on main thread for ONNX compatibility
16
19
  this.embeddingFunction = null;
17
20
  this.embedCount = 0;
18
21
  this.restartCount = 0;
19
22
  this.lastRestart = 0;
20
- // Choose strategy based on environment
21
23
  if (isServerless) {
22
24
  this.strategy = 'serverless-restart';
23
25
  this.maxEmbeddings = 50; // Restart frequently in serverless
24
26
  }
25
27
  else if (isNode && !isBrowser) {
26
- this.strategy = 'node-worker';
27
- this.maxEmbeddings = 100; // Worker can handle more
28
+ // CHANGED: Use direct strategy instead of node-worker to avoid V8 isolate issues
29
+ this.strategy = 'node-direct';
30
+ this.maxEmbeddings = 200; // Main thread can handle more with single model instance
28
31
  }
29
32
  else if (isBrowser) {
30
33
  this.strategy = 'browser-dispose';
@@ -35,6 +38,7 @@ export class UniversalMemoryManager {
35
38
  this.maxEmbeddings = 75;
36
39
  }
37
40
  console.log(`🧠 Universal Memory Manager: Using ${this.strategy} strategy`);
41
+ console.log('✅ UNIVERSAL: Memory-safe embedding system initialized');
38
42
  }
39
43
  async getEmbeddingFunction() {
40
44
  return async (data) => {
@@ -62,8 +66,8 @@ export class UniversalMemoryManager {
62
66
  return;
63
67
  }
64
68
  switch (this.strategy) {
65
- case 'node-worker':
66
- await this.initNodeWorker();
69
+ case 'node-direct':
70
+ await this.initNodeDirect();
67
71
  break;
68
72
  case 'serverless-restart':
69
73
  await this.initServerless();
@@ -75,19 +79,12 @@ export class UniversalMemoryManager {
75
79
  await this.initFallback();
76
80
  }
77
81
  }
78
- async initNodeWorker() {
82
+ async initNodeDirect() {
79
83
  if (isNode) {
80
- try {
81
- // Try to use worker threads if available
82
- const { workerEmbeddingManager } = await import('./worker-manager.js');
83
- this.embeddingFunction = workerEmbeddingManager;
84
- console.log('✅ Using Node.js worker threads for embeddings');
85
- }
86
- catch (error) {
87
- console.warn('⚠️ Worker threads not available, falling back to direct embedding');
88
- console.warn('Error:', error instanceof Error ? error.message : String(error));
89
- await this.initDirect();
90
- }
84
+ // CRITICAL: Use direct embedding to avoid worker thread V8 isolate issues
85
+ // This prevents HandleScope errors and ensures single model instance
86
+ console.log('✅ Using Node.js direct embedding (main thread - ONNX compatible)');
87
+ await this.initDirect();
91
88
  }
92
89
  }
93
90
  async initServerless() {
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export { NeuralImport } from './cortex/neuralImport.js';
16
16
  export type { NeuralAnalysisResult, DetectedEntity, DetectedRelationship, NeuralInsight, NeuralImportOptions } from './cortex/neuralImport.js';
17
17
  import { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance, getStatistics } from './utils/index.js';
18
18
  export { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance, getStatistics };
19
+ export { getBrainyVersion } from './utils/version.js';
19
20
  import { UniversalSentenceEncoder, TransformerEmbedding, createEmbeddingFunction, defaultEmbeddingFunction, batchEmbed, embeddingFunctions } from './utils/embedding.js';
20
21
  import { executeInThread, cleanupWorkerPools } from './utils/workerUtils.js';
21
22
  import { logger, LogLevel, configureLogger, createModuleLogger } from './utils/logger.js';
package/dist/index.js CHANGED
@@ -19,6 +19,8 @@ export { NeuralImport } from './cortex/neuralImport.js';
19
19
  // Export distance functions for convenience
20
20
  import { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance, getStatistics } from './utils/index.js';
21
21
  export { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance, getStatistics };
22
+ // Export version utilities
23
+ export { getBrainyVersion } from './utils/version.js';
22
24
  // Export embedding functionality
23
25
  import { UniversalSentenceEncoder, TransformerEmbedding, createEmbeddingFunction, defaultEmbeddingFunction, batchEmbed, embeddingFunctions } from './utils/embedding.js';
24
26
  // Export worker utilities
@@ -1,14 +1,30 @@
1
1
  /**
2
2
  * Version utilities for Brainy
3
3
  */
4
- // Package version - this should be updated during the build process
5
- const BRAINY_VERSION = '0.41.0';
4
+ import { readFileSync } from 'fs';
5
+ import { join, dirname } from 'path';
6
+ import { fileURLToPath } from 'url';
7
+ // Get package.json path relative to this file
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ const packageJsonPath = join(__dirname, '../../package.json');
11
+ let cachedVersion = null;
6
12
  /**
7
13
  * Get the current Brainy package version
8
14
  * @returns The current version string
9
15
  */
10
16
  export function getBrainyVersion() {
11
- return BRAINY_VERSION;
17
+ if (!cachedVersion) {
18
+ try {
19
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
20
+ cachedVersion = packageJson.version;
21
+ }
22
+ catch {
23
+ // Fallback version if package.json can't be read
24
+ cachedVersion = '2.7.1';
25
+ }
26
+ }
27
+ return cachedVersion;
12
28
  }
13
29
  /**
14
30
  * Get version information for augmentation metadata
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",