@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
package/README.md CHANGED
@@ -44,13 +44,13 @@ const brain = new BrainyData()
44
44
  await brain.init()
45
45
 
46
46
  // Add entities (nouns) with automatic embedding
47
- const jsId = await brain.addNoun("JavaScript is a programming language", {
47
+ const jsId = await brain.addNoun("JavaScript is a programming language", 'concept', {
48
48
  type: "language",
49
49
  year: 1995,
50
50
  paradigm: "multi-paradigm"
51
51
  })
52
52
 
53
- const nodeId = await brain.addNoun("Node.js runtime environment", {
53
+ const nodeId = await brain.addNoun("Node.js runtime environment", 'concept', {
54
54
  type: "runtime",
55
55
  year: 2009,
56
56
  platform: "server-side"
@@ -225,7 +225,7 @@ const results = await brain.find({
225
225
  ### CRUD Operations
226
226
  ```javascript
227
227
  // Create entities (nouns)
228
- const id = await brain.addNoun(data, metadata)
228
+ const id = await brain.addNoun(data, nounType, metadata)
229
229
 
230
230
  // Create relationships (verbs)
231
231
  const verbId = await brain.addVerb(sourceId, targetId, "relationType", {
@@ -255,18 +255,18 @@ const exported = await brain.export({ format: 'json' })
255
255
  ### Knowledge Management with Relationships
256
256
  ```javascript
257
257
  // Store documentation with rich relationships
258
- const apiGuide = await brain.addNoun("REST API Guide", {
258
+ const apiGuide = await brain.addNoun("REST API Guide", 'document', {
259
259
  title: "API Guide",
260
260
  category: "documentation",
261
261
  version: "2.0"
262
262
  })
263
263
 
264
- const author = await brain.addNoun("Jane Developer", {
264
+ const author = await brain.addNoun("Jane Developer", 'person', {
265
265
  type: "person",
266
266
  role: "tech-lead"
267
267
  })
268
268
 
269
- const project = await brain.addNoun("E-commerce Platform", {
269
+ const project = await brain.addNoun("E-commerce Platform", 'project', {
270
270
  type: "project",
271
271
  status: "active"
272
272
  })
@@ -295,18 +295,18 @@ const similar = await brain.search(existingContent, {
295
295
  ### AI Memory Layer with Context
296
296
  ```javascript
297
297
  // Store conversation with relationships
298
- const userId = await brain.addNoun("User 123", {
298
+ const userId = await brain.addNoun("User 123", 'user', {
299
299
  type: "user",
300
300
  tier: "premium"
301
301
  })
302
302
 
303
- const messageId = await brain.addNoun(userMessage, {
303
+ const messageId = await brain.addNoun(userMessage, 'message', {
304
304
  type: "message",
305
305
  timestamp: Date.now(),
306
306
  session: "abc"
307
307
  })
308
308
 
309
- const topicId = await brain.addNoun("Product Support", {
309
+ const topicId = await brain.addNoun("Product Support", 'topic', {
310
310
  type: "topic",
311
311
  category: "support"
312
312
  })
@@ -431,7 +431,7 @@ for (const cluster of feedbackClusters) {
431
431
  }
432
432
 
433
433
  // Find related documents
434
- const docId = await brain.addNoun("Machine learning guide")
434
+ const docId = await brain.addNoun("Machine learning guide", 'document')
435
435
  const similar = await neural.neighbors(docId, 5)
436
436
  // Returns 5 most similar documents
437
437
 
@@ -138,7 +138,7 @@ export class APIServerAugmentation extends BaseAugmentation {
138
138
  app.post('/api/add', async (req, res) => {
139
139
  try {
140
140
  const { content, metadata } = req.body;
141
- const id = await this.context.brain.add(content, metadata);
141
+ const id = await this.context.brain.addNoun(content, 'Content', metadata);
142
142
  res.json({ success: true, id });
143
143
  }
144
144
  catch (error) {
@@ -300,7 +300,7 @@ export class APIServerAugmentation extends BaseAugmentation {
300
300
  }));
301
301
  break;
302
302
  case 'add':
303
- const id = await this.context.brain.add(msg.content, msg.metadata);
303
+ const id = await this.context.brain.addNoun(msg.content, 'Content', msg.metadata);
304
304
  socket.send(JSON.stringify({
305
305
  type: 'addResult',
306
306
  requestId: msg.requestId,
@@ -24,7 +24,7 @@ export declare const TYPE_SPECIFIC_PATTERNS: Record<string, FieldPattern[]>;
24
24
  export declare function getFieldPatterns(entityType: 'noun' | 'verb', specificType?: string): FieldPattern[];
25
25
  /**
26
26
  * Priority fields for different entity types (for AI analysis)
27
- * Used by the IntelligentTypeMatcher and neural processing
27
+ * Used by the BrainyTypes and neural processing
28
28
  */
29
29
  export declare const TYPE_PRIORITY_FIELDS: Record<string, string[]>;
30
30
  /**
@@ -242,7 +242,7 @@ export function getFieldPatterns(entityType, specificType) {
242
242
  }
243
243
  /**
244
244
  * Priority fields for different entity types (for AI analysis)
245
- * Used by the IntelligentTypeMatcher and neural processing
245
+ * Used by the BrainyTypes and neural processing
246
246
  */
247
247
  export const TYPE_PRIORITY_FIELDS = {
248
248
  [NounType.Person]: [
@@ -2,7 +2,7 @@
2
2
  * Universal Display Augmentation - Intelligent Computation Engine
3
3
  *
4
4
  * Leverages existing Brainy AI infrastructure for intelligent field computation:
5
- * - IntelligentTypeMatcher for semantic type detection
5
+ * - BrainyTypes for semantic type detection
6
6
  * - Neural Import patterns for field analysis
7
7
  * - JSON processing utilities for field extraction
8
8
  * - Existing NounType/VerbType taxonomy (31+40 types)
@@ -36,7 +36,7 @@ export declare class IntelligentComputationEngine {
36
36
  */
37
37
  computeVerbDisplay(verb: GraphVerb): Promise<ComputedDisplayFields>;
38
38
  /**
39
- * AI-powered computation using your existing IntelligentTypeMatcher
39
+ * AI-powered computation using your existing BrainyTypes
40
40
  * @param data Entity data/metadata
41
41
  * @param entityType Type of entity (noun/verb)
42
42
  * @param options Additional options
@@ -2,12 +2,12 @@
2
2
  * Universal Display Augmentation - Intelligent Computation Engine
3
3
  *
4
4
  * Leverages existing Brainy AI infrastructure for intelligent field computation:
5
- * - IntelligentTypeMatcher for semantic type detection
5
+ * - BrainyTypes for semantic type detection
6
6
  * - Neural Import patterns for field analysis
7
7
  * - JSON processing utilities for field extraction
8
8
  * - Existing NounType/VerbType taxonomy (31+40 types)
9
9
  */
10
- import { getTypeMatcher } from '../typeMatching/intelligentTypeMatcher.js';
10
+ import { getBrainyTypes } from '../typeMatching/brainyTypes.js';
11
11
  import { getFieldPatterns, getPriorityFields } from './fieldPatterns.js';
12
12
  import { prepareJsonForVectorization } from '../../utils/jsonProcessing.js';
13
13
  import { NounType, VerbType } from '../../types/graphTypes.js';
@@ -29,7 +29,7 @@ export class IntelligentComputationEngine {
29
29
  return;
30
30
  try {
31
31
  // 🧠 LEVERAGE YOUR EXISTING AI INFRASTRUCTURE
32
- this.typeMatcher = await getTypeMatcher();
32
+ this.typeMatcher = await getBrainyTypes();
33
33
  if (this.typeMatcher) {
34
34
  console.log('🎨 Display computation engine initialized with AI intelligence');
35
35
  }
@@ -96,7 +96,7 @@ export class IntelligentComputationEngine {
96
96
  }
97
97
  }
98
98
  /**
99
- * AI-powered computation using your existing IntelligentTypeMatcher
99
+ * AI-powered computation using your existing BrainyTypes
100
100
  * @param data Entity data/metadata
101
101
  * @param entityType Type of entity (noun/verb)
102
102
  * @param options Additional options
@@ -83,7 +83,7 @@ export interface FieldComputationContext {
83
83
  };
84
84
  }
85
85
  /**
86
- * Type matching result from IntelligentTypeMatcher
86
+ * Type matching result from BrainyTypes
87
87
  */
88
88
  export interface TypeMatchResult {
89
89
  type: string;
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { BaseAugmentation } from './brainyAugmentation.js';
10
10
  import * as path from '../universal/path.js';
11
- import { getTypeMatcher } from './typeMatching/intelligentTypeMatcher.js';
11
+ import { getBrainyTypes } from './typeMatching/brainyTypes.js';
12
12
  import { prodLog } from '../utils/logger.js';
13
13
  /**
14
14
  * Neural Import Augmentation - Unified Implementation
@@ -37,7 +37,7 @@ export class NeuralImportAugmentation extends BaseAugmentation {
37
37
  }
38
38
  async onInitialize() {
39
39
  try {
40
- this.typeMatcher = await getTypeMatcher();
40
+ this.typeMatcher = await getBrainyTypes();
41
41
  this.log('🧠 Neural Import augmentation initialized with intelligent type matching');
42
42
  }
43
43
  catch (error) {
@@ -378,7 +378,7 @@ export class NeuralImportAugmentation extends BaseAugmentation {
378
378
  async inferNounType(obj) {
379
379
  if (!this.typeMatcher) {
380
380
  // Initialize type matcher if not available
381
- this.typeMatcher = await getTypeMatcher();
381
+ this.typeMatcher = await getBrainyTypes();
382
382
  }
383
383
  const result = await this.typeMatcher.matchNounType(obj);
384
384
  // Log if confidence is low for debugging
@@ -428,7 +428,7 @@ export class NeuralImportAugmentation extends BaseAugmentation {
428
428
  async inferVerbType(fieldName, sourceObj, targetObj) {
429
429
  if (!this.typeMatcher) {
430
430
  // Initialize type matcher if not available
431
- this.typeMatcher = await getTypeMatcher();
431
+ this.typeMatcher = await getBrainyTypes();
432
432
  }
433
433
  const result = await this.typeMatcher.matchVerbType(sourceObj, targetObj, fieldName);
434
434
  // Log if confidence is low for debugging
@@ -173,7 +173,7 @@ export class SynapseAugmentation extends BaseAugmentation {
173
173
  }
174
174
  // Store original content with neural metadata
175
175
  if (typeof content === 'string') {
176
- await this.context.brain.add(content, {
176
+ await this.context.brain.addNoun(content, 'Content', {
177
177
  ...enrichedMetadata,
178
178
  _neuralProcessed: true,
179
179
  _neuralConfidence: neuralResult.data.confidence,
@@ -190,11 +190,11 @@ export class SynapseAugmentation extends BaseAugmentation {
190
190
  }
191
191
  // Fallback to basic storage
192
192
  if (typeof content === 'string') {
193
- await this.context.brain.add(content, enrichedMetadata);
193
+ await this.context.brain.addNoun(content, 'Content', enrichedMetadata);
194
194
  }
195
195
  else {
196
196
  // For structured data, store as JSON
197
- await this.context.brain.add(JSON.stringify(content), enrichedMetadata);
197
+ await this.context.brain.addNoun(JSON.stringify(content), 'Content', enrichedMetadata);
198
198
  }
199
199
  }
200
200
  /**
@@ -0,0 +1,83 @@
1
+ /**
2
+ * BrainyTypes - Intelligent type detection using semantic embeddings
3
+ *
4
+ * This module uses our existing TransformerEmbedding and similarity functions
5
+ * to intelligently match data to our 31 noun types and 40 verb types.
6
+ *
7
+ * Features:
8
+ * - Semantic similarity matching using embeddings
9
+ * - Context-aware type detection
10
+ * - Confidence scoring
11
+ * - Caching for performance
12
+ */
13
+ /**
14
+ * Result of type matching with confidence scores
15
+ */
16
+ export interface TypeMatchResult {
17
+ type: string;
18
+ confidence: number;
19
+ reasoning: string;
20
+ alternatives: Array<{
21
+ type: string;
22
+ confidence: number;
23
+ }>;
24
+ }
25
+ /**
26
+ * BrainyTypes - Intelligent type detection for nouns and verbs
27
+ */
28
+ export declare class BrainyTypes {
29
+ private embedder;
30
+ private nounEmbeddings;
31
+ private verbEmbeddings;
32
+ private initialized;
33
+ private cache;
34
+ constructor();
35
+ /**
36
+ * Initialize the type matcher by generating embeddings for all types
37
+ */
38
+ init(): Promise<void>;
39
+ /**
40
+ * Match an object to the most appropriate noun type
41
+ */
42
+ matchNounType(obj: any): Promise<TypeMatchResult>;
43
+ /**
44
+ * Match a relationship to the most appropriate verb type
45
+ */
46
+ matchVerbType(sourceObj: any, targetObj: any, relationshipHint?: string): Promise<TypeMatchResult>;
47
+ /**
48
+ * Create text representation of an object for embedding
49
+ */
50
+ private createTextRepresentation;
51
+ /**
52
+ * Create text representation of a relationship
53
+ */
54
+ private createRelationshipText;
55
+ /**
56
+ * Get a brief summary of an object
57
+ */
58
+ private getObjectSummary;
59
+ /**
60
+ * Apply heuristic rules for noun type detection
61
+ */
62
+ private applyNounHeuristics;
63
+ /**
64
+ * Apply heuristic rules for verb type detection
65
+ */
66
+ private applyVerbHeuristics;
67
+ /**
68
+ * Generate human-readable reasoning for the type selection
69
+ */
70
+ private generateReasoning;
71
+ /**
72
+ * Clear the cache
73
+ */
74
+ clearCache(): void;
75
+ /**
76
+ * Dispose of resources
77
+ */
78
+ dispose(): Promise<void>;
79
+ }
80
+ /**
81
+ * Get or create the global BrainyTypes instance
82
+ */
83
+ export declare function getBrainyTypes(): Promise<BrainyTypes>;