@soulcraft/brainy 1.4.0 → 2.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 (141) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/LICENSE +2 -2
  3. package/README.md +201 -596
  4. package/bin/brainy-interactive.js +564 -0
  5. package/bin/brainy-ts.js +18 -0
  6. package/bin/brainy.js +672 -81
  7. package/dist/augmentationPipeline.d.ts +48 -220
  8. package/dist/augmentationPipeline.js +60 -508
  9. package/dist/augmentationRegistry.d.ts +22 -31
  10. package/dist/augmentationRegistry.js +28 -79
  11. package/dist/augmentations/apiServerAugmentation.d.ts +108 -0
  12. package/dist/augmentations/apiServerAugmentation.js +502 -0
  13. package/dist/augmentations/batchProcessingAugmentation.d.ts +95 -0
  14. package/dist/augmentations/batchProcessingAugmentation.js +567 -0
  15. package/dist/augmentations/brainyAugmentation.d.ts +153 -0
  16. package/dist/augmentations/brainyAugmentation.js +145 -0
  17. package/dist/augmentations/cacheAugmentation.d.ts +105 -0
  18. package/dist/augmentations/cacheAugmentation.js +238 -0
  19. package/dist/augmentations/conduitAugmentations.d.ts +54 -156
  20. package/dist/augmentations/conduitAugmentations.js +156 -1082
  21. package/dist/augmentations/connectionPoolAugmentation.d.ts +62 -0
  22. package/dist/augmentations/connectionPoolAugmentation.js +316 -0
  23. package/dist/augmentations/defaultAugmentations.d.ts +53 -0
  24. package/dist/augmentations/defaultAugmentations.js +88 -0
  25. package/dist/augmentations/entityRegistryAugmentation.d.ts +126 -0
  26. package/dist/augmentations/entityRegistryAugmentation.js +386 -0
  27. package/dist/augmentations/indexAugmentation.d.ts +117 -0
  28. package/dist/augmentations/indexAugmentation.js +284 -0
  29. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +152 -0
  30. package/dist/augmentations/intelligentVerbScoringAugmentation.js +554 -0
  31. package/dist/augmentations/metricsAugmentation.d.ts +202 -0
  32. package/dist/augmentations/metricsAugmentation.js +291 -0
  33. package/dist/augmentations/monitoringAugmentation.d.ts +94 -0
  34. package/dist/augmentations/monitoringAugmentation.js +227 -0
  35. package/dist/augmentations/neuralImport.d.ts +50 -117
  36. package/dist/augmentations/neuralImport.js +255 -629
  37. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +52 -0
  38. package/dist/augmentations/requestDeduplicatorAugmentation.js +162 -0
  39. package/dist/augmentations/serverSearchAugmentations.d.ts +43 -22
  40. package/dist/augmentations/serverSearchAugmentations.js +125 -72
  41. package/dist/augmentations/storageAugmentation.d.ts +54 -0
  42. package/dist/augmentations/storageAugmentation.js +93 -0
  43. package/dist/augmentations/storageAugmentations.d.ts +96 -0
  44. package/dist/augmentations/storageAugmentations.js +182 -0
  45. package/dist/augmentations/synapseAugmentation.d.ts +156 -0
  46. package/dist/augmentations/synapseAugmentation.js +312 -0
  47. package/dist/augmentations/walAugmentation.d.ts +108 -0
  48. package/dist/augmentations/walAugmentation.js +515 -0
  49. package/dist/brainyData.d.ts +404 -130
  50. package/dist/brainyData.js +1336 -855
  51. package/dist/chat/BrainyChat.d.ts +16 -8
  52. package/dist/chat/BrainyChat.js +60 -32
  53. package/dist/chat/ChatCLI.d.ts +1 -1
  54. package/dist/chat/ChatCLI.js +6 -6
  55. package/dist/cli/catalog.d.ts +3 -3
  56. package/dist/cli/catalog.js +116 -70
  57. package/dist/cli/commands/core.d.ts +61 -0
  58. package/dist/cli/commands/core.js +348 -0
  59. package/dist/cli/commands/neural.d.ts +25 -0
  60. package/dist/cli/commands/neural.js +508 -0
  61. package/dist/cli/commands/utility.d.ts +37 -0
  62. package/dist/cli/commands/utility.js +276 -0
  63. package/dist/cli/index.d.ts +7 -0
  64. package/dist/cli/index.js +167 -0
  65. package/dist/cli/interactive.d.ts +164 -0
  66. package/dist/cli/interactive.js +542 -0
  67. package/dist/cortex/neuralImport.js +5 -5
  68. package/dist/critical/model-guardian.js +11 -4
  69. package/dist/embeddings/lightweight-embedder.d.ts +23 -0
  70. package/dist/embeddings/lightweight-embedder.js +136 -0
  71. package/dist/embeddings/universal-memory-manager.d.ts +38 -0
  72. package/dist/embeddings/universal-memory-manager.js +206 -0
  73. package/dist/embeddings/worker-embedding.d.ts +7 -0
  74. package/dist/embeddings/worker-embedding.js +77 -0
  75. package/dist/embeddings/worker-manager.d.ts +28 -0
  76. package/dist/embeddings/worker-manager.js +162 -0
  77. package/dist/examples/basicUsage.js +7 -7
  78. package/dist/graph/pathfinding.d.ts +78 -0
  79. package/dist/graph/pathfinding.js +393 -0
  80. package/dist/hnsw/hnswIndex.d.ts +13 -0
  81. package/dist/hnsw/hnswIndex.js +35 -0
  82. package/dist/hnsw/hnswIndexOptimized.d.ts +1 -0
  83. package/dist/hnsw/hnswIndexOptimized.js +3 -0
  84. package/dist/index.d.ts +9 -11
  85. package/dist/index.js +21 -11
  86. package/dist/indices/fieldIndex.d.ts +76 -0
  87. package/dist/indices/fieldIndex.js +357 -0
  88. package/dist/mcp/brainyMCPAdapter.js +3 -2
  89. package/dist/mcp/mcpAugmentationToolset.js +11 -17
  90. package/dist/neural/embeddedPatterns.d.ts +41 -0
  91. package/dist/neural/embeddedPatterns.js +4044 -0
  92. package/dist/neural/naturalLanguageProcessor.d.ts +94 -0
  93. package/dist/neural/naturalLanguageProcessor.js +317 -0
  94. package/dist/neural/naturalLanguageProcessorStatic.d.ts +64 -0
  95. package/dist/neural/naturalLanguageProcessorStatic.js +151 -0
  96. package/dist/neural/neuralAPI.d.ts +255 -0
  97. package/dist/neural/neuralAPI.js +612 -0
  98. package/dist/neural/patternLibrary.d.ts +101 -0
  99. package/dist/neural/patternLibrary.js +313 -0
  100. package/dist/neural/patterns.d.ts +27 -0
  101. package/dist/neural/patterns.js +68 -0
  102. package/dist/neural/staticPatternMatcher.d.ts +35 -0
  103. package/dist/neural/staticPatternMatcher.js +153 -0
  104. package/dist/scripts/precomputePatternEmbeddings.d.ts +19 -0
  105. package/dist/scripts/precomputePatternEmbeddings.js +100 -0
  106. package/dist/storage/adapters/fileSystemStorage.d.ts +5 -0
  107. package/dist/storage/adapters/fileSystemStorage.js +20 -0
  108. package/dist/storage/adapters/s3CompatibleStorage.d.ts +5 -0
  109. package/dist/storage/adapters/s3CompatibleStorage.js +16 -0
  110. package/dist/storage/enhancedClearOperations.d.ts +83 -0
  111. package/dist/storage/enhancedClearOperations.js +345 -0
  112. package/dist/storage/storageFactory.js +31 -27
  113. package/dist/triple/TripleIntelligence.d.ts +134 -0
  114. package/dist/triple/TripleIntelligence.js +548 -0
  115. package/dist/types/augmentations.d.ts +45 -344
  116. package/dist/types/augmentations.js +5 -2
  117. package/dist/types/brainyDataInterface.d.ts +20 -10
  118. package/dist/types/graphTypes.d.ts +46 -0
  119. package/dist/types/graphTypes.js +16 -2
  120. package/dist/utils/BoundedRegistry.d.ts +29 -0
  121. package/dist/utils/BoundedRegistry.js +54 -0
  122. package/dist/utils/embedding.js +20 -3
  123. package/dist/utils/hybridModelManager.js +10 -5
  124. package/dist/utils/metadataFilter.d.ts +33 -19
  125. package/dist/utils/metadataFilter.js +58 -23
  126. package/dist/utils/metadataIndex.d.ts +37 -6
  127. package/dist/utils/metadataIndex.js +427 -64
  128. package/dist/utils/requestDeduplicator.d.ts +10 -0
  129. package/dist/utils/requestDeduplicator.js +24 -0
  130. package/dist/utils/unifiedCache.d.ts +103 -0
  131. package/dist/utils/unifiedCache.js +311 -0
  132. package/package.json +43 -128
  133. package/scripts/ensure-models.js +108 -0
  134. package/scripts/prepare-models.js +387 -0
  135. package/OFFLINE_MODELS.md +0 -56
  136. package/dist/intelligence/neuralEngine.d.ts +0 -207
  137. package/dist/intelligence/neuralEngine.js +0 -706
  138. package/dist/utils/modelLoader.d.ts +0 -32
  139. package/dist/utils/modelLoader.js +0 -219
  140. package/dist/utils/modelManager.d.ts +0 -77
  141. package/dist/utils/modelManager.js +0 -219
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Neural API - Unified Semantic Intelligence
3
+ *
4
+ * Best-of-both: Complete functionality + Enterprise performance
5
+ * Combines rich features with O(n) algorithms for millions of items
6
+ */
7
+ import { Vector } from '../coreTypes.js';
8
+ export interface SimilarityResult {
9
+ score: number;
10
+ method?: string;
11
+ confidence?: number;
12
+ explanation?: string;
13
+ hierarchy?: {
14
+ sharedParent?: string;
15
+ distance?: number;
16
+ };
17
+ breakdown?: {
18
+ semantic?: number;
19
+ taxonomic?: number;
20
+ contextual?: number;
21
+ };
22
+ }
23
+ export interface SimilarityOptions {
24
+ explain?: boolean;
25
+ includeBreakdown?: boolean;
26
+ method?: 'cosine' | 'euclidean' | 'hybrid';
27
+ }
28
+ export interface SemanticCluster {
29
+ id: string;
30
+ centroid: Vector;
31
+ members: string[];
32
+ label?: string;
33
+ confidence: number;
34
+ depth?: number;
35
+ size?: number;
36
+ level?: number;
37
+ center?: any;
38
+ }
39
+ export interface SemanticHierarchy {
40
+ self: {
41
+ id: string;
42
+ type?: string;
43
+ vector: Vector;
44
+ };
45
+ parent?: {
46
+ id: string;
47
+ type?: string;
48
+ similarity: number;
49
+ };
50
+ grandparent?: {
51
+ id: string;
52
+ type?: string;
53
+ similarity: number;
54
+ };
55
+ root?: {
56
+ id: string;
57
+ type?: string;
58
+ similarity: number;
59
+ };
60
+ siblings?: Array<{
61
+ id: string;
62
+ similarity: number;
63
+ }>;
64
+ children?: Array<{
65
+ id: string;
66
+ similarity: number;
67
+ }>;
68
+ depth?: number;
69
+ }
70
+ export interface NeighborGraph {
71
+ center: string;
72
+ neighbors: Array<{
73
+ id: string;
74
+ similarity: number;
75
+ type?: string;
76
+ connections?: number;
77
+ }>;
78
+ edges?: Array<{
79
+ source: string;
80
+ target: string;
81
+ weight: number;
82
+ type?: string;
83
+ }>;
84
+ }
85
+ export interface ClusterOptions {
86
+ algorithm?: 'hierarchical' | 'kmeans' | 'sample' | 'stream';
87
+ maxClusters?: number;
88
+ threshold?: number;
89
+ sampleSize?: number;
90
+ strategy?: 'random' | 'diverse' | 'recent';
91
+ level?: number;
92
+ batchSize?: number;
93
+ }
94
+ export interface VisualizationData {
95
+ format: 'force-directed' | 'hierarchical' | 'radial';
96
+ nodes: Array<{
97
+ id: string;
98
+ x: number;
99
+ y: number;
100
+ z?: number;
101
+ type?: string;
102
+ cluster?: string;
103
+ size?: number;
104
+ }>;
105
+ edges: Array<{
106
+ source: string;
107
+ target: string;
108
+ weight: number;
109
+ type?: string;
110
+ }>;
111
+ layout?: {
112
+ dimensions: number;
113
+ algorithm: string;
114
+ bounds?: {
115
+ width: number;
116
+ height: number;
117
+ depth?: number;
118
+ };
119
+ };
120
+ clusters?: Array<{
121
+ id: string;
122
+ color: string;
123
+ label?: string;
124
+ size: number;
125
+ }>;
126
+ }
127
+ export interface ClusteringStrategy {
128
+ type: 'sample' | 'hierarchical' | 'stream' | 'hybrid';
129
+ sampleSize?: number;
130
+ maxClusters?: number;
131
+ minClusterSize?: number;
132
+ }
133
+ export interface LODConfig {
134
+ levels: number;
135
+ itemsPerLevel: number[];
136
+ zoomThresholds: number[];
137
+ }
138
+ /**
139
+ * Neural API - Unified best-of-both implementation
140
+ */
141
+ export declare class NeuralAPI {
142
+ private brain;
143
+ private similarityCache;
144
+ private clusterCache;
145
+ private hierarchyCache;
146
+ constructor(brain: any);
147
+ /**
148
+ * Calculate similarity between any two items (smart detection)
149
+ */
150
+ similar(a: any, b: any, options?: SimilarityOptions): Promise<number | SimilarityResult>;
151
+ /**
152
+ * Find semantic clusters (auto-detects best approach)
153
+ * Now with enterprise performance!
154
+ */
155
+ clusters(input?: any): Promise<SemanticCluster[]>;
156
+ /**
157
+ * Get semantic hierarchy for an item
158
+ */
159
+ hierarchy(id: string): Promise<SemanticHierarchy>;
160
+ /**
161
+ * Find semantic neighbors for visualization
162
+ */
163
+ neighbors(id: string, options?: {
164
+ radius?: number;
165
+ limit?: number;
166
+ includeEdges?: boolean;
167
+ }): Promise<NeighborGraph>;
168
+ /**
169
+ * Find semantic path between two items
170
+ */
171
+ semanticPath(fromId: string, toId: string, options?: {
172
+ maxHops?: number;
173
+ algorithm?: 'breadth' | 'dijkstra';
174
+ }): Promise<Array<{
175
+ id: string;
176
+ similarity: number;
177
+ hop: number;
178
+ }>>;
179
+ /**
180
+ * Detect semantic outliers
181
+ */
182
+ outliers(threshold?: number): Promise<string[]>;
183
+ /**
184
+ * Generate visualization data
185
+ */
186
+ visualize(options?: {
187
+ maxNodes?: number;
188
+ dimensions?: 2 | 3;
189
+ algorithm?: 'force' | 'hierarchical' | 'radial';
190
+ includeEdges?: boolean;
191
+ }): Promise<VisualizationData>;
192
+ /**
193
+ * Fast clustering using HNSW levels - O(n) instead of O(n²)
194
+ */
195
+ clusterFast(options?: {
196
+ level?: number;
197
+ maxClusters?: number;
198
+ }): Promise<SemanticCluster[]>;
199
+ /**
200
+ * Large-scale clustering for massive datasets (millions of items)
201
+ */
202
+ clusterLarge(options?: {
203
+ sampleSize?: number;
204
+ strategy?: 'random' | 'diverse' | 'recent';
205
+ }): Promise<SemanticCluster[]>;
206
+ /**
207
+ * Streaming clustering for progressive refinement
208
+ */
209
+ clusterStream(options?: {
210
+ batchSize?: number;
211
+ maxBatches?: number;
212
+ }): AsyncGenerator<SemanticCluster[]>;
213
+ /**
214
+ * Level-of-detail for massive visualization
215
+ */
216
+ getLOD(zoomLevel: number, viewport?: {
217
+ center: Vector;
218
+ radius: number;
219
+ }): Promise<any>;
220
+ private isId;
221
+ private similarityById;
222
+ private similarityByText;
223
+ private similarityByVector;
224
+ private smartSimilarity;
225
+ private toVector;
226
+ private getOptimalClusteringLevel;
227
+ private getHNSWLevelNodes;
228
+ private findClusterMembers;
229
+ private getSample;
230
+ private shuffleArray;
231
+ private getDiverseSample;
232
+ private performFastClustering;
233
+ private calculateCentroid;
234
+ private projectClustersToFullDataset;
235
+ private mergeClusters;
236
+ private averageVectors;
237
+ private getBatch;
238
+ private clusterAll;
239
+ private clusterItems;
240
+ private clustersNear;
241
+ private clusterWithConfig;
242
+ private buildHierarchy;
243
+ private buildEdges;
244
+ private dijkstraPath;
245
+ private breadthFirstPath;
246
+ private outliersViaSampling;
247
+ private outliersByDistance;
248
+ private getVisualizationNodes;
249
+ private applyLayout;
250
+ private buildVisualizationEdges;
251
+ private detectOptimalFormat;
252
+ private calculateBounds;
253
+ private getViewportLOD;
254
+ private getGlobalLOD;
255
+ }