@soulcraft/brainy 1.5.0 → 2.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 +188 -0
- package/LICENSE +2 -2
- package/README.md +200 -595
- 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 +40 -125
- 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/utils/embedding.js
CHANGED
|
@@ -6,6 +6,15 @@ import { isBrowser } from './environment.js';
|
|
|
6
6
|
import { ModelManager } from '../embeddings/model-manager.js';
|
|
7
7
|
// @ts-ignore - Transformers.js is now the primary embedding library
|
|
8
8
|
import { pipeline, env } from '@huggingface/transformers';
|
|
9
|
+
// CRITICAL: Disable ONNX memory arena to prevent 4-8GB allocation
|
|
10
|
+
// This is needed for BOTH production and testing - reduces memory by 50-75%
|
|
11
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
12
|
+
process.env.ORT_DISABLE_MEMORY_ARENA = '1';
|
|
13
|
+
process.env.ORT_DISABLE_MEMORY_PATTERN = '1';
|
|
14
|
+
// Also limit ONNX thread count for more predictable memory usage
|
|
15
|
+
process.env.ORT_INTRA_OP_NUM_THREADS = '2';
|
|
16
|
+
process.env.ORT_INTER_OP_NUM_THREADS = '2';
|
|
17
|
+
}
|
|
9
18
|
/**
|
|
10
19
|
* Detect the best available GPU device for the current environment
|
|
11
20
|
*/
|
|
@@ -89,7 +98,7 @@ export class TransformerEmbedding {
|
|
|
89
98
|
verbose: this.verbose,
|
|
90
99
|
cacheDir: options.cacheDir || './models',
|
|
91
100
|
localFilesOnly: localFilesOnly,
|
|
92
|
-
dtype: options.dtype || '
|
|
101
|
+
dtype: options.dtype || 'q8', // Changed from fp32 to q8 for 75% memory reduction
|
|
93
102
|
device: options.device || 'auto'
|
|
94
103
|
};
|
|
95
104
|
if (this.verbose) {
|
|
@@ -203,11 +212,19 @@ export class TransformerEmbedding {
|
|
|
203
212
|
: this.options.cacheDir;
|
|
204
213
|
this.logger('log', `Loading Transformer model: ${this.options.model} on device: ${device}`);
|
|
205
214
|
const startTime = Date.now();
|
|
206
|
-
// Load the feature extraction pipeline with
|
|
215
|
+
// Load the feature extraction pipeline with memory optimizations
|
|
207
216
|
const pipelineOptions = {
|
|
208
217
|
cache_dir: cacheDir,
|
|
209
218
|
local_files_only: isBrowser() ? false : this.options.localFilesOnly,
|
|
210
|
-
dtype: this.options.dtype
|
|
219
|
+
dtype: this.options.dtype || 'q8', // Use quantized model for lower memory
|
|
220
|
+
// CRITICAL: ONNX memory optimizations
|
|
221
|
+
session_options: {
|
|
222
|
+
enableCpuMemArena: false, // Disable pre-allocated memory arena
|
|
223
|
+
enableMemPattern: false, // Disable memory pattern optimization
|
|
224
|
+
interOpNumThreads: 2, // Limit thread count
|
|
225
|
+
intraOpNumThreads: 2, // Limit parallelism
|
|
226
|
+
graphOptimizationLevel: 'all'
|
|
227
|
+
}
|
|
211
228
|
};
|
|
212
229
|
// Add device configuration for GPU acceleration
|
|
213
230
|
if (device !== 'cpu') {
|
|
@@ -75,6 +75,11 @@ class HybridModelManager {
|
|
|
75
75
|
process.env.FUNCTIONS_WORKER_RUNTIME);
|
|
76
76
|
const isDocker = typeof process !== 'undefined' && (process.env.DOCKER_CONTAINER ||
|
|
77
77
|
process.env.KUBERNETES_SERVICE_HOST);
|
|
78
|
+
// Respect BRAINY_ALLOW_REMOTE_MODELS environment variable first
|
|
79
|
+
let forceLocalOnly = false;
|
|
80
|
+
if (process.env.BRAINY_ALLOW_REMOTE_MODELS !== undefined) {
|
|
81
|
+
forceLocalOnly = process.env.BRAINY_ALLOW_REMOTE_MODELS !== 'true';
|
|
82
|
+
}
|
|
78
83
|
// Smart configuration based on environment
|
|
79
84
|
let options = {
|
|
80
85
|
verbose: !isTest && !isServerless,
|
|
@@ -85,7 +90,7 @@ class HybridModelManager {
|
|
|
85
90
|
if (isBrowser) {
|
|
86
91
|
options = {
|
|
87
92
|
...options,
|
|
88
|
-
localFilesOnly: false,
|
|
93
|
+
localFilesOnly: forceLocalOnly || false, // Respect environment variable
|
|
89
94
|
dtype: 'q8',
|
|
90
95
|
device: 'cpu',
|
|
91
96
|
verbose: false
|
|
@@ -94,7 +99,7 @@ class HybridModelManager {
|
|
|
94
99
|
else if (isServerless) {
|
|
95
100
|
options = {
|
|
96
101
|
...options,
|
|
97
|
-
localFilesOnly: true,
|
|
102
|
+
localFilesOnly: forceLocalOnly || true, // Default true for serverless, but respect env
|
|
98
103
|
dtype: 'q8',
|
|
99
104
|
device: 'cpu',
|
|
100
105
|
verbose: false
|
|
@@ -103,7 +108,7 @@ class HybridModelManager {
|
|
|
103
108
|
else if (isDocker) {
|
|
104
109
|
options = {
|
|
105
110
|
...options,
|
|
106
|
-
localFilesOnly: true,
|
|
111
|
+
localFilesOnly: forceLocalOnly || true, // Default true for docker, but respect env
|
|
107
112
|
dtype: 'fp32',
|
|
108
113
|
device: 'auto',
|
|
109
114
|
verbose: false
|
|
@@ -113,7 +118,7 @@ class HybridModelManager {
|
|
|
113
118
|
// CRITICAL FOR TESTS: Allow remote downloads but be smart about it
|
|
114
119
|
options = {
|
|
115
120
|
...options,
|
|
116
|
-
localFilesOnly: false,
|
|
121
|
+
localFilesOnly: forceLocalOnly || false, // Respect environment variable for tests
|
|
117
122
|
dtype: 'q8',
|
|
118
123
|
device: 'cpu',
|
|
119
124
|
verbose: false
|
|
@@ -122,7 +127,7 @@ class HybridModelManager {
|
|
|
122
127
|
else {
|
|
123
128
|
options = {
|
|
124
129
|
...options,
|
|
125
|
-
localFilesOnly: false,
|
|
130
|
+
localFilesOnly: forceLocalOnly || false, // Respect environment variable for default node
|
|
126
131
|
dtype: 'q8',
|
|
127
132
|
device: 'auto',
|
|
128
133
|
verbose: true
|
|
@@ -5,31 +5,45 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { SearchResult, HNSWNoun } from '../coreTypes.js';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Brainy Field Operators (BFO) - Our own field query system
|
|
9
|
+
* Designed for performance, clarity, and patent independence
|
|
9
10
|
*/
|
|
10
|
-
export interface
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
export interface BrainyFieldOperators {
|
|
12
|
+
equals?: any;
|
|
13
|
+
notEquals?: any;
|
|
14
|
+
is?: any;
|
|
15
|
+
isNot?: any;
|
|
16
|
+
greaterThan?: any;
|
|
17
|
+
greaterEqual?: any;
|
|
18
|
+
lessThan?: any;
|
|
19
|
+
lessEqual?: any;
|
|
20
|
+
between?: [any, any];
|
|
21
|
+
oneOf?: any[];
|
|
22
|
+
noneOf?: any[];
|
|
23
|
+
contains?: any;
|
|
24
|
+
excludes?: any;
|
|
25
|
+
hasAll?: any[];
|
|
26
|
+
length?: number;
|
|
27
|
+
exists?: boolean;
|
|
28
|
+
missing?: boolean;
|
|
29
|
+
matches?: string | RegExp;
|
|
30
|
+
startsWith?: string;
|
|
31
|
+
endsWith?: string;
|
|
32
|
+
allOf?: MetadataFilter[];
|
|
33
|
+
anyOf?: MetadataFilter[];
|
|
34
|
+
not?: MetadataFilter;
|
|
35
|
+
eq?: any;
|
|
36
|
+
ne?: any;
|
|
37
|
+
gt?: any;
|
|
38
|
+
gte?: any;
|
|
39
|
+
lt?: any;
|
|
40
|
+
lte?: any;
|
|
27
41
|
}
|
|
28
42
|
/**
|
|
29
43
|
* Metadata filter definition
|
|
30
44
|
*/
|
|
31
45
|
export interface MetadataFilter {
|
|
32
|
-
[key: string]: any |
|
|
46
|
+
[key: string]: any | BrainyFieldOperators;
|
|
33
47
|
}
|
|
34
48
|
/**
|
|
35
49
|
* Options for metadata filtering
|
|
@@ -11,55 +11,67 @@ function matchesQuery(value, query) {
|
|
|
11
11
|
if (typeof query !== 'object' || query === null || Array.isArray(query)) {
|
|
12
12
|
return value === query;
|
|
13
13
|
}
|
|
14
|
-
// Check for
|
|
14
|
+
// Check for Brainy Field Operators (BFO)
|
|
15
15
|
for (const [op, operand] of Object.entries(query)) {
|
|
16
16
|
switch (op) {
|
|
17
|
-
|
|
17
|
+
// Equality operators
|
|
18
|
+
case 'equals':
|
|
19
|
+
case 'is':
|
|
20
|
+
case 'eq':
|
|
18
21
|
if (value !== operand)
|
|
19
22
|
return false;
|
|
20
23
|
break;
|
|
21
|
-
case '
|
|
24
|
+
case 'notEquals':
|
|
25
|
+
case 'isNot':
|
|
26
|
+
case 'ne':
|
|
22
27
|
if (value === operand)
|
|
23
28
|
return false;
|
|
24
29
|
break;
|
|
25
|
-
|
|
30
|
+
// Comparison operators
|
|
31
|
+
case 'greaterThan':
|
|
32
|
+
case 'gt':
|
|
26
33
|
if (typeof value !== 'number' || typeof operand !== 'number' || !(value > operand))
|
|
27
34
|
return false;
|
|
28
35
|
break;
|
|
29
|
-
case '
|
|
36
|
+
case 'greaterEqual':
|
|
37
|
+
case 'gte':
|
|
30
38
|
if (typeof value !== 'number' || typeof operand !== 'number' || !(value >= operand))
|
|
31
39
|
return false;
|
|
32
40
|
break;
|
|
33
|
-
case '
|
|
41
|
+
case 'lessThan':
|
|
42
|
+
case 'lt':
|
|
34
43
|
if (typeof value !== 'number' || typeof operand !== 'number' || !(value < operand))
|
|
35
44
|
return false;
|
|
36
45
|
break;
|
|
37
|
-
case '
|
|
46
|
+
case 'lessEqual':
|
|
47
|
+
case 'lte':
|
|
38
48
|
if (typeof value !== 'number' || typeof operand !== 'number' || !(value <= operand))
|
|
39
49
|
return false;
|
|
40
50
|
break;
|
|
41
|
-
case '
|
|
42
|
-
if (!Array.isArray(operand) ||
|
|
51
|
+
case 'between':
|
|
52
|
+
if (!Array.isArray(operand) || operand.length !== 2)
|
|
43
53
|
return false;
|
|
44
|
-
|
|
45
|
-
case '$nin':
|
|
46
|
-
if (!Array.isArray(operand) || operand.includes(value))
|
|
54
|
+
if (typeof value !== 'number' || !(value >= operand[0] && value <= operand[1]))
|
|
47
55
|
return false;
|
|
48
56
|
break;
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
// Array/Set operators
|
|
58
|
+
case 'oneOf':
|
|
59
|
+
if (!Array.isArray(operand) || !operand.includes(value))
|
|
51
60
|
return false;
|
|
52
61
|
break;
|
|
53
|
-
case '
|
|
54
|
-
|
|
55
|
-
if (!(regex instanceof RegExp) || !regex.test(String(value)))
|
|
62
|
+
case 'noneOf':
|
|
63
|
+
if (!Array.isArray(operand) || operand.includes(value))
|
|
56
64
|
return false;
|
|
57
65
|
break;
|
|
58
|
-
case '
|
|
66
|
+
case 'contains':
|
|
59
67
|
if (!Array.isArray(value) || !value.includes(operand))
|
|
60
68
|
return false;
|
|
61
69
|
break;
|
|
62
|
-
case '
|
|
70
|
+
case 'excludes':
|
|
71
|
+
if (!Array.isArray(value) || value.includes(operand))
|
|
72
|
+
return false;
|
|
73
|
+
break;
|
|
74
|
+
case 'hasAll':
|
|
63
75
|
if (!Array.isArray(value) || !Array.isArray(operand))
|
|
64
76
|
return false;
|
|
65
77
|
for (const item of operand) {
|
|
@@ -67,10 +79,33 @@ function matchesQuery(value, query) {
|
|
|
67
79
|
return false;
|
|
68
80
|
}
|
|
69
81
|
break;
|
|
70
|
-
case '
|
|
82
|
+
case 'length':
|
|
71
83
|
if (!Array.isArray(value) || value.length !== operand)
|
|
72
84
|
return false;
|
|
73
85
|
break;
|
|
86
|
+
// Existence operators
|
|
87
|
+
case 'exists':
|
|
88
|
+
if ((value !== undefined) !== operand)
|
|
89
|
+
return false;
|
|
90
|
+
break;
|
|
91
|
+
case 'missing':
|
|
92
|
+
if ((value === undefined) !== operand)
|
|
93
|
+
return false;
|
|
94
|
+
break;
|
|
95
|
+
// Pattern operators
|
|
96
|
+
case 'matches':
|
|
97
|
+
const regex = typeof operand === 'string' ? new RegExp(operand) : operand;
|
|
98
|
+
if (!(regex instanceof RegExp) || !regex.test(String(value)))
|
|
99
|
+
return false;
|
|
100
|
+
break;
|
|
101
|
+
case 'startsWith':
|
|
102
|
+
if (typeof value !== 'string' || !value.startsWith(String(operand)))
|
|
103
|
+
return false;
|
|
104
|
+
break;
|
|
105
|
+
case 'endsWith':
|
|
106
|
+
if (typeof value !== 'string' || !value.endsWith(String(operand)))
|
|
107
|
+
return false;
|
|
108
|
+
break;
|
|
74
109
|
default:
|
|
75
110
|
// Unknown operator, treat as field name
|
|
76
111
|
if (!matchesFieldQuery(value, op, operand))
|
|
@@ -109,7 +144,7 @@ export function matchesMetadataFilter(metadata, filter) {
|
|
|
109
144
|
}
|
|
110
145
|
for (const [key, query] of Object.entries(filter)) {
|
|
111
146
|
// Handle logical operators
|
|
112
|
-
if (key === '
|
|
147
|
+
if (key === 'allOf') {
|
|
113
148
|
if (!Array.isArray(query))
|
|
114
149
|
return false;
|
|
115
150
|
for (const subFilter of query) {
|
|
@@ -118,7 +153,7 @@ export function matchesMetadataFilter(metadata, filter) {
|
|
|
118
153
|
}
|
|
119
154
|
continue;
|
|
120
155
|
}
|
|
121
|
-
if (key === '
|
|
156
|
+
if (key === 'anyOf') {
|
|
122
157
|
if (!Array.isArray(query))
|
|
123
158
|
return false;
|
|
124
159
|
let matched = false;
|
|
@@ -132,7 +167,7 @@ export function matchesMetadataFilter(metadata, filter) {
|
|
|
132
167
|
return false;
|
|
133
168
|
continue;
|
|
134
169
|
}
|
|
135
|
-
if (key === '
|
|
170
|
+
if (key === 'not') {
|
|
136
171
|
if (matchesMetadataFilter(metadata, query))
|
|
137
172
|
return false;
|
|
138
173
|
continue;
|
|
@@ -28,10 +28,6 @@ export interface MetadataIndexConfig {
|
|
|
28
28
|
indexedFields?: string[];
|
|
29
29
|
excludeFields?: string[];
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Manages metadata indexes for fast filtering
|
|
33
|
-
* Maintains inverted indexes: field+value -> list of IDs
|
|
34
|
-
*/
|
|
35
31
|
export declare class MetadataIndexManager {
|
|
36
32
|
private storage;
|
|
37
33
|
private config;
|
|
@@ -43,11 +39,34 @@ export declare class MetadataIndexManager {
|
|
|
43
39
|
private dirtyFields;
|
|
44
40
|
private lastFlushTime;
|
|
45
41
|
private autoFlushThreshold;
|
|
42
|
+
private sortedIndices;
|
|
43
|
+
private numericFields;
|
|
44
|
+
private unifiedCache;
|
|
46
45
|
constructor(storage: StorageAdapter, config?: MetadataIndexConfig);
|
|
47
46
|
/**
|
|
48
47
|
* Get index key for field and value
|
|
49
48
|
*/
|
|
50
49
|
private getIndexKey;
|
|
50
|
+
/**
|
|
51
|
+
* Ensure sorted index exists for a field (for range queries)
|
|
52
|
+
*/
|
|
53
|
+
private ensureSortedIndex;
|
|
54
|
+
/**
|
|
55
|
+
* Build sorted index for a field from hash index
|
|
56
|
+
*/
|
|
57
|
+
private buildSortedIndex;
|
|
58
|
+
/**
|
|
59
|
+
* Binary search for range start (inclusive or exclusive)
|
|
60
|
+
*/
|
|
61
|
+
private binarySearchStart;
|
|
62
|
+
/**
|
|
63
|
+
* Binary search for range end (inclusive or exclusive)
|
|
64
|
+
*/
|
|
65
|
+
private binarySearchEnd;
|
|
66
|
+
/**
|
|
67
|
+
* Get IDs matching a range query
|
|
68
|
+
*/
|
|
69
|
+
private getIdsForRange;
|
|
51
70
|
/**
|
|
52
71
|
* Generate field index filename for filter discovery
|
|
53
72
|
*/
|
|
@@ -101,13 +120,17 @@ export declare class MetadataIndexManager {
|
|
|
101
120
|
*/
|
|
102
121
|
getFilterFields(): Promise<string[]>;
|
|
103
122
|
/**
|
|
104
|
-
* Convert
|
|
123
|
+
* Convert Brainy Field Operator filter to simple field-value criteria for indexing
|
|
105
124
|
*/
|
|
106
125
|
private convertFilterToCriteria;
|
|
107
126
|
/**
|
|
108
|
-
* Get IDs matching
|
|
127
|
+
* Get IDs matching Brainy Field Operator metadata filter using indexes where possible
|
|
109
128
|
*/
|
|
110
129
|
getIdsForFilter(filter: any): Promise<string[]>;
|
|
130
|
+
/**
|
|
131
|
+
* DEPRECATED - Old implementation for backward compatibility
|
|
132
|
+
*/
|
|
133
|
+
private getIdsForFilterOld;
|
|
111
134
|
/**
|
|
112
135
|
* Get IDs matching multiple criteria (intersection) - LEGACY METHOD
|
|
113
136
|
* @deprecated Use getIdsForFilter instead
|
|
@@ -130,6 +153,14 @@ export declare class MetadataIndexManager {
|
|
|
130
153
|
* Save field index to storage
|
|
131
154
|
*/
|
|
132
155
|
private saveFieldIndex;
|
|
156
|
+
/**
|
|
157
|
+
* Save sorted index to storage for range queries
|
|
158
|
+
*/
|
|
159
|
+
private saveSortedIndex;
|
|
160
|
+
/**
|
|
161
|
+
* Load sorted index from storage
|
|
162
|
+
*/
|
|
163
|
+
private loadSortedIndex;
|
|
133
164
|
/**
|
|
134
165
|
* Get index statistics
|
|
135
166
|
*/
|