@soulcraft/brainy 0.54.3 → 0.54.4

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.
@@ -803,20 +803,30 @@ export class BrainyData {
803
803
  try {
804
804
  const testResult = await this.storage.getNouns({ pagination: { offset: 0, limit: 1 } });
805
805
  if (testResult.items.length > 0) {
806
- if (this.loggingConfig?.verbose) {
807
- console.log('Rebuilding metadata index for existing data...');
806
+ // Only rebuild metadata index if explicitly requested or if we have very few items
807
+ const shouldRebuild = process.env.BRAINY_REBUILD_INDEX === 'true';
808
+ if (shouldRebuild) {
809
+ if (this.loggingConfig?.verbose) {
810
+ console.log('🔄 Rebuilding metadata index for existing data...');
811
+ }
812
+ await this.metadataIndex.rebuild();
813
+ if (this.loggingConfig?.verbose) {
814
+ const newStats = await this.metadataIndex.getStats();
815
+ console.log(`✅ Metadata index rebuilt: ${newStats.totalEntries} entries, ${newStats.fieldsIndexed.length} fields`);
816
+ }
808
817
  }
809
- await this.metadataIndex.rebuild();
810
- if (this.loggingConfig?.verbose) {
811
- const newStats = await this.metadataIndex.getStats();
812
- console.log(`Metadata index rebuilt: ${newStats.totalEntries} entries, ${newStats.fieldsIndexed.length} fields`);
818
+ else {
819
+ if (this.loggingConfig?.verbose) {
820
+ console.log('⏭️ Skipping metadata index rebuild (set BRAINY_REBUILD_INDEX=true to force)');
821
+ }
822
+ // Build index incrementally as items are accessed instead
813
823
  }
814
824
  }
815
825
  }
816
826
  catch (error) {
817
827
  // If getNouns fails, skip rebuild
818
828
  if (this.loggingConfig?.verbose) {
819
- console.log('Skipping metadata index rebuild:', error);
829
+ console.log('⚠️ Skipping metadata index rebuild due to error:', error);
820
830
  }
821
831
  }
822
832
  }