brainy/src/storage/adapters
David Snelling a21a84545a fix: populate totalNodes/totalEdges in ALL storage adapters for HNSW rebuild
Critical fix for v3.37.1 GCS persistence bug where HNSW rebuild reported
"Preloading 0 vectors" and hung indefinitely during container restarts.

Root Cause:
HNSW rebuild (hnswIndex.ts:835) calls storage.getStatistics() and expects
stats.totalNodes to determine entity count for adaptive caching. When
totalNodes was undefined, entityCount evaluated to 0, causing HNSW to
report "0 vectors" and hang waiting for entities that it couldn't find.

Fixes Applied:
- GcsStorage: Populate totalNodes/totalEdges from this.totalNounCount/totalVerbCount
- MemoryStorage: Populate totalNodes/totalEdges from in-memory counts
- OPFSStorage: Populate totalNodes/totalEdges in ALL return paths (cache, current day, yesterday, legacy)
- S3CompatibleStorage: Populate totalNodes/totalEdges in ALL return paths (cache, fresh stats, error fallback)

Impact:
-  GCS container restarts now work correctly
-  HNSW rebuild correctly detects entity count
-  Adaptive caching strategy works as designed
-  All storage adapters now consistent

Files exist in GCS, counts load correctly, but HNSW couldn't see them
because getStatisticsData() didn't populate the totalNodes field that
HNSW depends on.

Closes: BRAINY_V3_37_1_INDEX_REBUILD_BUG.md
Related: v3.37.0 (metadata reconstruction), v3.37.1 (getNoun_internal fix)
2025-10-10 17:48:40 -07:00
..
baseStorageAdapter.ts feat: implement HNSW index rebuild and unified index interface 2025-10-10 11:15:17 -07:00
batchS3Operations.ts 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00
fileSystemStorage.ts fix: combine vector and metadata in getNoun/getVerb internal methods 2025-10-10 16:51:59 -07:00
gcsStorage.ts fix: populate totalNodes/totalEdges in ALL storage adapters for HNSW rebuild 2025-10-10 17:48:40 -07:00
memoryStorage.ts fix: populate totalNodes/totalEdges in ALL storage adapters for HNSW rebuild 2025-10-10 17:48:40 -07:00
opfsStorage.ts fix: populate totalNodes/totalEdges in ALL storage adapters for HNSW rebuild 2025-10-10 17:48:40 -07:00
optimizedS3Search.ts 🧠 Brainy 2.0.0 - Zero-Configuration AI Database with Triple Intelligence™ 2025-08-26 12:32:21 -07:00
s3CompatibleStorage.ts fix: populate totalNodes/totalEdges in ALL storage adapters for HNSW rebuild 2025-10-10 17:48:40 -07:00