@soulcraft/brainy 2.10.1 → 2.12.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 (42) hide show
  1. package/README.md +10 -10
  2. package/dist/augmentations/apiServerAugmentation.js +2 -2
  3. package/dist/augmentations/display/fieldPatterns.d.ts +1 -1
  4. package/dist/augmentations/display/fieldPatterns.js +1 -1
  5. package/dist/augmentations/display/intelligentComputation.d.ts +2 -2
  6. package/dist/augmentations/display/intelligentComputation.js +4 -4
  7. package/dist/augmentations/display/types.d.ts +1 -1
  8. package/dist/augmentations/neuralImport.js +4 -4
  9. package/dist/augmentations/synapseAugmentation.js +3 -3
  10. package/dist/augmentations/typeMatching/brainyTypes.d.ts +83 -0
  11. package/dist/augmentations/typeMatching/brainyTypes.js +425 -0
  12. package/dist/augmentations/universalDisplayAugmentation.d.ts +1 -1
  13. package/dist/augmentations/universalDisplayAugmentation.js +1 -1
  14. package/dist/brainyData.d.ts +20 -41
  15. package/dist/brainyData.js +1467 -1430
  16. package/dist/chat/BrainyChat.js +11 -11
  17. package/dist/examples/basicUsage.js +4 -1
  18. package/dist/importManager.js +2 -2
  19. package/dist/index.d.ts +3 -1
  20. package/dist/index.js +5 -1
  21. package/dist/neural/embeddedPatterns.d.ts +1 -1
  22. package/dist/neural/embeddedPatterns.js +2 -2
  23. package/dist/neural/improvedNeuralAPI.d.ts +346 -0
  24. package/dist/neural/improvedNeuralAPI.js +2439 -0
  25. package/dist/neural/types.d.ts +267 -0
  26. package/dist/neural/types.js +24 -0
  27. package/dist/storage/adapters/fileSystemStorage.d.ts +2 -2
  28. package/dist/storage/adapters/fileSystemStorage.js +2 -2
  29. package/dist/storage/adapters/memoryStorage.d.ts +4 -4
  30. package/dist/storage/adapters/memoryStorage.js +4 -4
  31. package/dist/storage/adapters/opfsStorage.d.ts +2 -2
  32. package/dist/storage/adapters/opfsStorage.js +2 -2
  33. package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
  34. package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
  35. package/dist/storage/baseStorage.d.ts +12 -2
  36. package/dist/storage/baseStorage.js +32 -0
  37. package/dist/types/brainyDataInterface.d.ts +2 -5
  38. package/dist/utils/brainyTypes.d.ts +217 -0
  39. package/dist/utils/brainyTypes.js +261 -0
  40. package/dist/utils/typeValidation.d.ts +25 -0
  41. package/dist/utils/typeValidation.js +127 -0
  42. package/package.json +1 -1
@@ -0,0 +1,346 @@
1
+ /**
2
+ * Improved Neural API - Clean, Consistent, Performant
3
+ *
4
+ * Public API Surface:
5
+ * - brain.neural.similar(a, b, options?) // Similarity calculation
6
+ * - brain.neural.clusters(items?, options?) // Semantic clustering
7
+ * - brain.neural.neighbors(id, options?) // K-nearest neighbors
8
+ * - brain.neural.hierarchy(id, options?) // Semantic hierarchy
9
+ * - brain.neural.outliers(options?) // Anomaly detection
10
+ * - brain.neural.visualize(options?) // Visualization data
11
+ *
12
+ * Advanced Clustering:
13
+ * - brain.neural.clusterByDomain(field, options?) // Domain-aware clustering
14
+ * - brain.neural.clusterByTime(field, windows, options?) // Temporal clustering
15
+ * - brain.neural.clusterStream(options?) // AsyncIterator for streaming
16
+ * - brain.neural.updateClusters(items, options?) // Incremental clustering
17
+ *
18
+ * Private methods are prefixed with _ and not exposed in public API
19
+ */
20
+ import { Vector } from '../coreTypes.js';
21
+ import { SemanticCluster, DomainCluster, TemporalCluster, SimilarityOptions, SimilarityResult, NeighborOptions, NeighborsResult, SemanticHierarchy, HierarchyOptions, ClusteringOptions, DomainClusteringOptions, TemporalClusteringOptions, StreamClusteringOptions, VisualizationOptions, VisualizationResult, OutlierOptions, Outlier, StreamingBatch, TimeWindow, PerformanceMetrics, NeuralAPIConfig } from './types.js';
22
+ export declare class ImprovedNeuralAPI {
23
+ private brain;
24
+ private config;
25
+ private similarityCache;
26
+ private clusterCache;
27
+ private hierarchyCache;
28
+ private neighborsCache;
29
+ private performanceMetrics;
30
+ constructor(brain: any, config?: NeuralAPIConfig);
31
+ /**
32
+ * Calculate similarity between any two items (auto-detection)
33
+ * Supports: IDs, text strings, vectors, or mixed types
34
+ */
35
+ similar(a: string | Vector | any, b: string | Vector | any, options?: SimilarityOptions): Promise<number | SimilarityResult>;
36
+ /**
37
+ * Intelligent semantic clustering with auto-routing
38
+ * - No input: Cluster all data
39
+ * - Array: Cluster specific items
40
+ * - String: Find clusters near this item
41
+ * - Options object: Advanced configuration
42
+ */
43
+ clusters(input?: string | string[] | ClusteringOptions): Promise<SemanticCluster[]>;
44
+ /**
45
+ * Fast hierarchical clustering using HNSW levels
46
+ */
47
+ clusterFast(options?: {
48
+ level?: number;
49
+ maxClusters?: number;
50
+ }): Promise<SemanticCluster[]>;
51
+ /**
52
+ * Large-scale clustering with intelligent sampling
53
+ */
54
+ clusterLarge(options?: {
55
+ sampleSize?: number;
56
+ strategy?: 'random' | 'diverse' | 'recent';
57
+ }): Promise<SemanticCluster[]>;
58
+ /**
59
+ * Domain-aware clustering based on metadata fields
60
+ */
61
+ clusterByDomain(field: string, options?: DomainClusteringOptions): Promise<DomainCluster[]>;
62
+ /**
63
+ * Temporal clustering based on time windows
64
+ */
65
+ clusterByTime(timeField: string, windows: TimeWindow[], options?: TemporalClusteringOptions): Promise<TemporalCluster[]>;
66
+ /**
67
+ * Streaming clustering with real-time updates
68
+ */
69
+ clusterStream(options?: StreamClusteringOptions): AsyncIterableIterator<StreamingBatch>;
70
+ /**
71
+ * Incremental clustering - add new items to existing clusters
72
+ */
73
+ updateClusters(newItems: string[], options?: ClusteringOptions): Promise<SemanticCluster[]>;
74
+ /**
75
+ * Find K-nearest semantic neighbors
76
+ */
77
+ neighbors(id: string, options?: NeighborOptions): Promise<NeighborsResult>;
78
+ /**
79
+ * Build semantic hierarchy around an item
80
+ */
81
+ hierarchy(id: string, options?: HierarchyOptions): Promise<SemanticHierarchy>;
82
+ /**
83
+ * Detect outliers and anomalous items
84
+ */
85
+ outliers(options?: OutlierOptions): Promise<Outlier[]>;
86
+ /**
87
+ * Generate visualization data for graph libraries
88
+ */
89
+ visualize(options?: VisualizationOptions): Promise<VisualizationResult>;
90
+ private _routeClusteringAlgorithm;
91
+ private _performClustering;
92
+ /**
93
+ * SEMANTIC-AWARE CLUSTERING: Uses existing NounType/VerbType taxonomy + HNSW
94
+ */
95
+ private _performSemanticClustering;
96
+ /**
97
+ * HIERARCHICAL CLUSTERING: Uses existing HNSW levels for O(n) clustering
98
+ */
99
+ private _performHierarchicalClustering;
100
+ /**
101
+ * K-MEANS CLUSTERING: Real implementation using existing distance functions
102
+ */
103
+ private _performKMeansClustering;
104
+ /**
105
+ * DBSCAN CLUSTERING: Density-based clustering with adaptive parameters using HNSW
106
+ */
107
+ private _performDBSCANClustering;
108
+ /**
109
+ * GRAPH COMMUNITY DETECTION: Uses existing verb relationships for clustering
110
+ */
111
+ private _performGraphClustering;
112
+ /**
113
+ * MULTI-MODAL FUSION: Combines vector + graph + semantic + Triple Intelligence
114
+ */
115
+ private _performMultiModalClustering;
116
+ /**
117
+ * SAMPLED CLUSTERING: For very large datasets using intelligent sampling
118
+ */
119
+ private _performSampledClustering;
120
+ private _similarityById;
121
+ private _similarityByVector;
122
+ private _similarityByText;
123
+ private _isId;
124
+ private _isVector;
125
+ private _convertToVector;
126
+ private _createSimilarityKey;
127
+ private _createClusteringKey;
128
+ private _cacheResult;
129
+ private _trackPerformance;
130
+ private _createPerformanceMetrics;
131
+ private _initializeCleanupTimer;
132
+ /**
133
+ * Build graph structure from existing verb relationships
134
+ */
135
+ private _buildGraphFromVerbs;
136
+ /**
137
+ * Detect communities using Louvain modularity optimization
138
+ */
139
+ private _detectCommunities;
140
+ /**
141
+ * Refine community boundaries using vector similarity
142
+ */
143
+ private _refineCommunitiesWithVectors;
144
+ /**
145
+ * Get items with their metadata including noun types
146
+ */
147
+ private _getItemsWithMetadata;
148
+ /**
149
+ * Group items by their semantic noun types
150
+ */
151
+ private _groupBySemanticType;
152
+ private _getAllItemIds;
153
+ private _getTotalItemCount;
154
+ private _calculateTotalWeight;
155
+ private _getNeighborCommunities;
156
+ private _calculateModularityGain;
157
+ private _getNodeDegree;
158
+ private _getEdgesToCommunity;
159
+ private _getCommunityWeight;
160
+ private _calculateCommunityModularity;
161
+ private _calculateCommunityDensity;
162
+ private _findStrongestConnections;
163
+ /**
164
+ * Get items with their vector representations
165
+ */
166
+ private _getItemsWithVectors;
167
+ /**
168
+ * Calculate centroid from items using existing distance functions
169
+ */
170
+ private _calculateCentroidFromItems;
171
+ /**
172
+ * Initialize centroids using k-means++ algorithm for better convergence
173
+ */
174
+ private _initializeCentroidsKMeansPlusPlus;
175
+ /**
176
+ * Assign points to nearest centroids using existing distance functions
177
+ */
178
+ private _assignPointsToCentroids;
179
+ /**
180
+ * Update centroids based on current assignments
181
+ */
182
+ private _updateCentroids;
183
+ /**
184
+ * Calculate how much assignments have changed between iterations
185
+ */
186
+ private _calculateAssignmentChangeRate;
187
+ /**
188
+ * Calculate cluster confidence for k-means clusters
189
+ */
190
+ private _calculateKMeansClusterConfidence;
191
+ /**
192
+ * Estimate optimal eps parameter using k-nearest neighbor distances
193
+ */
194
+ private _estimateOptimalEps;
195
+ /**
196
+ * Find neighbors within epsilon distance using efficient vector operations
197
+ */
198
+ private _findNeighborsWithinEps;
199
+ /**
200
+ * Expand DBSCAN cluster by adding density-reachable points
201
+ */
202
+ private _expandCluster;
203
+ /**
204
+ * Calculate DBSCAN cluster confidence based on density
205
+ */
206
+ private _calculateDBSCANClusterConfidence;
207
+ /**
208
+ * Calculate squared Euclidean distance (more efficient than sqrt)
209
+ */
210
+ private _calculateSquaredDistance;
211
+ /**
212
+ * Calculate vector coherence for community refinement
213
+ */
214
+ private _calculateVectorCoherence;
215
+ private _getItemsByField;
216
+ /**
217
+ * Generate intelligent cluster labels using Triple Intelligence
218
+ */
219
+ private _generateIntelligentClusterLabel;
220
+ /**
221
+ * Generate simple cluster labels based on semantic analysis
222
+ */
223
+ private _generateClusterLabel;
224
+ /**
225
+ * Fuse clustering results using Triple Intelligence consensus
226
+ */
227
+ private _fuseClusteringResultsWithTripleIntelligence;
228
+ /**
229
+ * Get items in a specific cluster from cluster sets
230
+ */
231
+ private _getItemsInCluster;
232
+ /**
233
+ * Count co-occurrences between two sets of assignments
234
+ */
235
+ private _countCoOccurrences;
236
+ /**
237
+ * Calculate fusion confidence based on algorithm agreement
238
+ */
239
+ private _calculateFusionConfidence;
240
+ /**
241
+ * Generate empty clustering result for edge cases
242
+ */
243
+ private _createEmptyResult;
244
+ /**
245
+ * Get sample using specified strategy for large dataset clustering
246
+ */
247
+ private _getSampleUsingStrategy;
248
+ /**
249
+ * Random sampling
250
+ */
251
+ private _getRandomSample;
252
+ /**
253
+ * Diverse sampling using vector space distribution
254
+ */
255
+ private _getDiverseSample;
256
+ /**
257
+ * Recent sampling based on creation time
258
+ */
259
+ private _getRecentSample;
260
+ /**
261
+ * Important sampling based on connection count and metadata
262
+ */
263
+ private _getImportantSample;
264
+ /**
265
+ * Project clusters back to full dataset using HNSW neighbors
266
+ */
267
+ private _projectClustersToFullDataset;
268
+ private _groupByDomain;
269
+ private _calculateDomainConfidence;
270
+ private _findCrossDomainMembers;
271
+ private _findCrossDomainClusters;
272
+ private _getItemsByTimeWindow;
273
+ private _calculateTemporalMetrics;
274
+ private _mergeOverlappingTemporalClusters;
275
+ private _adjustThresholdAdaptively;
276
+ private _calculateItemToClusterSimilarity;
277
+ private _recalculateClusterCentroid;
278
+ private _calculateSimilarity;
279
+ private _sortNeighbors;
280
+ private _buildSemanticHierarchy;
281
+ private _detectOutliersClusterBased;
282
+ private _detectOutliersIsolation;
283
+ private _detectOutliersStatistical;
284
+ private _generateVisualizationNodes;
285
+ private _generateVisualizationEdges;
286
+ private _generateVisualizationClusters;
287
+ private _applyLayoutAlgorithm;
288
+ private _manhattanDistance;
289
+ private _calculateConfidence;
290
+ private _generateSimilarityExplanation;
291
+ /**
292
+ * Get performance metrics for monitoring
293
+ */
294
+ getPerformanceMetrics(operation?: string): Map<string, PerformanceMetrics[]> | PerformanceMetrics[];
295
+ /**
296
+ * Clear all caches
297
+ */
298
+ clearCaches(): void;
299
+ /**
300
+ * Get cache statistics
301
+ */
302
+ getCacheStats(): Record<string, {
303
+ size: number;
304
+ maxSize: number;
305
+ }>;
306
+ /**
307
+ * Analyze data characteristics for algorithm selection
308
+ */
309
+ private _analyzeDataCharacteristics;
310
+ /**
311
+ * Calculate centroid for a group of items
312
+ */
313
+ private _calculateGroupCentroid;
314
+ /**
315
+ * Cluster within semantic type using vector similarity
316
+ */
317
+ private _clusterWithinSemanticType;
318
+ /**
319
+ * Find cross-type connections via verbs
320
+ */
321
+ private _findCrossTypeConnections;
322
+ /**
323
+ * Merge semantic clusters based on connections
324
+ */
325
+ private _mergeSemanticClusters;
326
+ /**
327
+ * Get optimal clustering level for HNSW
328
+ */
329
+ private _getOptimalClusteringLevel;
330
+ /**
331
+ * Get nodes at HNSW level
332
+ */
333
+ private _getHNSWLevelNodes;
334
+ /**
335
+ * Find cluster members using HNSW neighbors
336
+ */
337
+ private _findClusterMembers;
338
+ /**
339
+ * Calculate hierarchical clustering confidence
340
+ */
341
+ private _calculateHierarchicalConfidence;
342
+ /**
343
+ * Assign unassigned items to nearest clusters
344
+ */
345
+ private _assignUnassignedItems;
346
+ }