@soulcraft/brainy 1.5.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.
- package/CHANGELOG.md +188 -0
- package/LICENSE +2 -2
- package/README.md +201 -596
- package/bin/brainy-interactive.js +564 -0
- package/bin/brainy-ts.js +18 -0
- package/bin/brainy.js +672 -81
- package/dist/augmentationPipeline.d.ts +48 -220
- package/dist/augmentationPipeline.js +60 -508
- package/dist/augmentationRegistry.d.ts +22 -31
- package/dist/augmentationRegistry.js +28 -79
- package/dist/augmentations/apiServerAugmentation.d.ts +108 -0
- package/dist/augmentations/apiServerAugmentation.js +502 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +95 -0
- package/dist/augmentations/batchProcessingAugmentation.js +567 -0
- package/dist/augmentations/brainyAugmentation.d.ts +153 -0
- package/dist/augmentations/brainyAugmentation.js +145 -0
- package/dist/augmentations/cacheAugmentation.d.ts +105 -0
- package/dist/augmentations/cacheAugmentation.js +238 -0
- package/dist/augmentations/conduitAugmentations.d.ts +54 -156
- package/dist/augmentations/conduitAugmentations.js +156 -1082
- package/dist/augmentations/connectionPoolAugmentation.d.ts +62 -0
- package/dist/augmentations/connectionPoolAugmentation.js +316 -0
- package/dist/augmentations/defaultAugmentations.d.ts +53 -0
- package/dist/augmentations/defaultAugmentations.js +88 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +126 -0
- package/dist/augmentations/entityRegistryAugmentation.js +386 -0
- package/dist/augmentations/indexAugmentation.d.ts +117 -0
- package/dist/augmentations/indexAugmentation.js +284 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +152 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +554 -0
- package/dist/augmentations/metricsAugmentation.d.ts +202 -0
- package/dist/augmentations/metricsAugmentation.js +291 -0
- package/dist/augmentations/monitoringAugmentation.d.ts +94 -0
- package/dist/augmentations/monitoringAugmentation.js +227 -0
- package/dist/augmentations/neuralImport.d.ts +50 -117
- package/dist/augmentations/neuralImport.js +255 -629
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +52 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.js +162 -0
- package/dist/augmentations/serverSearchAugmentations.d.ts +43 -22
- package/dist/augmentations/serverSearchAugmentations.js +125 -72
- package/dist/augmentations/storageAugmentation.d.ts +54 -0
- package/dist/augmentations/storageAugmentation.js +93 -0
- package/dist/augmentations/storageAugmentations.d.ts +96 -0
- package/dist/augmentations/storageAugmentations.js +182 -0
- package/dist/augmentations/synapseAugmentation.d.ts +156 -0
- package/dist/augmentations/synapseAugmentation.js +312 -0
- package/dist/augmentations/walAugmentation.d.ts +108 -0
- package/dist/augmentations/walAugmentation.js +515 -0
- package/dist/brainyData.d.ts +404 -130
- package/dist/brainyData.js +1331 -853
- package/dist/chat/BrainyChat.d.ts +16 -8
- package/dist/chat/BrainyChat.js +60 -32
- package/dist/chat/ChatCLI.d.ts +1 -1
- package/dist/chat/ChatCLI.js +6 -6
- package/dist/cli/catalog.d.ts +3 -3
- package/dist/cli/catalog.js +116 -70
- package/dist/cli/commands/core.d.ts +61 -0
- package/dist/cli/commands/core.js +348 -0
- package/dist/cli/commands/neural.d.ts +25 -0
- package/dist/cli/commands/neural.js +508 -0
- package/dist/cli/commands/utility.d.ts +37 -0
- package/dist/cli/commands/utility.js +276 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +167 -0
- package/dist/cli/interactive.d.ts +164 -0
- package/dist/cli/interactive.js +542 -0
- package/dist/cortex/neuralImport.js +5 -5
- package/dist/critical/model-guardian.js +11 -4
- package/dist/embeddings/lightweight-embedder.d.ts +23 -0
- package/dist/embeddings/lightweight-embedder.js +136 -0
- package/dist/embeddings/universal-memory-manager.d.ts +38 -0
- package/dist/embeddings/universal-memory-manager.js +206 -0
- package/dist/embeddings/worker-embedding.d.ts +7 -0
- package/dist/embeddings/worker-embedding.js +77 -0
- package/dist/embeddings/worker-manager.d.ts +28 -0
- package/dist/embeddings/worker-manager.js +162 -0
- package/dist/examples/basicUsage.js +7 -7
- package/dist/graph/pathfinding.d.ts +78 -0
- package/dist/graph/pathfinding.js +393 -0
- package/dist/hnsw/hnswIndex.d.ts +13 -0
- package/dist/hnsw/hnswIndex.js +35 -0
- package/dist/hnsw/hnswIndexOptimized.d.ts +1 -0
- package/dist/hnsw/hnswIndexOptimized.js +3 -0
- package/dist/index.d.ts +9 -11
- package/dist/index.js +21 -11
- package/dist/indices/fieldIndex.d.ts +76 -0
- package/dist/indices/fieldIndex.js +357 -0
- package/dist/mcp/brainyMCPAdapter.js +3 -2
- package/dist/mcp/mcpAugmentationToolset.js +11 -17
- package/dist/neural/embeddedPatterns.d.ts +41 -0
- package/dist/neural/embeddedPatterns.js +4044 -0
- package/dist/neural/naturalLanguageProcessor.d.ts +94 -0
- package/dist/neural/naturalLanguageProcessor.js +317 -0
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +64 -0
- package/dist/neural/naturalLanguageProcessorStatic.js +151 -0
- package/dist/neural/neuralAPI.d.ts +255 -0
- package/dist/neural/neuralAPI.js +612 -0
- package/dist/neural/patternLibrary.d.ts +101 -0
- package/dist/neural/patternLibrary.js +313 -0
- package/dist/neural/patterns.d.ts +27 -0
- package/dist/neural/patterns.js +68 -0
- package/dist/neural/staticPatternMatcher.d.ts +35 -0
- package/dist/neural/staticPatternMatcher.js +153 -0
- package/dist/scripts/precomputePatternEmbeddings.d.ts +19 -0
- package/dist/scripts/precomputePatternEmbeddings.js +100 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +5 -0
- package/dist/storage/adapters/fileSystemStorage.js +20 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +5 -0
- package/dist/storage/adapters/s3CompatibleStorage.js +16 -0
- package/dist/storage/enhancedClearOperations.d.ts +83 -0
- package/dist/storage/enhancedClearOperations.js +345 -0
- package/dist/storage/storageFactory.js +31 -27
- package/dist/triple/TripleIntelligence.d.ts +134 -0
- package/dist/triple/TripleIntelligence.js +548 -0
- package/dist/types/augmentations.d.ts +45 -344
- package/dist/types/augmentations.js +5 -2
- package/dist/types/brainyDataInterface.d.ts +20 -10
- package/dist/types/graphTypes.d.ts +46 -0
- package/dist/types/graphTypes.js +16 -2
- package/dist/utils/BoundedRegistry.d.ts +29 -0
- package/dist/utils/BoundedRegistry.js +54 -0
- package/dist/utils/embedding.js +20 -3
- package/dist/utils/hybridModelManager.js +10 -5
- package/dist/utils/metadataFilter.d.ts +33 -19
- package/dist/utils/metadataFilter.js +58 -23
- package/dist/utils/metadataIndex.d.ts +37 -6
- package/dist/utils/metadataIndex.js +427 -64
- package/dist/utils/requestDeduplicator.d.ts +10 -0
- package/dist/utils/requestDeduplicator.js +24 -0
- package/dist/utils/unifiedCache.d.ts +103 -0
- package/dist/utils/unifiedCache.js +311 -0
- package/package.json +43 -128
- package/scripts/ensure-models.js +108 -0
- package/scripts/prepare-models.js +387 -0
- package/OFFLINE_MODELS.md +0 -56
- package/dist/intelligence/neuralEngine.d.ts +0 -207
- package/dist/intelligence/neuralEngine.js +0 -706
- package/dist/utils/modelLoader.d.ts +0 -32
- package/dist/utils/modelLoader.js +0 -219
- package/dist/utils/modelManager.d.ts +0 -77
- package/dist/utils/modelManager.js +0 -219
package/dist/index.js
CHANGED
|
@@ -53,15 +53,18 @@ export { FileSystemStorage } from './storage/adapters/fileSystemStorage.js';
|
|
|
53
53
|
// Export unified pipeline
|
|
54
54
|
import { Pipeline, pipeline, augmentationPipeline, ExecutionMode, createPipeline, createStreamingPipeline, StreamlinedExecutionMode } from './pipeline.js';
|
|
55
55
|
// Sequential pipeline removed - use unified pipeline instead
|
|
56
|
-
//
|
|
57
|
-
import { createSenseAugmentation, addWebSocketSupport, executeAugmentation, loadAugmentationModule } from './augmentationFactory.js';
|
|
56
|
+
// REMOVED: Old augmentation factory for 2.0 clean architecture
|
|
58
57
|
export {
|
|
59
58
|
// Unified pipeline exports
|
|
60
59
|
Pipeline, pipeline, augmentationPipeline, ExecutionMode,
|
|
61
60
|
// Factory functions
|
|
62
|
-
createPipeline, createStreamingPipeline, StreamlinedExecutionMode,
|
|
63
|
-
// Augmentation factory exports
|
|
64
|
-
createSenseAugmentation,
|
|
61
|
+
createPipeline, createStreamingPipeline, StreamlinedExecutionMode,
|
|
62
|
+
// Augmentation factory exports (REMOVED in 2.0 - Use BrainyAugmentation interface)
|
|
63
|
+
// createSenseAugmentation, // → Use BaseAugmentation class
|
|
64
|
+
// addWebSocketSupport, // → Use APIServerAugmentation
|
|
65
|
+
// executeAugmentation, // → Use brain.augmentations.execute()
|
|
66
|
+
// loadAugmentationModule // → Use dynamic imports
|
|
67
|
+
};
|
|
65
68
|
// Export augmentation registry for build-time loading
|
|
66
69
|
import { availableAugmentations, registerAugmentation, initializeAugmentationPipeline, setAugmentationEnabled, getAugmentationsByType } from './augmentationRegistry.js';
|
|
67
70
|
export { availableAugmentations, registerAugmentation, initializeAugmentationPipeline, setAugmentationEnabled, getAugmentationsByType };
|
|
@@ -69,19 +72,26 @@ export { availableAugmentations, registerAugmentation, initializeAugmentationPip
|
|
|
69
72
|
import { loadAugmentationsFromModules, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin } from './augmentationRegistryLoader.js';
|
|
70
73
|
export { loadAugmentationsFromModules, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin };
|
|
71
74
|
// Export augmentation implementations
|
|
72
|
-
import {
|
|
73
|
-
import {
|
|
75
|
+
import { StorageAugmentation, DynamicStorageAugmentation, createStorageAugmentationFromConfig } from './augmentations/storageAugmentation.js';
|
|
76
|
+
import { MemoryStorageAugmentation, FileSystemStorageAugmentation, OPFSStorageAugmentation, S3StorageAugmentation, R2StorageAugmentation, GCSStorageAugmentation, createAutoStorageAugmentation } from './augmentations/storageAugmentations.js';
|
|
77
|
+
import { WebSocketConduitAugmentation } from './augmentations/conduitAugmentations.js';
|
|
74
78
|
import { ServerSearchConduitAugmentation, ServerSearchActivationAugmentation, createServerSearchAugmentations } from './augmentations/serverSearchAugmentations.js';
|
|
75
|
-
//
|
|
76
|
-
export {
|
|
79
|
+
// Storage augmentation exports
|
|
80
|
+
export {
|
|
81
|
+
// Base classes
|
|
82
|
+
StorageAugmentation, DynamicStorageAugmentation,
|
|
83
|
+
// Concrete implementations
|
|
84
|
+
MemoryStorageAugmentation, FileSystemStorageAugmentation, OPFSStorageAugmentation, S3StorageAugmentation, R2StorageAugmentation, GCSStorageAugmentation,
|
|
85
|
+
// Factory functions
|
|
86
|
+
createAutoStorageAugmentation, createStorageAugmentationFromConfig };
|
|
87
|
+
// Other augmentation exports
|
|
88
|
+
export { WebSocketConduitAugmentation, ServerSearchConduitAugmentation, ServerSearchActivationAugmentation, createServerSearchAugmentations };
|
|
77
89
|
// Export HNSW index and optimized version
|
|
78
90
|
import { HNSWIndex } from './hnsw/hnswIndex.js';
|
|
79
91
|
import { HNSWIndexOptimized } from './hnsw/hnswIndexOptimized.js';
|
|
80
92
|
export { HNSWIndex, HNSWIndexOptimized };
|
|
81
|
-
import { AugmentationType } from './types/augmentations.js';
|
|
82
93
|
// Export augmentation manager for type-safe augmentation management
|
|
83
94
|
export { AugmentationManager } from './augmentationManager.js';
|
|
84
|
-
export { AugmentationType };
|
|
85
95
|
import { NounType, VerbType } from './types/graphTypes.js';
|
|
86
96
|
// Export type utility functions
|
|
87
97
|
import { getNounTypes, getVerbTypes, getNounTypeMap, getVerbTypeMap } from './utils/typeUtils.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field Index for efficient field-based queries
|
|
3
|
+
* Provides O(log n) lookups for field values and range queries
|
|
4
|
+
*/
|
|
5
|
+
interface RangeQueryOptions {
|
|
6
|
+
field: string;
|
|
7
|
+
min?: any;
|
|
8
|
+
max?: any;
|
|
9
|
+
includeMin?: boolean;
|
|
10
|
+
includeMax?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class FieldIndex {
|
|
13
|
+
private indices;
|
|
14
|
+
private sortedIndices;
|
|
15
|
+
private indexedFields;
|
|
16
|
+
/**
|
|
17
|
+
* Add a document to the field index
|
|
18
|
+
*/
|
|
19
|
+
add(id: string, metadata: Record<string, any>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Remove a document from the field index
|
|
22
|
+
*/
|
|
23
|
+
remove(id: string, metadata: Record<string, any>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Query for exact field value match
|
|
26
|
+
* O(1) hash lookup
|
|
27
|
+
*/
|
|
28
|
+
queryExact(field: string, value: any): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Query for multiple values (IN operator)
|
|
31
|
+
* O(k) where k is number of values
|
|
32
|
+
*/
|
|
33
|
+
queryIn(field: string, values: any[]): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Query for range of values
|
|
36
|
+
* O(log n + m) where m is number of results
|
|
37
|
+
*/
|
|
38
|
+
queryRange(options: RangeQueryOptions): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Query with complex where clause
|
|
41
|
+
*/
|
|
42
|
+
query(where: Record<string, any>): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Mark sorted index as needing rebuild
|
|
45
|
+
*/
|
|
46
|
+
private markSortedIndexDirty;
|
|
47
|
+
/**
|
|
48
|
+
* Ensure sorted index is up to date for a field
|
|
49
|
+
*/
|
|
50
|
+
private ensureSortedIndex;
|
|
51
|
+
/**
|
|
52
|
+
* Binary search for start position (inclusive)
|
|
53
|
+
*/
|
|
54
|
+
private binarySearch;
|
|
55
|
+
/**
|
|
56
|
+
* Binary search for end position (inclusive)
|
|
57
|
+
*/
|
|
58
|
+
private binarySearchEnd;
|
|
59
|
+
/**
|
|
60
|
+
* Debug method to inspect index contents
|
|
61
|
+
*/
|
|
62
|
+
debugIndex(field?: string): any;
|
|
63
|
+
/**
|
|
64
|
+
* Get statistics about the index
|
|
65
|
+
*/
|
|
66
|
+
getStats(): {
|
|
67
|
+
indexedFields: number;
|
|
68
|
+
totalValues: number;
|
|
69
|
+
totalMappings: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Clear all indices
|
|
73
|
+
*/
|
|
74
|
+
clear(): void;
|
|
75
|
+
}
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field Index for efficient field-based queries
|
|
3
|
+
* Provides O(log n) lookups for field values and range queries
|
|
4
|
+
*/
|
|
5
|
+
export class FieldIndex {
|
|
6
|
+
constructor() {
|
|
7
|
+
// Inverted index: field -> value -> noun IDs
|
|
8
|
+
this.indices = new Map();
|
|
9
|
+
// Sorted arrays for range queries: field -> sorted [value, ids] pairs
|
|
10
|
+
this.sortedIndices = new Map();
|
|
11
|
+
// Track which fields are indexed
|
|
12
|
+
this.indexedFields = new Set();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Add a document to the field index
|
|
16
|
+
*/
|
|
17
|
+
add(id, metadata) {
|
|
18
|
+
if (!metadata)
|
|
19
|
+
return;
|
|
20
|
+
for (const [field, value] of Object.entries(metadata)) {
|
|
21
|
+
// Skip null/undefined values
|
|
22
|
+
if (value === null || value === undefined)
|
|
23
|
+
continue;
|
|
24
|
+
// Get or create field index
|
|
25
|
+
if (!this.indices.has(field)) {
|
|
26
|
+
this.indices.set(field, new Map());
|
|
27
|
+
this.sortedIndices.set(field, []);
|
|
28
|
+
this.indexedFields.add(field);
|
|
29
|
+
}
|
|
30
|
+
const fieldIndex = this.indices.get(field);
|
|
31
|
+
// Get or create value set
|
|
32
|
+
if (!fieldIndex.has(value)) {
|
|
33
|
+
fieldIndex.set(value, new Set());
|
|
34
|
+
}
|
|
35
|
+
// Add ID to value set
|
|
36
|
+
fieldIndex.get(value).add(id);
|
|
37
|
+
// Mark sorted index as dirty (needs rebuild)
|
|
38
|
+
this.markSortedIndexDirty(field);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Remove a document from the field index
|
|
43
|
+
*/
|
|
44
|
+
remove(id, metadata) {
|
|
45
|
+
if (!metadata)
|
|
46
|
+
return;
|
|
47
|
+
for (const [field, value] of Object.entries(metadata)) {
|
|
48
|
+
if (value === null || value === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
const fieldIndex = this.indices.get(field);
|
|
51
|
+
if (!fieldIndex)
|
|
52
|
+
continue;
|
|
53
|
+
const valueSet = fieldIndex.get(value);
|
|
54
|
+
if (!valueSet)
|
|
55
|
+
continue;
|
|
56
|
+
valueSet.delete(id);
|
|
57
|
+
// Clean up empty sets
|
|
58
|
+
if (valueSet.size === 0) {
|
|
59
|
+
fieldIndex.delete(value);
|
|
60
|
+
this.markSortedIndexDirty(field);
|
|
61
|
+
}
|
|
62
|
+
// Clean up empty field indices
|
|
63
|
+
if (fieldIndex.size === 0) {
|
|
64
|
+
this.indices.delete(field);
|
|
65
|
+
this.sortedIndices.delete(field);
|
|
66
|
+
this.indexedFields.delete(field);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Query for exact field value match
|
|
72
|
+
* O(1) hash lookup
|
|
73
|
+
*/
|
|
74
|
+
queryExact(field, value) {
|
|
75
|
+
const fieldIndex = this.indices.get(field);
|
|
76
|
+
if (!fieldIndex)
|
|
77
|
+
return [];
|
|
78
|
+
const ids = fieldIndex.get(value);
|
|
79
|
+
return ids ? Array.from(ids) : [];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Query for multiple values (IN operator)
|
|
83
|
+
* O(k) where k is number of values
|
|
84
|
+
*/
|
|
85
|
+
queryIn(field, values) {
|
|
86
|
+
const fieldIndex = this.indices.get(field);
|
|
87
|
+
if (!fieldIndex)
|
|
88
|
+
return [];
|
|
89
|
+
const resultSet = new Set();
|
|
90
|
+
for (const value of values) {
|
|
91
|
+
const ids = fieldIndex.get(value);
|
|
92
|
+
if (ids) {
|
|
93
|
+
for (const id of ids) {
|
|
94
|
+
resultSet.add(id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return Array.from(resultSet);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Query for range of values
|
|
102
|
+
* O(log n + m) where m is number of results
|
|
103
|
+
*/
|
|
104
|
+
queryRange(options) {
|
|
105
|
+
const { field, min, max, includeMin = true, includeMax = true } = options;
|
|
106
|
+
// Ensure sorted index is up to date
|
|
107
|
+
this.ensureSortedIndex(field);
|
|
108
|
+
const sortedIndex = this.sortedIndices.get(field);
|
|
109
|
+
if (!sortedIndex || sortedIndex.length === 0)
|
|
110
|
+
return [];
|
|
111
|
+
const resultSet = new Set();
|
|
112
|
+
// Binary search for start position
|
|
113
|
+
let start = 0;
|
|
114
|
+
let end = sortedIndex.length - 1;
|
|
115
|
+
if (min !== undefined) {
|
|
116
|
+
start = this.binarySearch(sortedIndex, min, includeMin);
|
|
117
|
+
}
|
|
118
|
+
if (max !== undefined) {
|
|
119
|
+
end = this.binarySearchEnd(sortedIndex, max, includeMax);
|
|
120
|
+
}
|
|
121
|
+
// Collect all IDs in range
|
|
122
|
+
for (let i = start; i <= end && i < sortedIndex.length; i++) {
|
|
123
|
+
const [value, ids] = sortedIndex[i];
|
|
124
|
+
// Check if value is in range
|
|
125
|
+
if (min !== undefined) {
|
|
126
|
+
const minCheck = includeMin ? value >= min : value > min;
|
|
127
|
+
if (!minCheck)
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (max !== undefined) {
|
|
131
|
+
const maxCheck = includeMax ? value <= max : value < max;
|
|
132
|
+
if (!maxCheck)
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
for (const id of ids) {
|
|
136
|
+
resultSet.add(id);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return Array.from(resultSet);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Query with complex where clause
|
|
143
|
+
*/
|
|
144
|
+
query(where) {
|
|
145
|
+
const resultSets = [];
|
|
146
|
+
for (const [field, condition] of Object.entries(where)) {
|
|
147
|
+
let fieldResults = [];
|
|
148
|
+
if (typeof condition === 'object' && condition !== null) {
|
|
149
|
+
// Handle operators
|
|
150
|
+
if (condition.equals !== undefined) {
|
|
151
|
+
fieldResults = this.queryExact(field, condition.equals);
|
|
152
|
+
}
|
|
153
|
+
else if (condition.in !== undefined && Array.isArray(condition.in)) {
|
|
154
|
+
fieldResults = this.queryIn(field, condition.in);
|
|
155
|
+
}
|
|
156
|
+
else if (condition.greaterThan !== undefined || condition.lessThan !== undefined) {
|
|
157
|
+
fieldResults = this.queryRange({
|
|
158
|
+
field,
|
|
159
|
+
min: condition.greaterThan,
|
|
160
|
+
max: condition.lessThan,
|
|
161
|
+
includeMin: false,
|
|
162
|
+
includeMax: false
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else if (condition.greaterEqual !== undefined || condition.lessEqual !== undefined) {
|
|
166
|
+
fieldResults = this.queryRange({
|
|
167
|
+
field,
|
|
168
|
+
min: condition.greaterEqual,
|
|
169
|
+
max: condition.lessEqual,
|
|
170
|
+
includeMin: true,
|
|
171
|
+
includeMax: true
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else if (condition.between !== undefined && Array.isArray(condition.between)) {
|
|
175
|
+
fieldResults = this.queryRange({
|
|
176
|
+
field,
|
|
177
|
+
min: condition.between[0],
|
|
178
|
+
max: condition.between[1],
|
|
179
|
+
includeMin: true,
|
|
180
|
+
includeMax: true
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else if (condition.exists !== undefined) {
|
|
184
|
+
// Return all IDs that have this field
|
|
185
|
+
if (condition.exists) {
|
|
186
|
+
const fieldIndex = this.indices.get(field);
|
|
187
|
+
if (fieldIndex) {
|
|
188
|
+
const allIds = new Set();
|
|
189
|
+
for (const ids of fieldIndex.values()) {
|
|
190
|
+
for (const id of ids) {
|
|
191
|
+
allIds.add(id);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
fieldResults = Array.from(allIds);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// Direct value match
|
|
201
|
+
fieldResults = this.queryExact(field, condition);
|
|
202
|
+
}
|
|
203
|
+
if (fieldResults.length > 0) {
|
|
204
|
+
resultSets.push(new Set(fieldResults));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// If any field has no matches, intersection will be empty
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Intersect all result sets (AND operation)
|
|
212
|
+
if (resultSets.length === 0)
|
|
213
|
+
return [];
|
|
214
|
+
if (resultSets.length === 1)
|
|
215
|
+
return Array.from(resultSets[0]);
|
|
216
|
+
let intersection = resultSets[0];
|
|
217
|
+
for (let i = 1; i < resultSets.length; i++) {
|
|
218
|
+
const nextSet = resultSets[i];
|
|
219
|
+
const newIntersection = new Set();
|
|
220
|
+
// Use smaller set for iteration (optimization)
|
|
221
|
+
const [smaller, larger] = intersection.size <= nextSet.size
|
|
222
|
+
? [intersection, nextSet]
|
|
223
|
+
: [nextSet, intersection];
|
|
224
|
+
for (const id of smaller) {
|
|
225
|
+
if (larger.has(id)) {
|
|
226
|
+
newIntersection.add(id);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
intersection = newIntersection;
|
|
230
|
+
// Early exit if intersection is empty
|
|
231
|
+
if (intersection.size === 0)
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
return Array.from(intersection);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Mark sorted index as needing rebuild
|
|
238
|
+
*/
|
|
239
|
+
markSortedIndexDirty(field) {
|
|
240
|
+
// For now, we'll rebuild on demand
|
|
241
|
+
// Could optimize with a dirty flag if needed
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Ensure sorted index is up to date for a field
|
|
245
|
+
*/
|
|
246
|
+
ensureSortedIndex(field) {
|
|
247
|
+
const fieldIndex = this.indices.get(field);
|
|
248
|
+
if (!fieldIndex)
|
|
249
|
+
return;
|
|
250
|
+
// Rebuild sorted index from hash index
|
|
251
|
+
const sorted = [];
|
|
252
|
+
for (const [value, ids] of fieldIndex.entries()) {
|
|
253
|
+
sorted.push([value, ids]);
|
|
254
|
+
}
|
|
255
|
+
// Sort by value (handles numbers, strings, dates)
|
|
256
|
+
sorted.sort((a, b) => {
|
|
257
|
+
const aVal = a[0];
|
|
258
|
+
const bVal = b[0];
|
|
259
|
+
if (aVal < bVal)
|
|
260
|
+
return -1;
|
|
261
|
+
if (aVal > bVal)
|
|
262
|
+
return 1;
|
|
263
|
+
return 0;
|
|
264
|
+
});
|
|
265
|
+
this.sortedIndices.set(field, sorted);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Binary search for start position (inclusive)
|
|
269
|
+
*/
|
|
270
|
+
binarySearch(sorted, target, inclusive) {
|
|
271
|
+
let left = 0;
|
|
272
|
+
let right = sorted.length - 1;
|
|
273
|
+
let result = sorted.length;
|
|
274
|
+
while (left <= right) {
|
|
275
|
+
const mid = Math.floor((left + right) / 2);
|
|
276
|
+
const midVal = sorted[mid][0];
|
|
277
|
+
if (inclusive ? midVal >= target : midVal > target) {
|
|
278
|
+
result = mid;
|
|
279
|
+
right = mid - 1;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
left = mid + 1;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Binary search for end position (inclusive)
|
|
289
|
+
*/
|
|
290
|
+
binarySearchEnd(sorted, target, inclusive) {
|
|
291
|
+
let left = 0;
|
|
292
|
+
let right = sorted.length - 1;
|
|
293
|
+
let result = -1;
|
|
294
|
+
while (left <= right) {
|
|
295
|
+
const mid = Math.floor((left + right) / 2);
|
|
296
|
+
const midVal = sorted[mid][0];
|
|
297
|
+
if (inclusive ? midVal <= target : midVal < target) {
|
|
298
|
+
result = mid;
|
|
299
|
+
left = mid + 1;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
right = mid - 1;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Debug method to inspect index contents
|
|
309
|
+
*/
|
|
310
|
+
debugIndex(field) {
|
|
311
|
+
if (field) {
|
|
312
|
+
const fieldIndex = this.indices.get(field);
|
|
313
|
+
if (!fieldIndex)
|
|
314
|
+
return { error: 'Field not found', field };
|
|
315
|
+
const values = [];
|
|
316
|
+
for (const [value, ids] of fieldIndex.entries()) {
|
|
317
|
+
values.push({ value, type: typeof value, ids: Array.from(ids) });
|
|
318
|
+
}
|
|
319
|
+
return { field, values };
|
|
320
|
+
}
|
|
321
|
+
const allFields = {};
|
|
322
|
+
for (const [field, fieldIndex] of this.indices.entries()) {
|
|
323
|
+
allFields[field] = [];
|
|
324
|
+
for (const [value, ids] of fieldIndex.entries()) {
|
|
325
|
+
allFields[field].push({ value, type: typeof value, ids: Array.from(ids) });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return allFields;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get statistics about the index
|
|
332
|
+
*/
|
|
333
|
+
getStats() {
|
|
334
|
+
let totalValues = 0;
|
|
335
|
+
let totalMappings = 0;
|
|
336
|
+
for (const fieldIndex of this.indices.values()) {
|
|
337
|
+
totalValues += fieldIndex.size;
|
|
338
|
+
for (const ids of fieldIndex.values()) {
|
|
339
|
+
totalMappings += ids.size;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
indexedFields: this.indexedFields.size,
|
|
344
|
+
totalValues,
|
|
345
|
+
totalMappings
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Clear all indices
|
|
350
|
+
*/
|
|
351
|
+
clear() {
|
|
352
|
+
this.indices.clear();
|
|
353
|
+
this.sortedIndices.clear();
|
|
354
|
+
this.indexedFields.clear();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=fieldIndex.js.map
|
|
@@ -49,7 +49,7 @@ export class BrainyMCPAdapter {
|
|
|
49
49
|
if (!id) {
|
|
50
50
|
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "id" is required');
|
|
51
51
|
}
|
|
52
|
-
const noun = await this.brainyData.
|
|
52
|
+
const noun = await this.brainyData.getNoun(id);
|
|
53
53
|
if (!noun) {
|
|
54
54
|
return this.createErrorResponse(request.requestId, 'NOT_FOUND', `No noun found with id ${id}`);
|
|
55
55
|
}
|
|
@@ -78,7 +78,8 @@ export class BrainyMCPAdapter {
|
|
|
78
78
|
if (!text) {
|
|
79
79
|
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "text" is required');
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
// Add noun directly - addNoun handles string input automatically
|
|
82
|
+
const id = await this.brainyData.addNoun(text, metadata);
|
|
82
83
|
return this.createSuccessResponse(request.requestId, { id });
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
@@ -107,25 +107,19 @@ export class MCPAugmentationToolset {
|
|
|
107
107
|
* @returns The result of the pipeline execution
|
|
108
108
|
*/
|
|
109
109
|
async executePipeline(type, method, parameters) {
|
|
110
|
+
// In Brainy 2.0, we directly call methods on augmentation instances
|
|
111
|
+
// instead of using the old typed pipeline system
|
|
110
112
|
const { args = [], options = {} } = parameters;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return await
|
|
118
|
-
|
|
119
|
-
return await augmentationPipeline.executeMemoryPipeline(method, args, options);
|
|
120
|
-
case AugmentationType.PERCEPTION:
|
|
121
|
-
return await augmentationPipeline.executePerceptionPipeline(method, args, options);
|
|
122
|
-
case AugmentationType.DIALOG:
|
|
123
|
-
return await augmentationPipeline.executeDialogPipeline(method, args, options);
|
|
124
|
-
case AugmentationType.ACTIVATION:
|
|
125
|
-
return await augmentationPipeline.executeActivationPipeline(method, args, options);
|
|
126
|
-
default:
|
|
127
|
-
throw new Error(`Unsupported augmentation type: ${type}`);
|
|
113
|
+
// Get augmentations of the specified type
|
|
114
|
+
const augmentations = augmentationPipeline.getAugmentationsByType(type);
|
|
115
|
+
// Find the first augmentation that has the requested method
|
|
116
|
+
for (const augmentation of augmentations) {
|
|
117
|
+
if (typeof augmentation[method] === 'function') {
|
|
118
|
+
// Call the method directly on the augmentation instance
|
|
119
|
+
return await augmentation[method](...args, options);
|
|
120
|
+
}
|
|
128
121
|
}
|
|
122
|
+
throw new Error(`Method '${method}' not found in any ${type} augmentation`);
|
|
129
123
|
}
|
|
130
124
|
/**
|
|
131
125
|
* Checks if an augmentation type is valid
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🧠 BRAINY EMBEDDED PATTERNS
|
|
3
|
+
*
|
|
4
|
+
* AUTO-GENERATED - DO NOT EDIT
|
|
5
|
+
* Generated: 2025-08-26T19:59:35.203Z
|
|
6
|
+
* Patterns: 220
|
|
7
|
+
* Coverage: 94-98% of all queries
|
|
8
|
+
*
|
|
9
|
+
* This file contains ALL patterns and embeddings compiled into Brainy.
|
|
10
|
+
* No external files needed, no runtime loading, instant availability!
|
|
11
|
+
*/
|
|
12
|
+
import type { Pattern } from './patternLibrary.js';
|
|
13
|
+
export declare const EMBEDDED_PATTERNS: Pattern[];
|
|
14
|
+
/**
|
|
15
|
+
* Get pattern embeddings as a Map for fast lookup
|
|
16
|
+
* This is called once at startup and cached
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPatternEmbeddings(): Map<string, Float32Array>;
|
|
19
|
+
export declare const PATTERNS_METADATA: {
|
|
20
|
+
version: string;
|
|
21
|
+
totalPatterns: number;
|
|
22
|
+
categories: string[];
|
|
23
|
+
domains: string[];
|
|
24
|
+
embeddingDimensions: number;
|
|
25
|
+
averageConfidence: number;
|
|
26
|
+
coverage: {
|
|
27
|
+
general: string;
|
|
28
|
+
programming: string;
|
|
29
|
+
ai_ml: string;
|
|
30
|
+
social: string;
|
|
31
|
+
medical_legal: string;
|
|
32
|
+
financial_academic: string;
|
|
33
|
+
ecommerce: string;
|
|
34
|
+
overall: string;
|
|
35
|
+
};
|
|
36
|
+
sizeBytes: {
|
|
37
|
+
patterns: number;
|
|
38
|
+
embeddings: number;
|
|
39
|
+
total: number;
|
|
40
|
+
};
|
|
41
|
+
};
|