diff --git a/src/graph/graphAdjacencyIndex.ts b/src/graph/graphAdjacencyIndex.ts index bf0963af..af58c5cf 100644 --- a/src/graph/graphAdjacencyIndex.ts +++ b/src/graph/graphAdjacencyIndex.ts @@ -568,6 +568,8 @@ export class GraphAdjacencyIndex { // Clear current index this.verbIdSet.clear() this.totalRelationshipsIndexed = 0 + // v6.2.4: CRITICAL FIX - Clear relationship counts to prevent accumulation + this.relationshipCountsByType.clear() // Note: LSM-trees will be recreated from storage via their own initialization // Verb data will be loaded on-demand via UnifiedCache diff --git a/src/utils/metadataIndex.ts b/src/utils/metadataIndex.ts index 70223374..b0b92105 100644 --- a/src/utils/metadataIndex.ts +++ b/src/utils/metadataIndex.ts @@ -381,6 +381,12 @@ export class MetadataIndexManager { */ private async lazyLoadCounts(): Promise { try { + // v6.2.4: CRITICAL FIX - Clear counts before loading to prevent accumulation + // Previously, counts accumulated across restarts causing 100x inflation + this.totalEntitiesByType.clear() + this.entityCountsByTypeFixed.fill(0) + this.verbCountsByTypeFixed.fill(0) + // v6.2.2: Load counts from sparse index (correct source) const nounSparseIndex = await this.loadSparseIndex('noun') if (!nounSparseIndex) { @@ -2501,6 +2507,13 @@ export class MetadataIndexManager { this.fieldIndexes.clear() this.dirtyFields.clear() + // v6.2.4: CRITICAL FIX - Clear type counts to prevent accumulation + // Previously, counts accumulated across rebuilds causing incorrect values + this.totalEntitiesByType.clear() + this.entityCountsByTypeFixed.fill(0) + this.verbCountsByTypeFixed.fill(0) + this.typeFieldAffinity.clear() + // Clear all cached sparse indices in UnifiedCache // This ensures rebuild starts fresh (v3.44.1) this.unifiedCache.clear('metadata')