@soulcraft/brainy 3.37.3 → 3.37.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.
@@ -1349,13 +1349,17 @@ export class FileSystemStorage extends BaseStorage {
1349
1349
  mergeStatistics(storageStats, localStats) {
1350
1350
  // Handle null cases
1351
1351
  if (!storageStats && !localStats) {
1352
+ // CRITICAL FIX (v3.37.4): Statistics files don't exist yet (first init)
1353
+ // Return minimal stats with counts instead of zeros
1354
+ // This prevents HNSW from seeing entityCount=0 during index rebuild
1352
1355
  return {
1353
1356
  nounCount: {},
1354
1357
  verbCount: {},
1355
1358
  metadataCount: {},
1356
1359
  hnswIndexSize: 0,
1357
- totalNodes: 0,
1358
- totalEdges: 0,
1360
+ totalNodes: this.totalNounCount,
1361
+ totalEdges: this.totalVerbCount,
1362
+ totalMetadata: 0,
1359
1363
  lastUpdated: new Date().toISOString()
1360
1364
  };
1361
1365
  }
@@ -1188,8 +1188,20 @@ export class GcsStorage extends BaseStorage {
1188
1188
  }
1189
1189
  catch (error) {
1190
1190
  if (error.code === 404) {
1191
- this.logger.trace('Statistics not found (creating new)');
1192
- return null;
1191
+ // CRITICAL FIX (v3.37.4): Statistics file doesn't exist yet (first restart)
1192
+ // Return minimal stats with counts instead of null
1193
+ // This prevents HNSW from seeing entityCount=0 during index rebuild
1194
+ this.logger.trace('Statistics file not found - returning minimal stats with counts');
1195
+ return {
1196
+ nounCount: {},
1197
+ verbCount: {},
1198
+ metadataCount: {},
1199
+ hnswIndexSize: 0,
1200
+ totalNodes: this.totalNounCount,
1201
+ totalEdges: this.totalVerbCount,
1202
+ totalMetadata: 0,
1203
+ lastUpdated: new Date().toISOString()
1204
+ };
1193
1205
  }
1194
1206
  this.logger.error('Failed to get statistics:', error);
1195
1207
  return null;
@@ -551,7 +551,19 @@ export class MemoryStorage extends BaseStorage {
551
551
  */
552
552
  async getStatisticsData() {
553
553
  if (!this.statistics) {
554
- return null;
554
+ // CRITICAL FIX (v3.37.4): Statistics don't exist yet (first init)
555
+ // Return minimal stats with counts instead of null
556
+ // This prevents HNSW from seeing entityCount=0 during index rebuild
557
+ return {
558
+ nounCount: {},
559
+ verbCount: {},
560
+ metadataCount: {},
561
+ hnswIndexSize: 0,
562
+ totalNodes: this.totalNounCount,
563
+ totalEdges: this.totalVerbCount,
564
+ totalMetadata: 0,
565
+ lastUpdated: new Date().toISOString()
566
+ };
555
567
  }
556
568
  // Return a deep copy to avoid reference issues
557
569
  return {
@@ -1212,13 +1212,36 @@ export class OPFSStorage extends BaseStorage {
1212
1212
  }
1213
1213
  }
1214
1214
  catch (error) {
1215
- // If the legacy file doesn't exist either, return null
1216
- return null;
1215
+ // CRITICAL FIX (v3.37.4): No statistics files exist (first init)
1216
+ // Return minimal stats with counts instead of null
1217
+ // This prevents HNSW from seeing entityCount=0 during index rebuild
1218
+ return {
1219
+ nounCount: {},
1220
+ verbCount: {},
1221
+ metadataCount: {},
1222
+ hnswIndexSize: 0,
1223
+ totalNodes: this.totalNounCount,
1224
+ totalEdges: this.totalVerbCount,
1225
+ totalMetadata: 0,
1226
+ lastUpdated: new Date().toISOString()
1227
+ };
1217
1228
  }
1218
1229
  }
1219
1230
  }
1220
- // If we get here and statistics is null, return default statistics
1221
- return this.statistics ? this.statistics : null;
1231
+ // If we get here and statistics is null, return minimal stats with counts
1232
+ if (!this.statistics) {
1233
+ return {
1234
+ nounCount: {},
1235
+ verbCount: {},
1236
+ metadataCount: {},
1237
+ hnswIndexSize: 0,
1238
+ totalNodes: this.totalNounCount,
1239
+ totalEdges: this.totalVerbCount,
1240
+ totalMetadata: 0,
1241
+ lastUpdated: new Date().toISOString()
1242
+ };
1243
+ }
1244
+ return this.statistics;
1222
1245
  }
1223
1246
  catch (error) {
1224
1247
  console.error('Failed to get statistics data:', error);
@@ -2198,6 +2198,19 @@ export class S3CompatibleStorage extends BaseStorage {
2198
2198
  totalEdges: this.totalVerbCount
2199
2199
  };
2200
2200
  }
2201
+ // If we get here and statistics is null, return minimal stats with counts
2202
+ if (!statistics) {
2203
+ return {
2204
+ nounCount: {},
2205
+ verbCount: {},
2206
+ metadataCount: {},
2207
+ hnswIndexSize: 0,
2208
+ totalNodes: this.totalNounCount,
2209
+ totalEdges: this.totalVerbCount,
2210
+ totalMetadata: 0,
2211
+ lastUpdated: new Date().toISOString()
2212
+ };
2213
+ }
2201
2214
  // Successfully loaded statistics from storage
2202
2215
  return statistics;
2203
2216
  }
@@ -2212,7 +2225,19 @@ export class S3CompatibleStorage extends BaseStorage {
2212
2225
  totalEdges: this.totalVerbCount
2213
2226
  };
2214
2227
  }
2215
- return null;
2228
+ // CRITICAL FIX (v3.37.4): Statistics file doesn't exist yet (first restart)
2229
+ // Return minimal stats with counts instead of null
2230
+ // This prevents HNSW from seeing entityCount=0 during index rebuild
2231
+ return {
2232
+ nounCount: {},
2233
+ verbCount: {},
2234
+ metadataCount: {},
2235
+ hnswIndexSize: 0,
2236
+ totalNodes: this.totalNounCount,
2237
+ totalEdges: this.totalVerbCount,
2238
+ totalMetadata: 0,
2239
+ lastUpdated: new Date().toISOString()
2240
+ };
2216
2241
  }
2217
2242
  }
2218
2243
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "3.37.3",
3
+ "version": "3.37.4",
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",