@soulcraft/brainy 0.54.3 → 0.54.5
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.
- package/dist/brainyData.js +30 -19
- package/dist/brainyData.js.map +1 -1
- package/dist/coreTypes.d.ts +6 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +31 -1
- package/dist/storage/adapters/s3CompatibleStorage.js +275 -127
- package/dist/storage/adapters/s3CompatibleStorage.js.map +1 -1
- package/dist/utils/environment.d.ts +12 -0
- package/dist/utils/environment.js +90 -0
- package/dist/utils/environment.js.map +1 -1
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.js +91 -3
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/metadataIndex.d.ts +7 -1
- package/dist/utils/metadataIndex.js +145 -20
- package/dist/utils/metadataIndex.js.map +1 -1
- package/dist/utils/workerUtils.js.map +1 -1
- package/package.json +1 -1
package/dist/brainyData.js
CHANGED
|
@@ -14,6 +14,7 @@ import { NounType, VerbType } from './types/graphTypes.js';
|
|
|
14
14
|
import { createServerSearchAugmentations } from './augmentations/serverSearchAugmentations.js';
|
|
15
15
|
import { IntelligentVerbScoring } from './augmentations/intelligentVerbScoring.js';
|
|
16
16
|
import { augmentationPipeline } from './augmentationPipeline.js';
|
|
17
|
+
import { prodLog } from './utils/logger.js';
|
|
17
18
|
import { prepareJsonForVectorization, extractFieldFromJson } from './utils/jsonProcessing.js';
|
|
18
19
|
import { DistributedConfigManager, HashPartitioner, OperationalModeFactory, DomainDetector, HealthMonitor } from './distributed/index.js';
|
|
19
20
|
import { SearchCache } from './utils/searchCache.js';
|
|
@@ -197,7 +198,7 @@ export class BrainyData {
|
|
|
197
198
|
};
|
|
198
199
|
}
|
|
199
200
|
if (this.loggingConfig?.verbose) {
|
|
200
|
-
|
|
201
|
+
prodLog.info(this.cacheAutoConfigurator.getConfigExplanation(autoConfig));
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
// Initialize search cache with final configuration
|
|
@@ -252,7 +253,7 @@ export class BrainyData {
|
|
|
252
253
|
// If the database is frozen, do not start real-time updates
|
|
253
254
|
if (this.frozen) {
|
|
254
255
|
if (this.loggingConfig?.verbose) {
|
|
255
|
-
|
|
256
|
+
prodLog.info('Real-time updates disabled: database is frozen');
|
|
256
257
|
}
|
|
257
258
|
return;
|
|
258
259
|
}
|
|
@@ -266,16 +267,16 @@ export class BrainyData {
|
|
|
266
267
|
this.lastKnownNounCount = count;
|
|
267
268
|
})
|
|
268
269
|
.catch((error) => {
|
|
269
|
-
|
|
270
|
+
prodLog.warn('Failed to get initial noun count for real-time updates:', error);
|
|
270
271
|
});
|
|
271
272
|
// Start the update timer
|
|
272
273
|
this.updateTimerId = setInterval(() => {
|
|
273
274
|
this.checkForUpdates().catch((error) => {
|
|
274
|
-
|
|
275
|
+
prodLog.warn('Error during real-time update check:', error);
|
|
275
276
|
});
|
|
276
277
|
}, this.realtimeUpdateConfig.interval);
|
|
277
278
|
if (this.loggingConfig?.verbose) {
|
|
278
|
-
|
|
279
|
+
prodLog.info(`Real-time updates started with interval: ${this.realtimeUpdateConfig.interval}ms`);
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
282
|
/**
|
|
@@ -290,7 +291,7 @@ export class BrainyData {
|
|
|
290
291
|
clearInterval(this.updateTimerId);
|
|
291
292
|
this.updateTimerId = null;
|
|
292
293
|
if (this.loggingConfig?.verbose) {
|
|
293
|
-
|
|
294
|
+
prodLog.info('Real-time updates stopped');
|
|
294
295
|
}
|
|
295
296
|
}
|
|
296
297
|
/**
|
|
@@ -332,7 +333,7 @@ export class BrainyData {
|
|
|
332
333
|
await this.metadataIndex.flush();
|
|
333
334
|
}
|
|
334
335
|
catch (error) {
|
|
335
|
-
|
|
336
|
+
prodLog.warn('Error flushing metadata index:', error);
|
|
336
337
|
}
|
|
337
338
|
}, 30000); // Flush every 30 seconds
|
|
338
339
|
// Store the interval ID for cleanup
|
|
@@ -394,7 +395,7 @@ export class BrainyData {
|
|
|
394
395
|
// Cleanup expired cache entries (defensive mechanism for distributed scenarios)
|
|
395
396
|
const expiredCount = this.searchCache.cleanupExpiredEntries();
|
|
396
397
|
if (expiredCount > 0 && this.loggingConfig?.verbose) {
|
|
397
|
-
|
|
398
|
+
prodLog.debug(`Cleaned up ${expiredCount} expired cache entries`);
|
|
398
399
|
}
|
|
399
400
|
// Adapt cache configuration based on performance (every few updates)
|
|
400
401
|
// Only adapt every 5th update to avoid over-optimization
|
|
@@ -407,11 +408,11 @@ export class BrainyData {
|
|
|
407
408
|
this.lastUpdateTime = Date.now();
|
|
408
409
|
if (this.loggingConfig?.verbose) {
|
|
409
410
|
const duration = this.lastUpdateTime - startTime;
|
|
410
|
-
|
|
411
|
+
prodLog.debug(`Real-time update completed in ${duration}ms`);
|
|
411
412
|
}
|
|
412
413
|
}
|
|
413
414
|
catch (error) {
|
|
414
|
-
|
|
415
|
+
prodLog.error('Failed to check for updates:', error);
|
|
415
416
|
// Don't rethrow the error to avoid disrupting the update timer
|
|
416
417
|
}
|
|
417
418
|
}
|
|
@@ -437,7 +438,7 @@ export class BrainyData {
|
|
|
437
438
|
const noun = change.data;
|
|
438
439
|
// Check if the vector dimensions match the expected dimensions
|
|
439
440
|
if (noun.vector.length !== this._dimensions) {
|
|
440
|
-
|
|
441
|
+
prodLog.warn(`Skipping noun ${noun.id} due to dimension mismatch: expected ${this._dimensions}, got ${noun.vector.length}`);
|
|
441
442
|
continue;
|
|
442
443
|
}
|
|
443
444
|
// Add or update in index
|
|
@@ -452,7 +453,7 @@ export class BrainyData {
|
|
|
452
453
|
updatedCount++;
|
|
453
454
|
}
|
|
454
455
|
if (this.loggingConfig?.verbose) {
|
|
455
|
-
|
|
456
|
+
prodLog.debug(`${change.operation === 'add' ? 'Added' : 'Updated'} noun ${noun.id} in index during real-time update`);
|
|
456
457
|
}
|
|
457
458
|
}
|
|
458
459
|
break;
|
|
@@ -803,20 +804,30 @@ export class BrainyData {
|
|
|
803
804
|
try {
|
|
804
805
|
const testResult = await this.storage.getNouns({ pagination: { offset: 0, limit: 1 } });
|
|
805
806
|
if (testResult.items.length > 0) {
|
|
806
|
-
if
|
|
807
|
-
|
|
807
|
+
// Only rebuild metadata index if explicitly requested or if we have very few items
|
|
808
|
+
const shouldRebuild = process.env.BRAINY_REBUILD_INDEX === 'true';
|
|
809
|
+
if (shouldRebuild) {
|
|
810
|
+
if (this.loggingConfig?.verbose) {
|
|
811
|
+
console.log('🔄 Rebuilding metadata index for existing data...');
|
|
812
|
+
}
|
|
813
|
+
await this.metadataIndex.rebuild();
|
|
814
|
+
if (this.loggingConfig?.verbose) {
|
|
815
|
+
const newStats = await this.metadataIndex.getStats();
|
|
816
|
+
console.log(`✅ Metadata index rebuilt: ${newStats.totalEntries} entries, ${newStats.fieldsIndexed.length} fields`);
|
|
817
|
+
}
|
|
808
818
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
819
|
+
else {
|
|
820
|
+
if (this.loggingConfig?.verbose) {
|
|
821
|
+
console.log('⏭️ Skipping metadata index rebuild (set BRAINY_REBUILD_INDEX=true to force)');
|
|
822
|
+
}
|
|
823
|
+
// Build index incrementally as items are accessed instead
|
|
813
824
|
}
|
|
814
825
|
}
|
|
815
826
|
}
|
|
816
827
|
catch (error) {
|
|
817
828
|
// If getNouns fails, skip rebuild
|
|
818
829
|
if (this.loggingConfig?.verbose) {
|
|
819
|
-
console.log('Skipping metadata index rebuild:', error);
|
|
830
|
+
console.log('⚠️ Skipping metadata index rebuild due to error:', error);
|
|
820
831
|
}
|
|
821
832
|
}
|
|
822
833
|
}
|