@soulcraft/brainy 1.1.0 → 1.1.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.
@@ -945,7 +945,6 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
945
945
  * @deprecated Use add() instead - it's smart by default now
946
946
  * @hidden
947
947
  */
948
- addSmart(vectorOrData: Vector | any, metadata?: T, options?: any): Promise<string>;
949
948
  /**
950
949
  * Get the number of nouns in the database (excluding verbs)
951
950
  * This is used for statistics reporting to match the expected behavior in tests
@@ -3206,10 +3206,6 @@ export class BrainyData {
3206
3206
  * @deprecated Use add() instead - it's smart by default now
3207
3207
  * @hidden
3208
3208
  */
3209
- async addSmart(vectorOrData, metadata, options = {}) {
3210
- console.warn('⚠️ addSmart() is deprecated. Use add() instead - it\'s smart by default now!');
3211
- return this.add(vectorOrData, metadata, { ...options, process: 'auto' });
3212
- }
3213
3209
  /**
3214
3210
  * Get the number of nouns in the database (excluding verbs)
3215
3211
  * This is used for statistics reporting to match the expected behavior in tests
@@ -59,14 +59,41 @@ export class TransformerEmbedding {
59
59
  this.initialized = false;
60
60
  this.verbose = true;
61
61
  this.verbose = options.verbose !== undefined ? options.verbose : true;
62
+ // PRODUCTION-READY MODEL CONFIGURATION
63
+ // Priority order: explicit option > environment variable > smart default
64
+ let localFilesOnly;
65
+ if (options.localFilesOnly !== undefined) {
66
+ // 1. Explicit option takes highest priority
67
+ localFilesOnly = options.localFilesOnly;
68
+ }
69
+ else if (process.env.BRAINY_ALLOW_REMOTE_MODELS !== undefined) {
70
+ // 2. Environment variable override
71
+ localFilesOnly = process.env.BRAINY_ALLOW_REMOTE_MODELS !== 'true';
72
+ }
73
+ else if (process.env.NODE_ENV === 'development') {
74
+ // 3. Development mode allows remote models
75
+ localFilesOnly = false;
76
+ }
77
+ else if (isBrowser()) {
78
+ // 4. Browser defaults to allowing remote models
79
+ localFilesOnly = false;
80
+ }
81
+ else {
82
+ // 5. Node.js production: try local first, but allow remote as fallback
83
+ // This is the NEW production-friendly default
84
+ localFilesOnly = false;
85
+ }
62
86
  this.options = {
63
87
  model: options.model || 'Xenova/all-MiniLM-L6-v2',
64
88
  verbose: this.verbose,
65
- cacheDir: options.cacheDir || './models', // Will be resolved async in init()
66
- localFilesOnly: options.localFilesOnly !== undefined ? options.localFilesOnly : !isBrowser(),
89
+ cacheDir: options.cacheDir || './models',
90
+ localFilesOnly: localFilesOnly,
67
91
  dtype: options.dtype || 'fp32',
68
92
  device: options.device || 'auto'
69
93
  };
94
+ if (this.verbose) {
95
+ this.logger('log', `Embedding config: localFilesOnly=${localFilesOnly}, model=${this.options.model}, cacheDir=${this.options.cacheDir}`);
96
+ }
70
97
  // Configure transformers.js environment
71
98
  if (!isBrowser()) {
72
99
  // Set cache directory for Node.js
@@ -198,7 +225,30 @@ export class TransformerEmbedding {
198
225
  this.extractor = await pipeline('feature-extraction', this.options.model, cpuOptions);
199
226
  }
200
227
  else {
201
- throw gpuError;
228
+ // PRODUCTION-READY ERROR HANDLING
229
+ // If local_files_only is true and models are missing, try enabling remote downloads
230
+ if (pipelineOptions.local_files_only && gpuError?.message?.includes('local_files_only')) {
231
+ this.logger('warn', 'Local models not found, attempting remote download as fallback...');
232
+ try {
233
+ const remoteOptions = { ...pipelineOptions, local_files_only: false };
234
+ this.extractor = await pipeline('feature-extraction', this.options.model, remoteOptions);
235
+ this.logger('log', '✅ Successfully downloaded and loaded model from remote');
236
+ // Update the configuration to reflect what actually worked
237
+ this.options.localFilesOnly = false;
238
+ }
239
+ catch (remoteError) {
240
+ // Both local and remote failed - throw comprehensive error
241
+ const errorMsg = `Failed to load embedding model "${this.options.model}". ` +
242
+ `Local models not found and remote download failed. ` +
243
+ `To fix: 1) Set BRAINY_ALLOW_REMOTE_MODELS=true, ` +
244
+ `2) Run "npm run download-models", or ` +
245
+ `3) Use a custom embedding function.`;
246
+ throw new Error(errorMsg);
247
+ }
248
+ }
249
+ else {
250
+ throw gpuError;
251
+ }
202
252
  }
203
253
  }
204
254
  const loadTime = Date.now() - startTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Multi-Dimensional AI Database - Vector similarity, graph relationships, metadata facets with HNSW indexing and OPFS storage",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -196,6 +196,8 @@
196
196
  "@vitejs/plugin-basic-ssl": "^2.1.0",
197
197
  "@vitest/coverage-v8": "^3.2.4",
198
198
  "@vitest/ui": "^3.2.4",
199
+ "aws-sdk-client-mock": "^4.1.0",
200
+ "aws-sdk-client-mock-jest": "^4.1.0",
199
201
  "buffer": "^6.0.3",
200
202
  "crypto-browserify": "^3.12.1",
201
203
  "eslint": "^9.0.0",