@soulcraft/brainy 5.3.6 → 5.5.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +4 -3
  3. package/dist/augmentations/display/fieldPatterns.js +3 -3
  4. package/dist/augmentations/display/intelligentComputation.js +0 -2
  5. package/dist/augmentations/typeMatching/brainyTypes.js +6 -8
  6. package/dist/brainy.d.ts +61 -0
  7. package/dist/brainy.js +180 -24
  8. package/dist/cortex/neuralImport.js +0 -1
  9. package/dist/importers/SmartExcelImporter.js +1 -1
  10. package/dist/index.d.ts +2 -2
  11. package/dist/neural/embeddedKeywordEmbeddings.d.ts +1 -1
  12. package/dist/neural/embeddedKeywordEmbeddings.js +56 -56
  13. package/dist/neural/embeddedTypeEmbeddings.d.ts +3 -3
  14. package/dist/neural/embeddedTypeEmbeddings.js +14 -14
  15. package/dist/neural/entityExtractor.js +2 -2
  16. package/dist/neural/relationshipConfidence.js +1 -1
  17. package/dist/neural/signals/VerbContextSignal.js +6 -6
  18. package/dist/neural/signals/VerbExactMatchSignal.js +9 -9
  19. package/dist/neural/signals/VerbPatternSignal.js +5 -5
  20. package/dist/query/typeAwareQueryPlanner.js +2 -3
  21. package/dist/storage/adapters/azureBlobStorage.d.ts +13 -64
  22. package/dist/storage/adapters/azureBlobStorage.js +78 -388
  23. package/dist/storage/adapters/fileSystemStorage.d.ts +12 -78
  24. package/dist/storage/adapters/fileSystemStorage.js +49 -395
  25. package/dist/storage/adapters/gcsStorage.d.ts +13 -134
  26. package/dist/storage/adapters/gcsStorage.js +79 -557
  27. package/dist/storage/adapters/historicalStorageAdapter.d.ts +181 -0
  28. package/dist/storage/adapters/historicalStorageAdapter.js +332 -0
  29. package/dist/storage/adapters/memoryStorage.d.ts +4 -113
  30. package/dist/storage/adapters/memoryStorage.js +34 -471
  31. package/dist/storage/adapters/opfsStorage.d.ts +14 -127
  32. package/dist/storage/adapters/opfsStorage.js +44 -693
  33. package/dist/storage/adapters/r2Storage.d.ts +8 -41
  34. package/dist/storage/adapters/r2Storage.js +49 -237
  35. package/dist/storage/adapters/s3CompatibleStorage.d.ts +13 -111
  36. package/dist/storage/adapters/s3CompatibleStorage.js +77 -596
  37. package/dist/storage/baseStorage.d.ts +78 -38
  38. package/dist/storage/baseStorage.js +692 -23
  39. package/dist/storage/cow/BlobStorage.d.ts +2 -2
  40. package/dist/storage/cow/BlobStorage.js +4 -4
  41. package/dist/storage/storageFactory.d.ts +2 -3
  42. package/dist/storage/storageFactory.js +114 -66
  43. package/dist/types/graphTypes.d.ts +588 -230
  44. package/dist/types/graphTypes.js +683 -248
  45. package/dist/types/typeMigration.d.ts +95 -0
  46. package/dist/types/typeMigration.js +141 -0
  47. package/dist/utils/intelligentTypeMapper.js +2 -2
  48. package/dist/utils/metadataIndex.js +6 -6
  49. package/dist/vfs/types.d.ts +6 -2
  50. package/package.json +2 -2
@@ -5,6 +5,7 @@
5
5
  import { GraphAdjacencyIndex } from '../graph/graphAdjacencyIndex.js';
6
6
  import { GraphVerb, HNSWNoun, HNSWVerb, NounMetadata, VerbMetadata, HNSWNounWithMetadata, HNSWVerbWithMetadata, StatisticsData } from '../coreTypes.js';
7
7
  import { BaseStorageAdapter } from './adapters/baseStorageAdapter.js';
8
+ import { NounType, VerbType } from '../types/graphTypes.js';
8
9
  import { RefManager } from './cow/RefManager.js';
9
10
  import { BlobStorage } from './cow/BlobStorage.js';
10
11
  import { CommitLog } from './cow/CommitLog.js';
@@ -56,6 +57,10 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
56
57
  commitLog?: CommitLog;
57
58
  currentBranch: string;
58
59
  protected cowEnabled: boolean;
60
+ protected nounCountsByType: Uint32Array<ArrayBuffer>;
61
+ protected verbCountsByType: Uint32Array<ArrayBuffer>;
62
+ protected nounTypeCache: Map<string, NounType>;
63
+ protected verbTypeCache: Map<string, VerbType>;
59
64
  /**
60
65
  * Analyze a storage key to determine its routing and path
61
66
  * @param id - The key to analyze (UUID or system key)
@@ -65,10 +70,12 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
65
70
  */
66
71
  private analyzeKey;
67
72
  /**
68
- * Initialize the storage adapter
69
- * This method should be implemented by each specific adapter
73
+ * Initialize the storage adapter (v5.4.0)
74
+ * Loads type statistics for built-in type-aware indexing
75
+ *
76
+ * IMPORTANT: If your adapter overrides init(), call await super.init() first!
70
77
  */
71
- abstract init(): Promise<void>;
78
+ init(): Promise<void>;
72
79
  /**
73
80
  * Ensure the storage adapter is initialized
74
81
  */
@@ -213,6 +220,27 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
213
220
  hasMore: boolean;
214
221
  nextCursor?: string;
215
222
  }>;
223
+ /**
224
+ * Get nouns with pagination (v5.4.0: Type-first implementation)
225
+ *
226
+ * CRITICAL: This method is required for brain.find() to work!
227
+ * Iterates through all noun types to find entities.
228
+ */
229
+ getNounsWithPagination(options: {
230
+ limit: number;
231
+ offset: number;
232
+ cursor?: string;
233
+ filter?: {
234
+ nounType?: string | string[];
235
+ service?: string | string[];
236
+ metadata?: Record<string, any>;
237
+ };
238
+ }): Promise<{
239
+ items: HNSWNounWithMetadata[];
240
+ totalCount: number;
241
+ hasMore: boolean;
242
+ nextCursor?: string;
243
+ }>;
216
244
  /**
217
245
  * Get verbs with pagination and filtering
218
246
  * @param options Pagination and filtering options
@@ -319,12 +347,12 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
319
347
  protected saveNounMetadata_internal(id: string, metadata: NounMetadata): Promise<void>;
320
348
  /**
321
349
  * Get noun metadata from storage (v4.0.0: now typed)
322
- * Uses routing logic to handle both UUIDs (sharded) and system keys (unsharded)
350
+ * v5.4.0: Uses type-first paths (must match saveNounMetadata_internal)
323
351
  */
324
352
  getNounMetadata(id: string): Promise<NounMetadata | null>;
325
353
  /**
326
354
  * Delete noun metadata from storage
327
- * Uses routing logic to handle both UUIDs (sharded) and system keys (unsharded)
355
+ * v5.4.0: Uses type-first paths (must match saveNounMetadata_internal)
328
356
  */
329
357
  deleteNounMetadata(id: string): Promise<void>;
330
358
  /**
@@ -334,7 +362,7 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
334
362
  saveVerbMetadata(id: string, metadata: VerbMetadata): Promise<void>;
335
363
  /**
336
364
  * Internal method for saving verb metadata (v4.0.0: now typed)
337
- * Uses routing logic to handle both UUIDs (sharded) and system keys (unsharded)
365
+ * v5.4.0: Uses type-first paths (must match getVerbMetadata)
338
366
  *
339
367
  * CRITICAL (v4.1.2): Count synchronization happens here
340
368
  * This ensures verb counts are updated AFTER metadata exists, fixing the race condition
@@ -347,64 +375,76 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
347
375
  protected saveVerbMetadata_internal(id: string, metadata: VerbMetadata): Promise<void>;
348
376
  /**
349
377
  * Get verb metadata from storage (v4.0.0: now typed)
350
- * Uses routing logic to handle both UUIDs (sharded) and system keys (unsharded)
378
+ * v5.4.0: Uses type-first paths (must match saveVerbMetadata_internal)
351
379
  */
352
380
  getVerbMetadata(id: string): Promise<VerbMetadata | null>;
353
381
  /**
354
382
  * Delete verb metadata from storage
355
- * Uses routing logic to handle both UUIDs (sharded) and system keys (unsharded)
383
+ * v5.4.0: Uses type-first paths (must match saveVerbMetadata_internal)
356
384
  */
357
385
  deleteVerbMetadata(id: string): Promise<void>;
358
386
  /**
359
- * Save a noun to storage
360
- * This method should be implemented by each specific adapter
387
+ * Load type statistics from storage
388
+ * Rebuilds type counts if needed (called during init)
361
389
  */
362
- protected abstract saveNoun_internal(noun: HNSWNoun): Promise<void>;
390
+ protected loadTypeStatistics(): Promise<void>;
363
391
  /**
364
- * Get a noun from storage
365
- * This method should be implemented by each specific adapter
392
+ * Save type statistics to storage
393
+ * Periodically called when counts are updated
366
394
  */
367
- protected abstract getNoun_internal(id: string): Promise<HNSWNoun | null>;
395
+ protected saveTypeStatistics(): Promise<void>;
368
396
  /**
369
- * Get nouns by noun type
370
- * This method should be implemented by each specific adapter
397
+ * Get noun type from cache or metadata
398
+ * Relies on nounTypeCache populated during metadata saves
371
399
  */
372
- protected abstract getNounsByNounType_internal(nounType: string): Promise<HNSWNoun[]>;
400
+ protected getNounType(noun: HNSWNoun): NounType;
373
401
  /**
374
- * Delete a noun from storage
375
- * This method should be implemented by each specific adapter
402
+ * Get verb type from verb object
403
+ * Verb type is a required field in HNSWVerb
376
404
  */
377
- protected abstract deleteNoun_internal(id: string): Promise<void>;
405
+ protected getVerbType(verb: HNSWVerb | GraphVerb): VerbType;
378
406
  /**
379
- * Save a verb to storage
380
- * This method should be implemented by each specific adapter
407
+ * Save a noun to storage (type-first path)
381
408
  */
382
- protected abstract saveVerb_internal(verb: HNSWVerb): Promise<void>;
409
+ protected saveNoun_internal(noun: HNSWNoun): Promise<void>;
383
410
  /**
384
- * Get a verb from storage
385
- * This method should be implemented by each specific adapter
411
+ * Get a noun from storage (type-first path)
386
412
  */
387
- protected abstract getVerb_internal(id: string): Promise<HNSWVerb | null>;
413
+ protected getNoun_internal(id: string): Promise<HNSWNoun | null>;
388
414
  /**
389
- * Get verbs by source
390
- * This method should be implemented by each specific adapter
415
+ * Get nouns by noun type (O(1) with type-first paths!)
391
416
  */
392
- protected abstract getVerbsBySource_internal(sourceId: string): Promise<HNSWVerbWithMetadata[]>;
417
+ protected getNounsByNounType_internal(nounType: string): Promise<HNSWNoun[]>;
393
418
  /**
394
- * Get verbs by target
395
- * This method should be implemented by each specific adapter
419
+ * Delete a noun from storage (type-first path)
396
420
  */
397
- protected abstract getVerbsByTarget_internal(targetId: string): Promise<HNSWVerbWithMetadata[]>;
421
+ protected deleteNoun_internal(id: string): Promise<void>;
398
422
  /**
399
- * Get verbs by type
400
- * This method should be implemented by each specific adapter
423
+ * Save a verb to storage (type-first path)
401
424
  */
402
- protected abstract getVerbsByType_internal(type: string): Promise<HNSWVerbWithMetadata[]>;
425
+ protected saveVerb_internal(verb: HNSWVerb): Promise<void>;
403
426
  /**
404
- * Delete a verb from storage
405
- * This method should be implemented by each specific adapter
427
+ * Get a verb from storage (type-first path)
428
+ */
429
+ protected getVerb_internal(id: string): Promise<HNSWVerb | null>;
430
+ /**
431
+ * Get verbs by source (COW-aware implementation)
432
+ * v5.4.0: Fixed to directly list verb files instead of directories
433
+ */
434
+ protected getVerbsBySource_internal(sourceId: string): Promise<HNSWVerbWithMetadata[]>;
435
+ /**
436
+ * Get verbs by target (COW-aware implementation)
437
+ * v5.4.0: Fixed to directly list verb files instead of directories
438
+ */
439
+ protected getVerbsByTarget_internal(targetId: string): Promise<HNSWVerbWithMetadata[]>;
440
+ /**
441
+ * Get verbs by type (O(1) with type-first paths!)
442
+ */
443
+ protected getVerbsByType_internal(verbType: string): Promise<HNSWVerbWithMetadata[]>;
444
+ /**
445
+ * Delete a verb from storage (type-first path)
406
446
  */
407
- protected abstract deleteVerb_internal(id: string): Promise<void>;
447
+ protected deleteVerb_internal(id: string): Promise<void>;
408
448
  /**
409
449
  * Helper method to convert a Map to a plain object for serialization
410
450
  */