@soulcraft/brainy 2.15.0 → 3.0.1

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 (204) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +249 -152
  3. package/dist/api/ConfigAPI.d.ts +67 -0
  4. package/dist/api/ConfigAPI.js +166 -0
  5. package/dist/api/DataAPI.d.ts +123 -0
  6. package/dist/api/DataAPI.js +391 -0
  7. package/dist/api/SecurityAPI.d.ts +50 -0
  8. package/dist/api/SecurityAPI.js +139 -0
  9. package/dist/api/UniversalImportAPI.d.ts +134 -0
  10. package/dist/api/UniversalImportAPI.js +615 -0
  11. package/dist/augmentationManager.js +12 -7
  12. package/dist/augmentationPipeline.d.ts +0 -61
  13. package/dist/augmentationPipeline.js +0 -87
  14. package/dist/augmentationRegistry.d.ts +1 -1
  15. package/dist/augmentationRegistry.js +1 -1
  16. package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
  17. package/dist/augmentations/apiServerAugmentation.js +288 -7
  18. package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
  19. package/dist/augmentations/auditLogAugmentation.js +358 -0
  20. package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
  21. package/dist/augmentations/batchProcessingAugmentation.js +123 -22
  22. package/dist/augmentations/brainyAugmentation.d.ts +87 -8
  23. package/dist/augmentations/brainyAugmentation.js +159 -2
  24. package/dist/augmentations/cacheAugmentation.d.ts +6 -5
  25. package/dist/augmentations/cacheAugmentation.js +113 -17
  26. package/dist/augmentations/conduitAugmentations.d.ts +2 -2
  27. package/dist/augmentations/conduitAugmentations.js +2 -2
  28. package/dist/augmentations/configResolver.d.ts +122 -0
  29. package/dist/augmentations/configResolver.js +440 -0
  30. package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
  31. package/dist/augmentations/connectionPoolAugmentation.js +37 -12
  32. package/dist/augmentations/defaultAugmentations.d.ts +9 -11
  33. package/dist/augmentations/defaultAugmentations.js +4 -11
  34. package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
  35. package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
  36. package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
  37. package/dist/augmentations/discovery/localDiscovery.js +246 -0
  38. package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
  39. package/dist/augmentations/discovery/runtimeLoader.js +337 -0
  40. package/dist/augmentations/discovery.d.ts +152 -0
  41. package/dist/augmentations/discovery.js +441 -0
  42. package/dist/augmentations/display/intelligentComputation.d.ts +1 -1
  43. package/dist/augmentations/display/intelligentComputation.js +4 -4
  44. package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
  45. package/dist/augmentations/entityRegistryAugmentation.js +5 -1
  46. package/dist/augmentations/indexAugmentation.d.ts +3 -3
  47. package/dist/augmentations/indexAugmentation.js +2 -2
  48. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +22 -6
  49. package/dist/augmentations/intelligentVerbScoringAugmentation.js +106 -23
  50. package/dist/augmentations/manifest.d.ts +176 -0
  51. package/dist/augmentations/manifest.js +8 -0
  52. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
  53. package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
  54. package/dist/augmentations/marketplace/cli.d.ts +47 -0
  55. package/dist/augmentations/marketplace/cli.js +265 -0
  56. package/dist/augmentations/metricsAugmentation.d.ts +3 -3
  57. package/dist/augmentations/metricsAugmentation.js +2 -2
  58. package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
  59. package/dist/augmentations/monitoringAugmentation.js +2 -2
  60. package/dist/augmentations/neuralImport.d.ts +1 -1
  61. package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
  62. package/dist/augmentations/rateLimitAugmentation.js +321 -0
  63. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
  64. package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
  65. package/dist/augmentations/storageAugmentation.d.ts +1 -1
  66. package/dist/augmentations/storageAugmentation.js +2 -2
  67. package/dist/augmentations/storageAugmentations.d.ts +37 -8
  68. package/dist/augmentations/storageAugmentations.js +204 -15
  69. package/dist/augmentations/synapseAugmentation.d.ts +1 -1
  70. package/dist/augmentations/synapseAugmentation.js +35 -16
  71. package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
  72. package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
  73. package/dist/augmentations/universalDisplayAugmentation.d.ts +2 -2
  74. package/dist/augmentations/universalDisplayAugmentation.js +2 -2
  75. package/dist/brainy-unified.d.ts +106 -0
  76. package/dist/brainy-unified.js +327 -0
  77. package/dist/brainy.d.ts +273 -0
  78. package/dist/brainy.js +1181 -0
  79. package/dist/brainyData.d.ts +29 -72
  80. package/dist/brainyData.js +350 -304
  81. package/dist/brainyDataV3.d.ts +186 -0
  82. package/dist/brainyDataV3.js +337 -0
  83. package/dist/browserFramework.d.ts +6 -6
  84. package/dist/browserFramework.js +11 -8
  85. package/dist/browserFramework.minimal.d.ts +5 -5
  86. package/dist/browserFramework.minimal.js +11 -8
  87. package/dist/config/index.d.ts +2 -2
  88. package/dist/config/index.js +3 -3
  89. package/dist/config/modelAutoConfig.d.ts +6 -7
  90. package/dist/config/modelAutoConfig.js +17 -76
  91. package/dist/cortex/backupRestore.d.ts +2 -2
  92. package/dist/cortex/backupRestore.js +85 -27
  93. package/dist/cortex/healthCheck.d.ts +2 -2
  94. package/dist/cortex/neuralImport.d.ts +2 -2
  95. package/dist/cortex/neuralImport.js +18 -13
  96. package/dist/cortex/performanceMonitor.d.ts +2 -2
  97. package/dist/critical/model-guardian.d.ts +4 -0
  98. package/dist/critical/model-guardian.js +31 -11
  99. package/dist/demo.d.ts +4 -4
  100. package/dist/demo.js +7 -7
  101. package/dist/distributed/cacheSync.d.ts +112 -0
  102. package/dist/distributed/cacheSync.js +265 -0
  103. package/dist/distributed/coordinator.d.ts +193 -0
  104. package/dist/distributed/coordinator.js +548 -0
  105. package/dist/distributed/httpTransport.d.ts +120 -0
  106. package/dist/distributed/httpTransport.js +446 -0
  107. package/dist/distributed/index.d.ts +8 -0
  108. package/dist/distributed/index.js +5 -0
  109. package/dist/distributed/networkTransport.d.ts +132 -0
  110. package/dist/distributed/networkTransport.js +633 -0
  111. package/dist/distributed/queryPlanner.d.ts +104 -0
  112. package/dist/distributed/queryPlanner.js +327 -0
  113. package/dist/distributed/readWriteSeparation.d.ts +134 -0
  114. package/dist/distributed/readWriteSeparation.js +350 -0
  115. package/dist/distributed/shardManager.d.ts +114 -0
  116. package/dist/distributed/shardManager.js +357 -0
  117. package/dist/distributed/shardMigration.d.ts +110 -0
  118. package/dist/distributed/shardMigration.js +289 -0
  119. package/dist/distributed/storageDiscovery.d.ts +160 -0
  120. package/dist/distributed/storageDiscovery.js +551 -0
  121. package/dist/embeddings/EmbeddingManager.d.ts +0 -4
  122. package/dist/embeddings/EmbeddingManager.js +21 -26
  123. package/dist/errors/brainyError.d.ts +5 -1
  124. package/dist/errors/brainyError.js +12 -0
  125. package/dist/examples/basicUsage.js +3 -3
  126. package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
  127. package/dist/graph/graphAdjacencyIndex.js +288 -0
  128. package/dist/graph/pathfinding.js +4 -2
  129. package/dist/hnsw/scaledHNSWSystem.js +11 -2
  130. package/dist/importManager.js +6 -3
  131. package/dist/index.d.ts +12 -21
  132. package/dist/index.js +14 -22
  133. package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
  134. package/dist/mcp/brainyMCPAdapter.js +5 -5
  135. package/dist/mcp/brainyMCPService.d.ts +3 -3
  136. package/dist/mcp/brainyMCPService.js +3 -11
  137. package/dist/mcp/mcpAugmentationToolset.js +20 -30
  138. package/dist/neural/embeddedPatterns.d.ts +1 -1
  139. package/dist/neural/embeddedPatterns.js +2 -2
  140. package/dist/neural/entityExtractor.d.ts +65 -0
  141. package/dist/neural/entityExtractor.js +316 -0
  142. package/dist/neural/improvedNeuralAPI.js +90 -79
  143. package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
  144. package/dist/neural/naturalLanguageProcessor.js +941 -66
  145. package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
  146. package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
  147. package/dist/neural/neuralAPI.js +8 -2
  148. package/dist/neural/patternLibrary.d.ts +57 -3
  149. package/dist/neural/patternLibrary.js +348 -13
  150. package/dist/neural/staticPatternMatcher.d.ts +2 -2
  151. package/dist/neural/staticPatternMatcher.js +2 -2
  152. package/dist/shared/default-augmentations.d.ts +3 -3
  153. package/dist/shared/default-augmentations.js +5 -5
  154. package/dist/storage/adapters/fileSystemStorage.d.ts +4 -0
  155. package/dist/storage/adapters/fileSystemStorage.js +54 -1
  156. package/dist/storage/adapters/memoryStorage.js +13 -8
  157. package/dist/storage/backwardCompatibility.d.ts +10 -78
  158. package/dist/storage/backwardCompatibility.js +17 -132
  159. package/dist/storage/baseStorage.d.ts +6 -0
  160. package/dist/storage/baseStorage.js +17 -0
  161. package/dist/storage/cacheManager.js +2 -2
  162. package/dist/storage/readOnlyOptimizations.js +8 -3
  163. package/dist/streaming/pipeline.d.ts +154 -0
  164. package/dist/streaming/pipeline.js +551 -0
  165. package/dist/triple/TripleIntelligence.d.ts +25 -110
  166. package/dist/triple/TripleIntelligence.js +4 -574
  167. package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
  168. package/dist/triple/TripleIntelligenceSystem.js +519 -0
  169. package/dist/types/apiTypes.d.ts +278 -0
  170. package/dist/types/apiTypes.js +33 -0
  171. package/dist/types/brainy.types.d.ts +308 -0
  172. package/dist/types/brainy.types.js +8 -0
  173. package/dist/types/brainyDataInterface.d.ts +3 -3
  174. package/dist/types/brainyDataInterface.js +2 -2
  175. package/dist/types/graphTypes.js +2 -2
  176. package/dist/utils/cacheAutoConfig.d.ts +3 -3
  177. package/dist/utils/embedding.js +8 -14
  178. package/dist/utils/enhancedLogger.d.ts +104 -0
  179. package/dist/utils/enhancedLogger.js +232 -0
  180. package/dist/utils/index.d.ts +1 -1
  181. package/dist/utils/index.js +1 -1
  182. package/dist/utils/intelligentTypeMapper.d.ts +60 -0
  183. package/dist/utils/intelligentTypeMapper.js +349 -0
  184. package/dist/utils/metadataIndex.d.ts +118 -1
  185. package/dist/utils/metadataIndex.js +539 -16
  186. package/dist/utils/paramValidation.d.ts +39 -0
  187. package/dist/utils/paramValidation.js +192 -0
  188. package/dist/utils/rateLimiter.d.ts +160 -0
  189. package/dist/utils/rateLimiter.js +271 -0
  190. package/dist/utils/statistics.d.ts +4 -4
  191. package/dist/utils/statistics.js +3 -3
  192. package/dist/utils/structuredLogger.d.ts +146 -0
  193. package/dist/utils/structuredLogger.js +394 -0
  194. package/dist/utils/textEncoding.js +2 -1
  195. package/dist/utils/typeValidation.d.ts +34 -0
  196. package/dist/utils/typeValidation.js +247 -0
  197. package/package.json +14 -6
  198. package/scripts/download-models.cjs +6 -15
  199. package/dist/augmentations/walAugmentation.d.ts +0 -111
  200. package/dist/augmentations/walAugmentation.js +0 -519
  201. package/dist/chat/BrainyChat.d.ts +0 -121
  202. package/dist/chat/BrainyChat.js +0 -396
  203. package/dist/chat/ChatCLI.d.ts +0 -61
  204. package/dist/chat/ChatCLI.js +0 -351
@@ -9,9 +9,10 @@
9
9
  * - Progressive learning from usage
10
10
  */
11
11
  import { TripleQuery } from '../triple/TripleIntelligence.js';
12
- import { BrainyData } from '../brainyData.js';
12
+ import { Brainy } from '../brainy.js';
13
13
  export interface NaturalQueryIntent {
14
14
  type: 'vector' | 'field' | 'graph' | 'combined';
15
+ primaryIntent: 'search' | 'filter' | 'aggregate' | 'navigate' | 'compare' | 'explain';
15
16
  confidence: number;
16
17
  extractedTerms: {
17
18
  searchTerms?: string[];
@@ -26,31 +27,113 @@ export interface NaturalQueryIntent {
26
27
  popular?: boolean;
27
28
  limit?: number;
28
29
  boost?: string;
30
+ sortBy?: string;
31
+ groupBy?: string;
29
32
  };
30
33
  };
34
+ context?: {
35
+ domain?: string;
36
+ temporalScope?: 'past' | 'present' | 'future' | 'all';
37
+ complexity?: 'simple' | 'moderate' | 'complex';
38
+ };
31
39
  }
32
40
  export declare class NaturalLanguageProcessor {
33
41
  private brain;
34
42
  private patternLibrary;
35
43
  private queryHistory;
36
44
  private initialized;
37
- constructor(brain: BrainyData);
45
+ private embeddingCache;
46
+ private fieldEmbeddings;
47
+ private fieldNames;
48
+ private lastFieldRefresh;
49
+ private readonly FIELD_REFRESH_INTERVAL;
50
+ private nounTypeEmbeddings;
51
+ private verbTypeEmbeddings;
52
+ private typeEmbeddingsInitialized;
53
+ constructor(brain: Brainy);
54
+ /**
55
+ * Get embedding directly using brain's embed method
56
+ */
57
+ private getEmbedding;
38
58
  /**
39
59
  * Initialize the pattern library (lazy loading)
40
60
  */
41
61
  private ensureInitialized;
62
+ /**
63
+ * Initialize embeddings for all NounTypes and VerbTypes
64
+ * These are fixed types that never change - perfect for caching
65
+ */
66
+ private initializeTypeEmbeddings;
67
+ /**
68
+ * Find best matching NounType using semantic similarity
69
+ */
70
+ private findBestNounType;
71
+ /**
72
+ * Find best matching VerbType using semantic similarity
73
+ */
74
+ private findBestVerbType;
75
+ /**
76
+ * Refresh field embeddings from metadata index
77
+ * Creates embeddings for all indexed fields for semantic matching
78
+ */
79
+ private refreshFieldEmbeddings;
80
+ /**
81
+ * Generate linguistic variations of field names - NO HARDCODED TERMS
82
+ * Uses algorithmic patterns to create natural variations
83
+ */
84
+ private getFieldVariations;
85
+ /**
86
+ * Find best matching field using semantic similarity
87
+ * Returns field name and confidence score
88
+ */
89
+ private findBestMatchingField;
90
+ /**
91
+ * Find best matching field with type context prioritization
92
+ * Fields with high type affinity get boosted scores
93
+ */
94
+ private findBestMatchingFieldWithTypeContext;
95
+ /**
96
+ * Validate field-type compatibility
97
+ * Returns validation result with suggestions for invalid combinations
98
+ */
99
+ private validateFieldForType;
100
+ /**
101
+ * Enhanced intelligent parse with validation
102
+ */
103
+ private validateAndOptimizeQuery;
104
+ /**
105
+ * Calculate cosine similarity between two vectors
106
+ */
107
+ private cosineSimilarity;
108
+ /**
109
+ * Public initialization method for external callers
110
+ */
111
+ init(): Promise<void>;
42
112
  /**
43
113
  * 🎯 MAIN METHOD: Convert natural language to Triple Intelligence query
44
114
  */
45
115
  processNaturalQuery(naturalQuery: string): Promise<TripleQuery>;
46
116
  /**
47
- * Hybrid parse when pattern matching fails
117
+ * Intelligent parse using type-aware field discovery and semantic matching
118
+ * NO FALLBACKS - uses actual indexed fields, entities, and type context
48
119
  */
49
- private hybridParse;
120
+ private intelligentParse;
50
121
  /**
51
- * Analyze intent using keywords and structure
122
+ * Analyze intent using keywords and structure with enhanced classification
52
123
  */
53
124
  private analyzeIntent;
125
+ /**
126
+ * Detect the domain of the query
127
+ */
128
+ private detectDomain;
129
+ /**
130
+ * Detect temporal scope in query
131
+ */
132
+ private detectTemporalScope;
133
+ /**
134
+ * Assess query complexity
135
+ */
136
+ private assessComplexity;
54
137
  /**
55
138
  * Step 2: Use neural analysis to decompose complex queries
56
139
  */
@@ -80,15 +163,77 @@ export declare class NaturalLanguageProcessor {
80
163
  */
81
164
  private extractTerms;
82
165
  /**
83
- * Find entity matches using Brainy's search capabilities
166
+ * Find entity matches using type context and semantic similarity
84
167
  */
85
168
  private findEntityMatches;
86
169
  /**
87
- * Check if term is a known field name
170
+ * Find entity matches with type context for better field prioritization
171
+ */
172
+ private findEntityMatchesWithTypeContext;
173
+ /**
174
+ * Find similar successful queries from history
175
+ * Uses Brainy's vector search to find semantically similar previous queries
176
+ */
177
+ private findSimilarQueries;
178
+ /**
179
+ * Extract entities from query using Brainy's semantic search
180
+ * Identifies known entities, concepts, and relationships in the query text
181
+ */
182
+ private extractEntities;
183
+ /**
184
+ * Build final TripleQuery based on intent, entities, and query analysis
185
+ * Constructs optimized query combining vector, graph, and field searches
88
186
  */
89
- private isKnownField;
187
+ private buildQuery;
188
+ /**
189
+ * Extract entities from text using NEURAL matching to strict NounTypes
190
+ * ALWAYS uses neural matching, NEVER falls back to patterns
191
+ */
192
+ extract(text: string, options?: {
193
+ types?: string[];
194
+ includeMetadata?: boolean;
195
+ confidence?: number;
196
+ }): Promise<Array<{
197
+ text: string;
198
+ type: string;
199
+ position: {
200
+ start: number;
201
+ end: number;
202
+ };
203
+ confidence: number;
204
+ metadata?: any;
205
+ }>>;
206
+ /**
207
+ * DEPRECATED - Old pattern-based extraction
208
+ * This should NEVER be used - kept only for reference
209
+ */
210
+ private extractWithPatterns_DEPRECATED;
211
+ /**
212
+ * Analyze sentiment of text
213
+ */
214
+ sentiment(text: string, options?: {
215
+ granularity?: 'document' | 'sentence' | 'aspect';
216
+ aspects?: string[];
217
+ }): Promise<{
218
+ overall: {
219
+ score: number;
220
+ magnitude: number;
221
+ label: 'positive' | 'negative' | 'neutral' | 'mixed';
222
+ };
223
+ sentences?: Array<{
224
+ text: string;
225
+ score: number;
226
+ magnitude: number;
227
+ label: string;
228
+ }>;
229
+ aspects?: Record<string, {
230
+ score: number;
231
+ magnitude: number;
232
+ mentions: number;
233
+ }>;
234
+ }>;
90
235
  /**
91
- * Map colloquial terms to actual field names
236
+ * Calculate confidence for entity extraction
92
237
  */
93
- private mapToFieldName;
238
+ private calculateConfidence;
94
239
  }