@soulcraft/brainy 3.50.2 → 4.0.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 (57) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/README.md +358 -658
  3. package/dist/api/ConfigAPI.js +56 -19
  4. package/dist/api/DataAPI.js +24 -18
  5. package/dist/augmentations/storageAugmentations.d.ts +24 -0
  6. package/dist/augmentations/storageAugmentations.js +22 -0
  7. package/dist/brainy.js +32 -9
  8. package/dist/cli/commands/core.d.ts +20 -10
  9. package/dist/cli/commands/core.js +384 -82
  10. package/dist/cli/commands/import.d.ts +41 -0
  11. package/dist/cli/commands/import.js +456 -0
  12. package/dist/cli/commands/insights.d.ts +34 -0
  13. package/dist/cli/commands/insights.js +300 -0
  14. package/dist/cli/commands/neural.d.ts +6 -12
  15. package/dist/cli/commands/neural.js +113 -10
  16. package/dist/cli/commands/nlp.d.ts +28 -0
  17. package/dist/cli/commands/nlp.js +246 -0
  18. package/dist/cli/commands/storage.d.ts +64 -0
  19. package/dist/cli/commands/storage.js +730 -0
  20. package/dist/cli/index.js +210 -24
  21. package/dist/coreTypes.d.ts +206 -34
  22. package/dist/distributed/configManager.js +8 -6
  23. package/dist/distributed/shardMigration.js +2 -0
  24. package/dist/distributed/storageDiscovery.js +6 -4
  25. package/dist/embeddings/EmbeddingManager.d.ts +2 -2
  26. package/dist/embeddings/EmbeddingManager.js +5 -1
  27. package/dist/graph/lsm/LSMTree.js +32 -20
  28. package/dist/hnsw/typeAwareHNSWIndex.js +6 -2
  29. package/dist/storage/adapters/azureBlobStorage.d.ts +545 -0
  30. package/dist/storage/adapters/azureBlobStorage.js +1809 -0
  31. package/dist/storage/adapters/baseStorageAdapter.d.ts +16 -13
  32. package/dist/storage/adapters/fileSystemStorage.d.ts +21 -9
  33. package/dist/storage/adapters/fileSystemStorage.js +204 -127
  34. package/dist/storage/adapters/gcsStorage.d.ts +119 -9
  35. package/dist/storage/adapters/gcsStorage.js +317 -62
  36. package/dist/storage/adapters/memoryStorage.d.ts +30 -18
  37. package/dist/storage/adapters/memoryStorage.js +99 -94
  38. package/dist/storage/adapters/opfsStorage.d.ts +48 -10
  39. package/dist/storage/adapters/opfsStorage.js +201 -80
  40. package/dist/storage/adapters/r2Storage.d.ts +12 -5
  41. package/dist/storage/adapters/r2Storage.js +63 -15
  42. package/dist/storage/adapters/s3CompatibleStorage.d.ts +164 -17
  43. package/dist/storage/adapters/s3CompatibleStorage.js +472 -80
  44. package/dist/storage/adapters/typeAwareStorageAdapter.d.ts +38 -6
  45. package/dist/storage/adapters/typeAwareStorageAdapter.js +218 -39
  46. package/dist/storage/baseStorage.d.ts +41 -38
  47. package/dist/storage/baseStorage.js +110 -134
  48. package/dist/storage/storageFactory.d.ts +29 -2
  49. package/dist/storage/storageFactory.js +30 -1
  50. package/dist/utils/entityIdMapper.js +5 -2
  51. package/dist/utils/fieldTypeInference.js +8 -1
  52. package/dist/utils/metadataFilter.d.ts +3 -2
  53. package/dist/utils/metadataFilter.js +1 -0
  54. package/dist/utils/metadataIndex.js +2 -0
  55. package/dist/utils/metadataIndexChunking.js +9 -4
  56. package/dist/utils/periodicCleanup.js +1 -0
  57. package/package.json +3 -1
@@ -3,19 +3,11 @@
3
3
  * Uses the AWS S3 client to interact with S3-compatible storage services
4
4
  * including Amazon S3, Cloudflare R2, and Google Cloud Storage
5
5
  */
6
- import { GraphVerb, HNSWNoun, HNSWVerb, StatisticsData } from '../../coreTypes.js';
6
+ import { Change, HNSWNoun, HNSWVerb, HNSWNounWithMetadata, HNSWVerbWithMetadata, StatisticsData } from '../../coreTypes.js';
7
7
  import { BaseStorage } from '../baseStorage.js';
8
8
  import { OperationConfig } from '../../utils/operationUtils.js';
9
9
  type HNSWNode = HNSWNoun;
10
10
  type Edge = HNSWVerb;
11
- interface ChangeLogEntry {
12
- timestamp: number;
13
- operation: 'add' | 'update' | 'delete';
14
- entityType: 'noun' | 'verb' | 'metadata';
15
- entityId: string;
16
- data?: any;
17
- instanceId?: string;
18
- }
19
11
  /**
20
12
  * S3-compatible storage adapter for server environments
21
13
  * Uses the AWS S3 client to interact with S3-compatible storage services
@@ -221,7 +213,8 @@ export declare class S3CompatibleStorage extends BaseStorage {
221
213
  protected saveNode(node: HNSWNode): Promise<void>;
222
214
  /**
223
215
  * Get a noun from storage (internal implementation)
224
- * Combines vector data from getNode() with metadata from getNounMetadata()
216
+ * v4.0.0: Returns ONLY vector data (no metadata field)
217
+ * Base class combines with metadata via getNoun() -> HNSWNounWithMetadata
225
218
  */
226
219
  protected getNoun_internal(id: string): Promise<HNSWNoun | null>;
227
220
  /**
@@ -297,7 +290,8 @@ export declare class S3CompatibleStorage extends BaseStorage {
297
290
  protected saveEdge(edge: Edge): Promise<void>;
298
291
  /**
299
292
  * Get a verb from storage (internal implementation)
300
- * Combines vector data from getEdge() with metadata from getVerbMetadata()
293
+ * v4.0.0: Returns ONLY vector + core relational fields (no metadata field)
294
+ * Base class combines with metadata via getVerb() -> HNSWVerbWithMetadata
301
295
  */
302
296
  protected getVerb_internal(id: string): Promise<HNSWVerb | null>;
303
297
  /**
@@ -352,7 +346,7 @@ export declare class S3CompatibleStorage extends BaseStorage {
352
346
  metadata?: Record<string, any>;
353
347
  };
354
348
  }): Promise<{
355
- items: GraphVerb[];
349
+ items: HNSWVerbWithMetadata[];
356
350
  totalCount?: number;
357
351
  hasMore: boolean;
358
352
  nextCursor?: string;
@@ -360,15 +354,15 @@ export declare class S3CompatibleStorage extends BaseStorage {
360
354
  /**
361
355
  * Get verbs by source (internal implementation)
362
356
  */
363
- protected getVerbsBySource_internal(sourceId: string): Promise<GraphVerb[]>;
357
+ protected getVerbsBySource_internal(sourceId: string): Promise<HNSWVerbWithMetadata[]>;
364
358
  /**
365
359
  * Get verbs by target (internal implementation)
366
360
  */
367
- protected getVerbsByTarget_internal(targetId: string): Promise<GraphVerb[]>;
361
+ protected getVerbsByTarget_internal(targetId: string): Promise<HNSWVerbWithMetadata[]>;
368
362
  /**
369
363
  * Get verbs by type (internal implementation)
370
364
  */
371
- protected getVerbsByType_internal(type: string): Promise<GraphVerb[]>;
365
+ protected getVerbsByType_internal(type: string): Promise<HNSWVerbWithMetadata[]>;
372
366
  /**
373
367
  * Delete a verb from storage (internal implementation)
374
368
  */
@@ -392,6 +386,28 @@ export declare class S3CompatibleStorage extends BaseStorage {
392
386
  * All metadata operations use this internally via base class routing
393
387
  */
394
388
  protected deleteObjectFromPath(path: string): Promise<void>;
389
+ /**
390
+ * Batch delete multiple objects from S3-compatible storage
391
+ * Deletes up to 1000 objects per batch (S3 limit)
392
+ * Handles throttling, retries, and partial failures
393
+ *
394
+ * @param keys - Array of object keys (paths) to delete
395
+ * @param options - Configuration options for batch deletion
396
+ * @returns Statistics about successful and failed deletions
397
+ */
398
+ batchDelete(keys: string[], options?: {
399
+ maxRetries?: number;
400
+ retryDelayMs?: number;
401
+ continueOnError?: boolean;
402
+ }): Promise<{
403
+ totalRequested: number;
404
+ successfulDeletes: number;
405
+ failedDeletes: number;
406
+ errors: Array<{
407
+ key: string;
408
+ error: string;
409
+ }>;
410
+ }>;
395
411
  /**
396
412
  * Primitive operation: List objects under path prefix
397
413
  * All metadata operations use this internally via base class routing
@@ -498,7 +514,7 @@ export declare class S3CompatibleStorage extends BaseStorage {
498
514
  * @param maxEntries Maximum number of entries to return (default: 1000)
499
515
  * @returns Array of change log entries
500
516
  */
501
- getChangesSince(sinceTimestamp: number, maxEntries?: number): Promise<ChangeLogEntry[]>;
517
+ getChangesSince(sinceTimestamp: number, maxEntries?: number): Promise<Change[]>;
502
518
  /**
503
519
  * Clean up old change log entries to prevent unlimited growth
504
520
  * @param olderThanTimestamp Remove entries older than this timestamp
@@ -542,7 +558,7 @@ export declare class S3CompatibleStorage extends BaseStorage {
542
558
  metadata?: Record<string, any>;
543
559
  };
544
560
  }): Promise<{
545
- items: HNSWNoun[];
561
+ items: HNSWNounWithMetadata[];
546
562
  totalCount?: number;
547
563
  hasMore: boolean;
548
564
  nextCursor?: string;
@@ -609,5 +625,136 @@ export declare class S3CompatibleStorage extends BaseStorage {
609
625
  entryPointId: string | null;
610
626
  maxLevel: number;
611
627
  } | null>;
628
+ /**
629
+ * Set S3 lifecycle policy for automatic tier transitions and deletions (v4.0.0)
630
+ * Automates cost optimization by moving old data to cheaper storage classes
631
+ *
632
+ * S3 Storage Classes:
633
+ * - Standard: $0.023/GB/month - Frequent access
634
+ * - Standard-IA: $0.0125/GB/month - Infrequent access (46% cheaper)
635
+ * - Glacier Instant: $0.004/GB/month - Archive with instant retrieval (83% cheaper)
636
+ * - Glacier Flexible: $0.0036/GB/month - Archive with 1-5 min retrieval (84% cheaper)
637
+ * - Glacier Deep Archive: $0.00099/GB/month - Long-term archive (96% cheaper!)
638
+ *
639
+ * @param options - Lifecycle policy configuration
640
+ * @returns Promise that resolves when policy is set
641
+ *
642
+ * @example
643
+ * // Auto-archive old vectors for 96% cost savings
644
+ * await storage.setLifecyclePolicy({
645
+ * rules: [
646
+ * {
647
+ * id: 'archive-old-vectors',
648
+ * prefix: 'entities/nouns/vectors/',
649
+ * status: 'Enabled',
650
+ * transitions: [
651
+ * { days: 30, storageClass: 'STANDARD_IA' },
652
+ * { days: 90, storageClass: 'GLACIER' },
653
+ * { days: 365, storageClass: 'DEEP_ARCHIVE' }
654
+ * ],
655
+ * expiration: { days: 730 }
656
+ * }
657
+ * ]
658
+ * })
659
+ */
660
+ setLifecyclePolicy(options: {
661
+ rules: Array<{
662
+ id: string;
663
+ prefix: string;
664
+ status: 'Enabled' | 'Disabled';
665
+ transitions?: Array<{
666
+ days: number;
667
+ storageClass: 'STANDARD_IA' | 'ONEZONE_IA' | 'INTELLIGENT_TIERING' | 'GLACIER' | 'DEEP_ARCHIVE' | 'GLACIER_IR';
668
+ }>;
669
+ expiration?: {
670
+ days: number;
671
+ };
672
+ }>;
673
+ }): Promise<void>;
674
+ /**
675
+ * Get the current S3 lifecycle policy
676
+ *
677
+ * @returns Promise that resolves to the current policy or null if not set
678
+ *
679
+ * @example
680
+ * const policy = await storage.getLifecyclePolicy()
681
+ * if (policy) {
682
+ * console.log(`Found ${policy.rules.length} lifecycle rules`)
683
+ * }
684
+ */
685
+ getLifecyclePolicy(): Promise<{
686
+ rules: Array<{
687
+ id: string;
688
+ prefix: string;
689
+ status: string;
690
+ transitions?: Array<{
691
+ days: number;
692
+ storageClass: string;
693
+ }>;
694
+ expiration?: {
695
+ days: number;
696
+ };
697
+ }>;
698
+ } | null>;
699
+ /**
700
+ * Remove the S3 lifecycle policy
701
+ * All automatic tier transitions and deletions will stop
702
+ *
703
+ * @returns Promise that resolves when policy is removed
704
+ *
705
+ * @example
706
+ * await storage.removeLifecyclePolicy()
707
+ * console.log('Lifecycle policy removed - auto-archival disabled')
708
+ */
709
+ removeLifecyclePolicy(): Promise<void>;
710
+ /**
711
+ * Enable S3 Intelligent-Tiering for automatic cost optimization (v4.0.0)
712
+ * Automatically moves objects between access tiers based on usage patterns
713
+ *
714
+ * Intelligent-Tiering automatically saves up to 95% on storage costs:
715
+ * - Frequent Access: $0.023/GB (same as Standard)
716
+ * - Infrequent Access: $0.0125/GB (after 30 days no access)
717
+ * - Archive Instant Access: $0.004/GB (after 90 days no access)
718
+ * - Archive Access: $0.0036/GB (after 180 days no access, optional)
719
+ * - Deep Archive Access: $0.00099/GB (after 180 days no access, optional)
720
+ *
721
+ * No retrieval fees, no operational overhead, automatic optimization!
722
+ *
723
+ * @param prefix - Object prefix to apply Intelligent-Tiering (e.g., 'entities/nouns/vectors/')
724
+ * @param configId - Configuration ID (default: 'brainy-intelligent-tiering')
725
+ * @returns Promise that resolves when configuration is set
726
+ *
727
+ * @example
728
+ * // Enable Intelligent-Tiering for all vectors
729
+ * await storage.enableIntelligentTiering('entities/')
730
+ */
731
+ enableIntelligentTiering(prefix?: string, configId?: string): Promise<void>;
732
+ /**
733
+ * Get S3 Intelligent-Tiering configurations
734
+ *
735
+ * @returns Promise that resolves to array of configurations
736
+ *
737
+ * @example
738
+ * const configs = await storage.getIntelligentTieringConfigs()
739
+ * for (const config of configs) {
740
+ * console.log(`Config: ${config.id}, Status: ${config.status}`)
741
+ * }
742
+ */
743
+ getIntelligentTieringConfigs(): Promise<Array<{
744
+ id: string;
745
+ status: string;
746
+ prefix?: string;
747
+ }>>;
748
+ /**
749
+ * Disable S3 Intelligent-Tiering
750
+ *
751
+ * @param configId - Configuration ID to remove (default: 'brainy-intelligent-tiering')
752
+ * @returns Promise that resolves when configuration is removed
753
+ *
754
+ * @example
755
+ * await storage.disableIntelligentTiering()
756
+ * console.log('Intelligent-Tiering disabled')
757
+ */
758
+ disableIntelligentTiering(configId?: string): Promise<void>;
612
759
  }
613
760
  export {};