@soulcraft/brainy 3.0.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.
- package/CHANGELOG.md +53 -3
- package/README.md +353 -110
- package/bin/brainy.js +340 -62
- package/dist/api/ConfigAPI.d.ts +67 -0
- package/dist/api/ConfigAPI.js +166 -0
- package/dist/api/DataAPI.d.ts +123 -0
- package/dist/api/DataAPI.js +391 -0
- package/dist/api/SecurityAPI.d.ts +50 -0
- package/dist/api/SecurityAPI.js +139 -0
- package/dist/api/UniversalImportAPI.d.ts +134 -0
- package/dist/api/UniversalImportAPI.js +615 -0
- package/dist/augmentationManager.js +12 -7
- package/dist/augmentationPipeline.d.ts +0 -61
- package/dist/augmentationPipeline.js +0 -87
- package/dist/augmentationRegistry.d.ts +1 -1
- package/dist/augmentationRegistry.js +1 -1
- package/dist/augmentations/apiServerAugmentation.d.ts +27 -1
- package/dist/augmentations/apiServerAugmentation.js +290 -9
- package/dist/augmentations/auditLogAugmentation.d.ts +109 -0
- package/dist/augmentations/auditLogAugmentation.js +358 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +3 -2
- package/dist/augmentations/batchProcessingAugmentation.js +123 -22
- package/dist/augmentations/brainyAugmentation.d.ts +142 -8
- package/dist/augmentations/brainyAugmentation.js +179 -2
- package/dist/augmentations/cacheAugmentation.d.ts +8 -5
- package/dist/augmentations/cacheAugmentation.js +116 -17
- package/dist/augmentations/conduitAugmentations.d.ts +2 -2
- package/dist/augmentations/conduitAugmentations.js +2 -2
- package/dist/augmentations/configResolver.d.ts +122 -0
- package/dist/augmentations/configResolver.js +440 -0
- package/dist/augmentations/connectionPoolAugmentation.d.ts +3 -1
- package/dist/augmentations/connectionPoolAugmentation.js +37 -12
- package/dist/augmentations/defaultAugmentations.d.ts +14 -10
- package/dist/augmentations/defaultAugmentations.js +16 -11
- package/dist/augmentations/discovery/catalogDiscovery.d.ts +142 -0
- package/dist/augmentations/discovery/catalogDiscovery.js +249 -0
- package/dist/augmentations/discovery/localDiscovery.d.ts +84 -0
- package/dist/augmentations/discovery/localDiscovery.js +246 -0
- package/dist/augmentations/discovery/runtimeLoader.d.ts +97 -0
- package/dist/augmentations/discovery/runtimeLoader.js +337 -0
- package/dist/augmentations/discovery.d.ts +152 -0
- package/dist/augmentations/discovery.js +441 -0
- package/dist/augmentations/display/cache.d.ts +130 -0
- package/dist/augmentations/display/cache.js +319 -0
- package/dist/augmentations/display/fieldPatterns.d.ts +52 -0
- package/dist/augmentations/display/fieldPatterns.js +393 -0
- package/dist/augmentations/display/iconMappings.d.ts +57 -0
- package/dist/augmentations/display/iconMappings.js +68 -0
- package/dist/augmentations/display/intelligentComputation.d.ts +109 -0
- package/dist/augmentations/display/intelligentComputation.js +462 -0
- package/dist/augmentations/display/types.d.ts +203 -0
- package/dist/augmentations/display/types.js +7 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +3 -1
- package/dist/augmentations/entityRegistryAugmentation.js +5 -1
- package/dist/augmentations/indexAugmentation.d.ts +5 -3
- package/dist/augmentations/indexAugmentation.js +5 -2
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +24 -7
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +111 -27
- package/dist/augmentations/manifest.d.ts +176 -0
- package/dist/augmentations/manifest.js +8 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +168 -0
- package/dist/augmentations/marketplace/AugmentationMarketplace.js +329 -0
- package/dist/augmentations/marketplace/cli.d.ts +47 -0
- package/dist/augmentations/marketplace/cli.js +265 -0
- package/dist/augmentations/metricsAugmentation.d.ts +3 -3
- package/dist/augmentations/metricsAugmentation.js +2 -2
- package/dist/augmentations/monitoringAugmentation.d.ts +3 -3
- package/dist/augmentations/monitoringAugmentation.js +2 -2
- package/dist/augmentations/neuralImport.d.ts +1 -1
- package/dist/augmentations/neuralImport.js +4 -4
- package/dist/augmentations/rateLimitAugmentation.d.ts +82 -0
- package/dist/augmentations/rateLimitAugmentation.js +321 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +2 -2
- package/dist/augmentations/requestDeduplicatorAugmentation.js +1 -1
- package/dist/augmentations/storageAugmentation.d.ts +1 -1
- package/dist/augmentations/storageAugmentation.js +2 -2
- package/dist/augmentations/storageAugmentations.d.ts +37 -8
- package/dist/augmentations/storageAugmentations.js +204 -15
- package/dist/augmentations/synapseAugmentation.d.ts +1 -1
- package/dist/augmentations/synapseAugmentation.js +35 -16
- package/dist/augmentations/typeMatching/brainyTypes.d.ts +83 -0
- package/dist/augmentations/typeMatching/brainyTypes.js +425 -0
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +39 -59
- package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +103 -389
- package/dist/augmentations/universalDisplayAugmentation.d.ts +191 -0
- package/dist/augmentations/universalDisplayAugmentation.js +371 -0
- package/dist/brainy-unified.d.ts +106 -0
- package/dist/brainy-unified.js +327 -0
- package/dist/brainy.d.ts +273 -0
- package/dist/brainy.js +1181 -0
- package/dist/brainyData.d.ts +56 -111
- package/dist/brainyData.js +912 -756
- package/dist/brainyDataV3.d.ts +186 -0
- package/dist/brainyDataV3.js +337 -0
- package/dist/browserFramework.d.ts +6 -6
- package/dist/browserFramework.js +11 -8
- package/dist/browserFramework.minimal.d.ts +5 -5
- package/dist/browserFramework.minimal.js +11 -8
- package/dist/config/distributedPresets-new.d.ts +118 -0
- package/dist/config/distributedPresets-new.js +318 -0
- package/dist/config/distributedPresets.d.ts +118 -0
- package/dist/config/distributedPresets.js +318 -0
- package/dist/config/extensibleConfig.d.ts +99 -0
- package/dist/config/extensibleConfig.js +268 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +35 -0
- package/dist/config/modelAutoConfig.d.ts +32 -0
- package/dist/config/modelAutoConfig.js +139 -0
- package/dist/config/modelPrecisionManager.d.ts +42 -0
- package/dist/config/modelPrecisionManager.js +98 -0
- package/dist/config/sharedConfigManager.d.ts +67 -0
- package/dist/config/sharedConfigManager.js +215 -0
- package/dist/config/storageAutoConfig.d.ts +41 -0
- package/dist/config/storageAutoConfig.js +328 -0
- package/dist/config/zeroConfig.d.ts +68 -0
- package/dist/config/zeroConfig.js +301 -0
- package/dist/cortex/backupRestore.d.ts +2 -2
- package/dist/cortex/backupRestore.js +85 -27
- package/dist/cortex/healthCheck.d.ts +2 -2
- package/dist/cortex/neuralImport.d.ts +2 -2
- package/dist/cortex/neuralImport.js +18 -13
- package/dist/cortex/performanceMonitor.d.ts +2 -2
- package/dist/critical/model-guardian.d.ts +4 -0
- package/dist/critical/model-guardian.js +31 -11
- package/dist/demo.d.ts +4 -4
- package/dist/demo.js +7 -7
- package/dist/distributed/cacheSync.d.ts +112 -0
- package/dist/distributed/cacheSync.js +265 -0
- package/dist/distributed/coordinator.d.ts +193 -0
- package/dist/distributed/coordinator.js +548 -0
- package/dist/distributed/httpTransport.d.ts +120 -0
- package/dist/distributed/httpTransport.js +446 -0
- package/dist/distributed/index.d.ts +8 -0
- package/dist/distributed/index.js +5 -0
- package/dist/distributed/networkTransport.d.ts +132 -0
- package/dist/distributed/networkTransport.js +633 -0
- package/dist/distributed/queryPlanner.d.ts +104 -0
- package/dist/distributed/queryPlanner.js +327 -0
- package/dist/distributed/readWriteSeparation.d.ts +134 -0
- package/dist/distributed/readWriteSeparation.js +350 -0
- package/dist/distributed/shardManager.d.ts +114 -0
- package/dist/distributed/shardManager.js +357 -0
- package/dist/distributed/shardMigration.d.ts +110 -0
- package/dist/distributed/shardMigration.js +289 -0
- package/dist/distributed/storageDiscovery.d.ts +160 -0
- package/dist/distributed/storageDiscovery.js +551 -0
- package/dist/embeddings/CachedEmbeddings.d.ts +40 -0
- package/dist/embeddings/CachedEmbeddings.js +146 -0
- package/dist/embeddings/EmbeddingManager.d.ts +102 -0
- package/dist/embeddings/EmbeddingManager.js +291 -0
- package/dist/embeddings/SingletonModelManager.d.ts +95 -0
- package/dist/embeddings/SingletonModelManager.js +220 -0
- package/dist/embeddings/index.d.ts +12 -0
- package/dist/embeddings/index.js +16 -0
- package/dist/embeddings/lightweight-embedder.d.ts +0 -1
- package/dist/embeddings/lightweight-embedder.js +4 -12
- package/dist/embeddings/model-manager.d.ts +11 -0
- package/dist/embeddings/model-manager.js +43 -7
- package/dist/embeddings/universal-memory-manager.d.ts +1 -1
- package/dist/embeddings/universal-memory-manager.js +27 -67
- package/dist/embeddings/worker-embedding.js +4 -8
- package/dist/errors/brainyError.d.ts +5 -1
- package/dist/errors/brainyError.js +12 -0
- package/dist/examples/basicUsage.js +7 -4
- package/dist/graph/graphAdjacencyIndex.d.ts +96 -0
- package/dist/graph/graphAdjacencyIndex.js +288 -0
- package/dist/graph/pathfinding.js +4 -2
- package/dist/hnsw/scaledHNSWSystem.js +11 -2
- package/dist/importManager.js +8 -5
- package/dist/index.d.ts +17 -22
- package/dist/index.js +37 -23
- package/dist/mcp/brainyMCPAdapter.d.ts +4 -4
- package/dist/mcp/brainyMCPAdapter.js +5 -5
- package/dist/mcp/brainyMCPService.d.ts +3 -3
- package/dist/mcp/brainyMCPService.js +3 -11
- package/dist/mcp/mcpAugmentationToolset.js +20 -30
- package/dist/neural/embeddedPatterns.d.ts +1 -1
- package/dist/neural/embeddedPatterns.js +2 -2
- package/dist/neural/entityExtractor.d.ts +65 -0
- package/dist/neural/entityExtractor.js +316 -0
- package/dist/neural/improvedNeuralAPI.d.ts +357 -0
- package/dist/neural/improvedNeuralAPI.js +2628 -0
- package/dist/neural/naturalLanguageProcessor.d.ts +155 -10
- package/dist/neural/naturalLanguageProcessor.js +941 -66
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +2 -2
- package/dist/neural/naturalLanguageProcessorStatic.js +3 -3
- package/dist/neural/neuralAPI.js +8 -2
- package/dist/neural/patternLibrary.d.ts +57 -3
- package/dist/neural/patternLibrary.js +348 -13
- package/dist/neural/staticPatternMatcher.d.ts +2 -2
- package/dist/neural/staticPatternMatcher.js +2 -2
- package/dist/neural/types.d.ts +287 -0
- package/dist/neural/types.js +24 -0
- package/dist/shared/default-augmentations.d.ts +3 -3
- package/dist/shared/default-augmentations.js +5 -5
- package/dist/storage/adapters/baseStorageAdapter.d.ts +42 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +26 -2
- package/dist/storage/adapters/fileSystemStorage.js +218 -15
- package/dist/storage/adapters/memoryStorage.d.ts +4 -4
- package/dist/storage/adapters/memoryStorage.js +17 -12
- package/dist/storage/adapters/opfsStorage.d.ts +2 -2
- package/dist/storage/adapters/opfsStorage.js +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +2 -2
- package/dist/storage/adapters/s3CompatibleStorage.js +2 -2
- package/dist/storage/backwardCompatibility.d.ts +10 -78
- package/dist/storage/backwardCompatibility.js +17 -132
- package/dist/storage/baseStorage.d.ts +18 -2
- package/dist/storage/baseStorage.js +74 -3
- package/dist/storage/cacheManager.js +2 -2
- package/dist/storage/readOnlyOptimizations.js +8 -3
- package/dist/streaming/pipeline.d.ts +154 -0
- package/dist/streaming/pipeline.js +551 -0
- package/dist/triple/TripleIntelligence.d.ts +25 -110
- package/dist/triple/TripleIntelligence.js +4 -574
- package/dist/triple/TripleIntelligenceSystem.d.ts +159 -0
- package/dist/triple/TripleIntelligenceSystem.js +519 -0
- package/dist/types/apiTypes.d.ts +278 -0
- package/dist/types/apiTypes.js +33 -0
- package/dist/types/brainy.types.d.ts +308 -0
- package/dist/types/brainy.types.js +8 -0
- package/dist/types/brainyDataInterface.d.ts +5 -8
- package/dist/types/brainyDataInterface.js +2 -2
- package/dist/types/graphTypes.js +2 -2
- package/dist/utils/brainyTypes.d.ts +217 -0
- package/dist/utils/brainyTypes.js +261 -0
- package/dist/utils/cacheAutoConfig.d.ts +3 -3
- package/dist/utils/embedding.d.ts +9 -4
- package/dist/utils/embedding.js +89 -26
- package/dist/utils/enhancedLogger.d.ts +104 -0
- package/dist/utils/enhancedLogger.js +232 -0
- package/dist/utils/hybridModelManager.d.ts +19 -28
- package/dist/utils/hybridModelManager.js +36 -200
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/intelligentTypeMapper.d.ts +60 -0
- package/dist/utils/intelligentTypeMapper.js +349 -0
- package/dist/utils/metadataIndex.d.ts +118 -1
- package/dist/utils/metadataIndex.js +539 -16
- package/dist/utils/nodeVersionCheck.d.ts +24 -0
- package/dist/utils/nodeVersionCheck.js +65 -0
- package/dist/utils/paramValidation.d.ts +39 -0
- package/dist/utils/paramValidation.js +192 -0
- package/dist/utils/rateLimiter.d.ts +160 -0
- package/dist/utils/rateLimiter.js +271 -0
- package/dist/utils/statistics.d.ts +4 -4
- package/dist/utils/statistics.js +3 -3
- package/dist/utils/structuredLogger.d.ts +146 -0
- package/dist/utils/structuredLogger.js +394 -0
- package/dist/utils/textEncoding.js +2 -1
- package/dist/utils/typeValidation.d.ts +59 -0
- package/dist/utils/typeValidation.js +374 -0
- package/dist/utils/version.js +19 -3
- package/package.json +15 -4
- package/scripts/download-models.cjs +94 -20
- package/dist/augmentations/walAugmentation.d.ts +0 -109
- package/dist/augmentations/walAugmentation.js +0 -516
- package/dist/chat/BrainyChat.d.ts +0 -121
- package/dist/chat/BrainyChat.js +0 -396
- package/dist/chat/ChatCLI.d.ts +0 -61
- package/dist/chat/ChatCLI.js +0 -351
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrainyTypes - Complete type management for Brainy
|
|
3
|
+
*
|
|
4
|
+
* Provides type lists, validation, and intelligent suggestions
|
|
5
|
+
* for nouns and verbs using semantic embeddings.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BrainyTypes } from '@soulcraft/brainy'
|
|
10
|
+
*
|
|
11
|
+
* // Get all available types
|
|
12
|
+
* const nounTypes = BrainyTypes.nouns // ['Person', 'Organization', ...]
|
|
13
|
+
* const verbTypes = BrainyTypes.verbs // ['Contains', 'Creates', ...]
|
|
14
|
+
*
|
|
15
|
+
* // Validate types
|
|
16
|
+
* BrainyTypes.isValidNoun('Person') // true
|
|
17
|
+
* BrainyTypes.isValidVerb('Unknown') // false
|
|
18
|
+
*
|
|
19
|
+
* // Get intelligent suggestions
|
|
20
|
+
* const personData = {
|
|
21
|
+
* name: 'John Doe',
|
|
22
|
+
* email: 'john@example.com'
|
|
23
|
+
* }
|
|
24
|
+
* const suggestion = await BrainyTypes.suggestNoun(personData)
|
|
25
|
+
* console.log(suggestion.type) // 'Person'
|
|
26
|
+
* console.log(suggestion.confidence) // 0.92
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
30
|
+
/**
|
|
31
|
+
* Type suggestion result
|
|
32
|
+
*/
|
|
33
|
+
export interface TypeSuggestion {
|
|
34
|
+
/** The suggested type */
|
|
35
|
+
type: NounType | VerbType;
|
|
36
|
+
/** Confidence score between 0 and 1 */
|
|
37
|
+
confidence: number;
|
|
38
|
+
/** Human-readable explanation */
|
|
39
|
+
reason?: string;
|
|
40
|
+
/** Alternative suggestions */
|
|
41
|
+
alternatives?: Array<{
|
|
42
|
+
type: NounType | VerbType;
|
|
43
|
+
confidence: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* BrainyTypes - Complete type management for Brainy
|
|
48
|
+
*
|
|
49
|
+
* Static class providing type lists, validation, and intelligent suggestions.
|
|
50
|
+
* No instantiation needed - all methods are static.
|
|
51
|
+
*/
|
|
52
|
+
export declare class BrainyTypes {
|
|
53
|
+
private static instance;
|
|
54
|
+
private static initialized;
|
|
55
|
+
/**
|
|
56
|
+
* All available noun types
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* BrainyTypes.nouns.forEach(type => console.log(type))
|
|
60
|
+
* // 'Person', 'Organization', 'Location', ...
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
static readonly nouns: readonly NounType[];
|
|
64
|
+
/**
|
|
65
|
+
* All available verb types
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* BrainyTypes.verbs.forEach(type => console.log(type))
|
|
69
|
+
* // 'Contains', 'Creates', 'RelatedTo', ...
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
static readonly verbs: readonly VerbType[];
|
|
73
|
+
/**
|
|
74
|
+
* Get or create the internal matcher instance
|
|
75
|
+
*/
|
|
76
|
+
private static getInternalMatcher;
|
|
77
|
+
/**
|
|
78
|
+
* Check if a string is a valid noun type
|
|
79
|
+
*
|
|
80
|
+
* @param type The type string to check
|
|
81
|
+
* @returns True if valid noun type
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* BrainyTypes.isValidNoun('Person') // true
|
|
86
|
+
* BrainyTypes.isValidNoun('Unknown') // false
|
|
87
|
+
* BrainyTypes.isValidNoun('Contains') // false (it's a verb)
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
static isValidNoun(type: string): type is NounType;
|
|
91
|
+
/**
|
|
92
|
+
* Check if a string is a valid verb type
|
|
93
|
+
*
|
|
94
|
+
* @param type The type string to check
|
|
95
|
+
* @returns True if valid verb type
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* BrainyTypes.isValidVerb('Contains') // true
|
|
100
|
+
* BrainyTypes.isValidVerb('Unknown') // false
|
|
101
|
+
* BrainyTypes.isValidVerb('Person') // false (it's a noun)
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
static isValidVerb(type: string): type is VerbType;
|
|
105
|
+
/**
|
|
106
|
+
* Suggest the most appropriate noun type for an object
|
|
107
|
+
*
|
|
108
|
+
* @param data The object or data to analyze
|
|
109
|
+
* @returns Promise resolving to type suggestion with confidence score
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const data = {
|
|
114
|
+
* title: 'Quarterly Report',
|
|
115
|
+
* author: 'Jane Smith',
|
|
116
|
+
* pages: 42
|
|
117
|
+
* }
|
|
118
|
+
* const suggestion = await BrainyTypes.suggestNoun(data)
|
|
119
|
+
* console.log(suggestion.type) // 'Document'
|
|
120
|
+
* console.log(suggestion.confidence) // 0.88
|
|
121
|
+
*
|
|
122
|
+
* // Check alternatives if confidence is low
|
|
123
|
+
* if (suggestion.confidence < 0.8) {
|
|
124
|
+
* console.log('Also consider:', suggestion.alternatives)
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
static suggestNoun(data: any): Promise<TypeSuggestion>;
|
|
129
|
+
/**
|
|
130
|
+
* Suggest the most appropriate verb type for a relationship
|
|
131
|
+
*
|
|
132
|
+
* @param source The source entity
|
|
133
|
+
* @param target The target entity
|
|
134
|
+
* @param hint Optional hint about the relationship
|
|
135
|
+
* @returns Promise resolving to type suggestion with confidence score
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const source = { type: 'Person', name: 'Alice' }
|
|
140
|
+
* const target = { type: 'Document', title: 'Research Paper' }
|
|
141
|
+
*
|
|
142
|
+
* const suggestion = await BrainyTypes.suggestVerb(source, target, 'authored')
|
|
143
|
+
* console.log(suggestion.type) // 'CreatedBy'
|
|
144
|
+
* console.log(suggestion.confidence) // 0.91
|
|
145
|
+
*
|
|
146
|
+
* // Without hint
|
|
147
|
+
* const suggestion2 = await BrainyTypes.suggestVerb(source, target)
|
|
148
|
+
* console.log(suggestion2.type) // 'RelatedTo' (more generic)
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
static suggestVerb(source: any, target: any, hint?: string): Promise<TypeSuggestion>;
|
|
152
|
+
/**
|
|
153
|
+
* Get a noun type by name (with validation)
|
|
154
|
+
*
|
|
155
|
+
* @param name The noun type name
|
|
156
|
+
* @returns The NounType enum value
|
|
157
|
+
* @throws Error if invalid noun type
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const type = BrainyTypes.getNoun('Person') // NounType.Person
|
|
162
|
+
* const bad = BrainyTypes.getNoun('Unknown') // throws Error
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
static getNoun(name: string): NounType;
|
|
166
|
+
/**
|
|
167
|
+
* Get a verb type by name (with validation)
|
|
168
|
+
*
|
|
169
|
+
* @param name The verb type name
|
|
170
|
+
* @returns The VerbType enum value
|
|
171
|
+
* @throws Error if invalid verb type
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const type = BrainyTypes.getVerb('Contains') // VerbType.Contains
|
|
176
|
+
* const bad = BrainyTypes.getVerb('Unknown') // throws Error
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
static getVerb(name: string): VerbType;
|
|
180
|
+
/**
|
|
181
|
+
* Clear the internal cache
|
|
182
|
+
* Useful when processing many different types of data
|
|
183
|
+
*/
|
|
184
|
+
static clearCache(): void;
|
|
185
|
+
/**
|
|
186
|
+
* Dispose of resources
|
|
187
|
+
* Call when completely done using BrainyTypes
|
|
188
|
+
*/
|
|
189
|
+
static dispose(): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Get noun types as a plain object (for iteration)
|
|
192
|
+
* @returns Object with noun type names as keys
|
|
193
|
+
*/
|
|
194
|
+
static getNounMap(): Record<string, NounType>;
|
|
195
|
+
/**
|
|
196
|
+
* Get verb types as a plain object (for iteration)
|
|
197
|
+
* @returns Object with verb type names as keys
|
|
198
|
+
*/
|
|
199
|
+
static getVerbMap(): Record<string, VerbType>;
|
|
200
|
+
}
|
|
201
|
+
export { NounType, VerbType };
|
|
202
|
+
/**
|
|
203
|
+
* Helper function to validate and suggest types in one call
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* import { suggestType } from '@soulcraft/brainy'
|
|
208
|
+
*
|
|
209
|
+
* // For nouns
|
|
210
|
+
* const nounSuggestion = await suggestType('noun', data)
|
|
211
|
+
*
|
|
212
|
+
* // For verbs
|
|
213
|
+
* const verbSuggestion = await suggestType('verb', source, target)
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export declare function suggestType(kind: 'noun', data: any): Promise<TypeSuggestion>;
|
|
217
|
+
export declare function suggestType(kind: 'verb', source: any, target: any, hint?: string): Promise<TypeSuggestion>;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrainyTypes - Complete type management for Brainy
|
|
3
|
+
*
|
|
4
|
+
* Provides type lists, validation, and intelligent suggestions
|
|
5
|
+
* for nouns and verbs using semantic embeddings.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { BrainyTypes } from '@soulcraft/brainy'
|
|
10
|
+
*
|
|
11
|
+
* // Get all available types
|
|
12
|
+
* const nounTypes = BrainyTypes.nouns // ['Person', 'Organization', ...]
|
|
13
|
+
* const verbTypes = BrainyTypes.verbs // ['Contains', 'Creates', ...]
|
|
14
|
+
*
|
|
15
|
+
* // Validate types
|
|
16
|
+
* BrainyTypes.isValidNoun('Person') // true
|
|
17
|
+
* BrainyTypes.isValidVerb('Unknown') // false
|
|
18
|
+
*
|
|
19
|
+
* // Get intelligent suggestions
|
|
20
|
+
* const personData = {
|
|
21
|
+
* name: 'John Doe',
|
|
22
|
+
* email: 'john@example.com'
|
|
23
|
+
* }
|
|
24
|
+
* const suggestion = await BrainyTypes.suggestNoun(personData)
|
|
25
|
+
* console.log(suggestion.type) // 'Person'
|
|
26
|
+
* console.log(suggestion.confidence) // 0.92
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
30
|
+
import { BrainyTypes as InternalBrainyTypes } from '../augmentations/typeMatching/brainyTypes.js';
|
|
31
|
+
/**
|
|
32
|
+
* BrainyTypes - Complete type management for Brainy
|
|
33
|
+
*
|
|
34
|
+
* Static class providing type lists, validation, and intelligent suggestions.
|
|
35
|
+
* No instantiation needed - all methods are static.
|
|
36
|
+
*/
|
|
37
|
+
export class BrainyTypes {
|
|
38
|
+
/**
|
|
39
|
+
* Get or create the internal matcher instance
|
|
40
|
+
*/
|
|
41
|
+
static async getInternalMatcher() {
|
|
42
|
+
if (!this.instance) {
|
|
43
|
+
this.instance = new InternalBrainyTypes();
|
|
44
|
+
await this.instance.init();
|
|
45
|
+
this.initialized = true;
|
|
46
|
+
}
|
|
47
|
+
return this.instance;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a string is a valid noun type
|
|
51
|
+
*
|
|
52
|
+
* @param type The type string to check
|
|
53
|
+
* @returns True if valid noun type
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* BrainyTypes.isValidNoun('Person') // true
|
|
58
|
+
* BrainyTypes.isValidNoun('Unknown') // false
|
|
59
|
+
* BrainyTypes.isValidNoun('Contains') // false (it's a verb)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
static isValidNoun(type) {
|
|
63
|
+
return this.nouns.includes(type);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a string is a valid verb type
|
|
67
|
+
*
|
|
68
|
+
* @param type The type string to check
|
|
69
|
+
* @returns True if valid verb type
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* BrainyTypes.isValidVerb('Contains') // true
|
|
74
|
+
* BrainyTypes.isValidVerb('Unknown') // false
|
|
75
|
+
* BrainyTypes.isValidVerb('Person') // false (it's a noun)
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
static isValidVerb(type) {
|
|
79
|
+
return this.verbs.includes(type);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Suggest the most appropriate noun type for an object
|
|
83
|
+
*
|
|
84
|
+
* @param data The object or data to analyze
|
|
85
|
+
* @returns Promise resolving to type suggestion with confidence score
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const data = {
|
|
90
|
+
* title: 'Quarterly Report',
|
|
91
|
+
* author: 'Jane Smith',
|
|
92
|
+
* pages: 42
|
|
93
|
+
* }
|
|
94
|
+
* const suggestion = await BrainyTypes.suggestNoun(data)
|
|
95
|
+
* console.log(suggestion.type) // 'Document'
|
|
96
|
+
* console.log(suggestion.confidence) // 0.88
|
|
97
|
+
*
|
|
98
|
+
* // Check alternatives if confidence is low
|
|
99
|
+
* if (suggestion.confidence < 0.8) {
|
|
100
|
+
* console.log('Also consider:', suggestion.alternatives)
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
static async suggestNoun(data) {
|
|
105
|
+
const matcher = await this.getInternalMatcher();
|
|
106
|
+
const result = await matcher.matchNounType(data);
|
|
107
|
+
return {
|
|
108
|
+
type: result.type,
|
|
109
|
+
confidence: result.confidence,
|
|
110
|
+
reason: result.reasoning,
|
|
111
|
+
alternatives: result.alternatives?.map(alt => ({
|
|
112
|
+
type: alt.type,
|
|
113
|
+
confidence: alt.confidence
|
|
114
|
+
}))
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Suggest the most appropriate verb type for a relationship
|
|
119
|
+
*
|
|
120
|
+
* @param source The source entity
|
|
121
|
+
* @param target The target entity
|
|
122
|
+
* @param hint Optional hint about the relationship
|
|
123
|
+
* @returns Promise resolving to type suggestion with confidence score
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const source = { type: 'Person', name: 'Alice' }
|
|
128
|
+
* const target = { type: 'Document', title: 'Research Paper' }
|
|
129
|
+
*
|
|
130
|
+
* const suggestion = await BrainyTypes.suggestVerb(source, target, 'authored')
|
|
131
|
+
* console.log(suggestion.type) // 'CreatedBy'
|
|
132
|
+
* console.log(suggestion.confidence) // 0.91
|
|
133
|
+
*
|
|
134
|
+
* // Without hint
|
|
135
|
+
* const suggestion2 = await BrainyTypes.suggestVerb(source, target)
|
|
136
|
+
* console.log(suggestion2.type) // 'RelatedTo' (more generic)
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
static async suggestVerb(source, target, hint) {
|
|
140
|
+
const matcher = await this.getInternalMatcher();
|
|
141
|
+
const result = await matcher.matchVerbType(source, target, hint);
|
|
142
|
+
return {
|
|
143
|
+
type: result.type,
|
|
144
|
+
confidence: result.confidence,
|
|
145
|
+
reason: result.reasoning,
|
|
146
|
+
alternatives: result.alternatives?.map(alt => ({
|
|
147
|
+
type: alt.type,
|
|
148
|
+
confidence: alt.confidence
|
|
149
|
+
}))
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get a noun type by name (with validation)
|
|
154
|
+
*
|
|
155
|
+
* @param name The noun type name
|
|
156
|
+
* @returns The NounType enum value
|
|
157
|
+
* @throws Error if invalid noun type
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const type = BrainyTypes.getNoun('Person') // NounType.Person
|
|
162
|
+
* const bad = BrainyTypes.getNoun('Unknown') // throws Error
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
static getNoun(name) {
|
|
166
|
+
if (!this.isValidNoun(name)) {
|
|
167
|
+
throw new Error(`Invalid noun type: '${name}'. Valid types are: ${this.nouns.join(', ')}`);
|
|
168
|
+
}
|
|
169
|
+
return name;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get a verb type by name (with validation)
|
|
173
|
+
*
|
|
174
|
+
* @param name The verb type name
|
|
175
|
+
* @returns The VerbType enum value
|
|
176
|
+
* @throws Error if invalid verb type
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const type = BrainyTypes.getVerb('Contains') // VerbType.Contains
|
|
181
|
+
* const bad = BrainyTypes.getVerb('Unknown') // throws Error
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
static getVerb(name) {
|
|
185
|
+
if (!this.isValidVerb(name)) {
|
|
186
|
+
throw new Error(`Invalid verb type: '${name}'. Valid types are: ${this.verbs.join(', ')}`);
|
|
187
|
+
}
|
|
188
|
+
return name;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Clear the internal cache
|
|
192
|
+
* Useful when processing many different types of data
|
|
193
|
+
*/
|
|
194
|
+
static clearCache() {
|
|
195
|
+
this.instance?.clearCache();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Dispose of resources
|
|
199
|
+
* Call when completely done using BrainyTypes
|
|
200
|
+
*/
|
|
201
|
+
static async dispose() {
|
|
202
|
+
if (this.instance) {
|
|
203
|
+
await this.instance.dispose();
|
|
204
|
+
this.instance = null;
|
|
205
|
+
this.initialized = false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Get noun types as a plain object (for iteration)
|
|
210
|
+
* @returns Object with noun type names as keys
|
|
211
|
+
*/
|
|
212
|
+
static getNounMap() {
|
|
213
|
+
const map = {};
|
|
214
|
+
for (const noun of this.nouns) {
|
|
215
|
+
map[noun] = noun;
|
|
216
|
+
}
|
|
217
|
+
return map;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get verb types as a plain object (for iteration)
|
|
221
|
+
* @returns Object with verb type names as keys
|
|
222
|
+
*/
|
|
223
|
+
static getVerbMap() {
|
|
224
|
+
const map = {};
|
|
225
|
+
for (const verb of this.verbs) {
|
|
226
|
+
map[verb] = verb;
|
|
227
|
+
}
|
|
228
|
+
return map;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
BrainyTypes.instance = null;
|
|
232
|
+
BrainyTypes.initialized = false;
|
|
233
|
+
/**
|
|
234
|
+
* All available noun types
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* BrainyTypes.nouns.forEach(type => console.log(type))
|
|
238
|
+
* // 'Person', 'Organization', 'Location', ...
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
BrainyTypes.nouns = Object.freeze(Object.values(NounType));
|
|
242
|
+
/**
|
|
243
|
+
* All available verb types
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* BrainyTypes.verbs.forEach(type => console.log(type))
|
|
247
|
+
* // 'Contains', 'Creates', 'RelatedTo', ...
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
BrainyTypes.verbs = Object.freeze(Object.values(VerbType));
|
|
251
|
+
// Re-export the enums for convenience
|
|
252
|
+
export { NounType, VerbType };
|
|
253
|
+
export async function suggestType(kind, ...args) {
|
|
254
|
+
if (kind === 'noun') {
|
|
255
|
+
return BrainyTypes.suggestNoun(args[0]);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return BrainyTypes.suggestVerb(args[0], args[1], args[2]);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=brainyTypes.js.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Adapts cache settings based on environment, usage patterns, and storage type
|
|
4
4
|
*/
|
|
5
5
|
import { SearchCacheConfig } from './searchCache.js';
|
|
6
|
-
import {
|
|
6
|
+
import { BrainyConfig } from '../brainy.js';
|
|
7
7
|
export interface CacheUsageStats {
|
|
8
8
|
totalQueries: number;
|
|
9
9
|
repeatQueries: number;
|
|
@@ -16,7 +16,7 @@ export interface CacheUsageStats {
|
|
|
16
16
|
}
|
|
17
17
|
export interface AutoConfigResult {
|
|
18
18
|
cacheConfig: SearchCacheConfig;
|
|
19
|
-
realtimeConfig: NonNullable<
|
|
19
|
+
realtimeConfig: NonNullable<BrainyConfig['realtimeUpdates']>;
|
|
20
20
|
reasoning: string[];
|
|
21
21
|
}
|
|
22
22
|
export declare class CacheAutoConfigurator {
|
|
@@ -26,7 +26,7 @@ export declare class CacheAutoConfigurator {
|
|
|
26
26
|
/**
|
|
27
27
|
* Auto-detect optimal cache configuration based on current conditions
|
|
28
28
|
*/
|
|
29
|
-
autoDetectOptimalConfig(storageConfig?:
|
|
29
|
+
autoDetectOptimalConfig(storageConfig?: BrainyConfig['storage'], currentStats?: Partial<CacheUsageStats>): AutoConfigResult;
|
|
30
30
|
/**
|
|
31
31
|
* Dynamically adjust configuration based on runtime performance
|
|
32
32
|
*/
|
|
@@ -25,8 +25,8 @@ export interface TransformerEmbeddingOptions {
|
|
|
25
25
|
cacheDir?: string;
|
|
26
26
|
/** Force local files only (no downloads) */
|
|
27
27
|
localFilesOnly?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/** Model precision: 'q8' = 75% smaller quantized model, 'fp32' = full precision (default) */
|
|
29
|
+
precision?: 'fp32' | 'q8';
|
|
30
30
|
/** Device to run inference on - 'auto' detects best available */
|
|
31
31
|
device?: 'auto' | 'cpu' | 'webgpu' | 'cuda' | 'gpu';
|
|
32
32
|
}
|
|
@@ -51,6 +51,10 @@ export declare class TransformerEmbedding implements EmbeddingModel {
|
|
|
51
51
|
* Log message only if verbose mode is enabled
|
|
52
52
|
*/
|
|
53
53
|
private logger;
|
|
54
|
+
/**
|
|
55
|
+
* Generate mock embeddings for unit tests
|
|
56
|
+
*/
|
|
57
|
+
private getMockEmbedding;
|
|
54
58
|
/**
|
|
55
59
|
* Initialize the embedding model
|
|
56
60
|
*/
|
|
@@ -78,12 +82,13 @@ export declare const UniversalSentenceEncoder: typeof TransformerEmbedding;
|
|
|
78
82
|
*/
|
|
79
83
|
export declare function createEmbeddingModel(options?: TransformerEmbeddingOptions): EmbeddingModel;
|
|
80
84
|
/**
|
|
81
|
-
* Default embedding function using the
|
|
82
|
-
*
|
|
85
|
+
* Default embedding function using the unified EmbeddingManager
|
|
86
|
+
* Simple, clean, reliable - no more layers of indirection
|
|
83
87
|
*/
|
|
84
88
|
export declare const defaultEmbeddingFunction: EmbeddingFunction;
|
|
85
89
|
/**
|
|
86
90
|
* Create an embedding function with custom options
|
|
91
|
+
* NOTE: Options are validated but the singleton EmbeddingManager is always used
|
|
87
92
|
*/
|
|
88
93
|
export declare function createEmbeddingFunction(options?: TransformerEmbeddingOptions): EmbeddingFunction;
|
|
89
94
|
/**
|