@soulcraft/brainy 3.41.1 → 3.42.0

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.
@@ -29,6 +29,10 @@ export interface MetadataIndexConfig {
29
29
  indexedFields?: string[];
30
30
  excludeFields?: string[];
31
31
  }
32
+ /**
33
+ * Manages metadata indexes for fast filtering
34
+ * Maintains inverted indexes: field+value -> list of IDs
35
+ */
32
36
  interface CardinalityInfo {
33
37
  uniqueValues: number;
34
38
  totalValues: number;
@@ -42,22 +46,18 @@ interface FieldStats {
42
46
  rangeQueryCount: number;
43
47
  exactQueryCount: number;
44
48
  avgQueryTime: number;
45
- indexType: 'hash' | 'sorted' | 'both';
49
+ indexType: 'hash';
46
50
  normalizationStrategy?: 'none' | 'precision' | 'bucket';
47
51
  }
48
52
  export declare class MetadataIndexManager {
49
53
  private storage;
50
54
  private config;
51
- private indexCache;
52
- private dirtyEntries;
53
55
  private isRebuilding;
54
56
  private metadataCache;
55
57
  private fieldIndexes;
56
58
  private dirtyFields;
57
59
  private lastFlushTime;
58
60
  private autoFlushThreshold;
59
- private sortedIndices;
60
- private numericFields;
61
61
  private fieldStats;
62
62
  private cardinalityUpdateInterval;
63
63
  private operationCount;
@@ -70,6 +70,9 @@ export declare class MetadataIndexManager {
70
70
  private activeLocks;
71
71
  private lockPromises;
72
72
  private lockTimers;
73
+ private sparseIndices;
74
+ private chunkManager;
75
+ private chunkingStrategy;
73
76
  constructor(storage: StorageAdapter, config?: MetadataIndexConfig);
74
77
  /**
75
78
  * Acquire an in-memory lock for coordinating concurrent metadata index writes
@@ -92,60 +95,43 @@ export declare class MetadataIndexManager {
92
95
  */
93
96
  private lazyLoadCounts;
94
97
  /**
95
- * Get index key for field and value
96
- */
97
- private getIndexKey;
98
- /**
99
- * Ensure sorted index exists for a field (for range queries)
100
- */
101
- private ensureSortedIndex;
102
- /**
103
- * Build sorted index for a field from hash index
104
- */
105
- private buildSortedIndex;
106
- /**
107
- * Detect field type from value
108
- */
109
- private detectFieldType;
110
- /**
111
- * Compare two values based on field type for sorting
98
+ * Update cardinality statistics for a field
112
99
  */
113
- private compareValues;
100
+ private updateCardinalityStats;
114
101
  /**
115
- * Binary search to find insertion position for a value
116
- * Returns the index where the value should be inserted to maintain sorted order
102
+ * Analyze field distribution for optimization
117
103
  */
118
- private findInsertPosition;
104
+ private analyzeFieldDistribution;
119
105
  /**
120
- * Incrementally update sorted index when adding an ID
106
+ * Update index strategy based on field statistics
121
107
  */
122
- private updateSortedIndexAdd;
108
+ private updateIndexStrategy;
123
109
  /**
124
- * Incrementally update sorted index when removing an ID
110
+ * Load sparse index from storage
125
111
  */
126
- private updateSortedIndexRemove;
112
+ private loadSparseIndex;
127
113
  /**
128
- * Binary search for range start (inclusive or exclusive)
114
+ * Save sparse index to storage
129
115
  */
130
- private binarySearchStart;
116
+ private saveSparseIndex;
131
117
  /**
132
- * Binary search for range end (inclusive or exclusive)
118
+ * Get IDs for a value using chunked sparse index
133
119
  */
134
- private binarySearchEnd;
120
+ private getIdsFromChunks;
135
121
  /**
136
- * Update cardinality statistics for a field
122
+ * Get IDs for a range using chunked sparse index with zone maps
137
123
  */
138
- private updateCardinalityStats;
124
+ private getIdsFromChunksForRange;
139
125
  /**
140
- * Analyze field distribution for optimization
126
+ * Add value-ID mapping to chunked index
141
127
  */
142
- private analyzeFieldDistribution;
128
+ private addToChunkedIndex;
143
129
  /**
144
- * Update index strategy based on field statistics
130
+ * Remove ID from chunked index
145
131
  */
146
- private updateIndexStrategy;
132
+ private removeFromChunkedIndex;
147
133
  /**
148
- * Get IDs matching a range query
134
+ * Get IDs matching a range query using zone maps
149
135
  */
150
136
  private getIdsForRange;
151
137
  /**
@@ -193,7 +179,7 @@ export declare class MetadataIndexManager {
193
179
  */
194
180
  getAllIds(): Promise<string[]>;
195
181
  /**
196
- * Get IDs for a specific field-value combination with caching
182
+ * Get IDs for a specific field-value combination using chunked sparse index
197
183
  */
198
184
  getIds(field: string, value: any): Promise<string[]>;
199
185
  /**
@@ -223,6 +209,7 @@ export declare class MetadataIndexManager {
223
209
  getIdsForCriteria(criteria: Record<string, any>): Promise<string[]>;
224
210
  /**
225
211
  * Flush dirty entries to storage (non-blocking version)
212
+ * NOTE (v3.42.0): Sparse indices are flushed immediately in add/remove operations
226
213
  */
227
214
  flush(): Promise<void>;
228
215
  /**
@@ -238,14 +225,6 @@ export declare class MetadataIndexManager {
238
225
  * Save field index to storage with file locking
239
226
  */
240
227
  private saveFieldIndex;
241
- /**
242
- * Save sorted index to storage for range queries with file locking
243
- */
244
- private saveSortedIndex;
245
- /**
246
- * Load sorted index from storage
247
- */
248
- private loadSortedIndex;
249
228
  /**
250
229
  * Get count of entities by type - O(1) operation using existing tracking
251
230
  * This exposes the production-ready counting that's already maintained
@@ -260,7 +239,7 @@ export declare class MetadataIndexManager {
260
239
  */
261
240
  getAllEntityCounts(): Map<string, number>;
262
241
  /**
263
- * Get count of entities matching field-value criteria - O(1) lookup from existing indexes
242
+ * Get count of entities matching field-value criteria - queries chunked sparse index
264
243
  */
265
244
  getCountForCriteria(field: string, value: any): Promise<number>;
266
245
  /**
@@ -272,18 +251,6 @@ export declare class MetadataIndexManager {
272
251
  * Non-blocking version that yields control back to event loop
273
252
  */
274
253
  rebuild(): Promise<void>;
275
- /**
276
- * Load index entry from storage using safe filenames
277
- */
278
- private loadIndexEntry;
279
- /**
280
- * Save index entry to storage using safe filenames with file locking
281
- */
282
- private saveIndexEntry;
283
- /**
284
- * Delete index entry from storage using safe filenames
285
- */
286
- private deleteIndexEntry;
287
254
  /**
288
255
  * Get field statistics for optimization and discovery
289
256
  */