rag-lite-ts 1.0.2 → 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/README.md +605 -93
- package/dist/cli/indexer.js +192 -4
- package/dist/cli/search.js +50 -11
- package/dist/cli.js +183 -26
- package/dist/core/abstract-embedder.d.ts +125 -0
- package/dist/core/abstract-embedder.js +264 -0
- package/dist/core/actionable-error-messages.d.ts +60 -0
- package/dist/core/actionable-error-messages.js +397 -0
- package/dist/core/batch-processing-optimizer.d.ts +155 -0
- package/dist/core/batch-processing-optimizer.js +541 -0
- package/dist/core/binary-index-format.d.ts +52 -0
- package/dist/core/binary-index-format.js +122 -0
- package/dist/core/chunker.d.ts +2 -0
- package/dist/core/cli-database-utils.d.ts +53 -0
- package/dist/core/cli-database-utils.js +239 -0
- package/dist/core/config.js +10 -3
- package/dist/core/content-errors.d.ts +111 -0
- package/dist/core/content-errors.js +362 -0
- package/dist/core/content-manager.d.ts +343 -0
- package/dist/core/content-manager.js +1504 -0
- package/dist/core/content-performance-optimizer.d.ts +150 -0
- package/dist/core/content-performance-optimizer.js +516 -0
- package/dist/core/content-resolver.d.ts +104 -0
- package/dist/core/content-resolver.js +285 -0
- package/dist/core/cross-modal-search.d.ts +164 -0
- package/dist/core/cross-modal-search.js +342 -0
- package/dist/core/database-connection-manager.d.ts +109 -0
- package/dist/core/database-connection-manager.js +304 -0
- package/dist/core/db.d.ts +141 -2
- package/dist/core/db.js +631 -89
- package/dist/core/embedder-factory.d.ts +176 -0
- package/dist/core/embedder-factory.js +338 -0
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.js +4 -1
- package/dist/core/ingestion.d.ts +85 -15
- package/dist/core/ingestion.js +510 -45
- package/dist/core/lazy-dependency-loader.d.ts +152 -0
- package/dist/core/lazy-dependency-loader.js +453 -0
- package/dist/core/mode-detection-service.d.ts +150 -0
- package/dist/core/mode-detection-service.js +565 -0
- package/dist/core/mode-model-validator.d.ts +92 -0
- package/dist/core/mode-model-validator.js +203 -0
- package/dist/core/model-registry.d.ts +120 -0
- package/dist/core/model-registry.js +415 -0
- package/dist/core/model-validator.d.ts +217 -0
- package/dist/core/model-validator.js +782 -0
- package/dist/core/polymorphic-search-factory.d.ts +154 -0
- package/dist/core/polymorphic-search-factory.js +344 -0
- package/dist/core/raglite-paths.d.ts +121 -0
- package/dist/core/raglite-paths.js +145 -0
- package/dist/core/reranking-config.d.ts +42 -0
- package/dist/core/reranking-config.js +156 -0
- package/dist/core/reranking-factory.d.ts +92 -0
- package/dist/core/reranking-factory.js +591 -0
- package/dist/core/reranking-strategies.d.ts +325 -0
- package/dist/core/reranking-strategies.js +720 -0
- package/dist/core/resource-cleanup.d.ts +163 -0
- package/dist/core/resource-cleanup.js +371 -0
- package/dist/core/resource-manager.d.ts +212 -0
- package/dist/core/resource-manager.js +564 -0
- package/dist/core/search.d.ts +28 -1
- package/dist/core/search.js +83 -5
- package/dist/core/streaming-operations.d.ts +145 -0
- package/dist/core/streaming-operations.js +409 -0
- package/dist/core/types.d.ts +3 -0
- package/dist/core/universal-embedder.d.ts +177 -0
- package/dist/core/universal-embedder.js +139 -0
- package/dist/core/validation-messages.d.ts +99 -0
- package/dist/core/validation-messages.js +334 -0
- package/dist/core/vector-index.d.ts +1 -1
- package/dist/core/vector-index.js +37 -39
- package/dist/factories/index.d.ts +3 -1
- package/dist/factories/index.js +2 -0
- package/dist/factories/polymorphic-factory.d.ts +50 -0
- package/dist/factories/polymorphic-factory.js +159 -0
- package/dist/factories/text-factory.d.ts +128 -34
- package/dist/factories/text-factory.js +346 -97
- package/dist/file-processor.d.ts +88 -2
- package/dist/file-processor.js +720 -17
- package/dist/index.d.ts +32 -0
- package/dist/index.js +29 -0
- package/dist/ingestion.d.ts +16 -0
- package/dist/ingestion.js +21 -0
- package/dist/mcp-server.d.ts +35 -3
- package/dist/mcp-server.js +1107 -31
- package/dist/multimodal/clip-embedder.d.ts +327 -0
- package/dist/multimodal/clip-embedder.js +992 -0
- package/dist/multimodal/index.d.ts +6 -0
- package/dist/multimodal/index.js +6 -0
- package/dist/run-error-recovery-tests.d.ts +7 -0
- package/dist/run-error-recovery-tests.js +101 -0
- package/dist/search.d.ts +60 -9
- package/dist/search.js +82 -11
- package/dist/test-utils.d.ts +8 -26
- package/dist/text/chunker.d.ts +1 -0
- package/dist/text/embedder.js +15 -8
- package/dist/text/index.d.ts +1 -0
- package/dist/text/index.js +1 -0
- package/dist/text/reranker.d.ts +1 -2
- package/dist/text/reranker.js +17 -47
- package/dist/text/sentence-transformer-embedder.d.ts +96 -0
- package/dist/text/sentence-transformer-embedder.js +340 -0
- package/dist/types.d.ts +39 -0
- package/dist/utils/vector-math.d.ts +31 -0
- package/dist/utils/vector-math.js +70 -0
- package/package.json +27 -6
- package/dist/api-errors.d.ts.map +0 -1
- package/dist/api-errors.js.map +0 -1
- package/dist/cli/indexer.d.ts.map +0 -1
- package/dist/cli/indexer.js.map +0 -1
- package/dist/cli/search.d.ts.map +0 -1
- package/dist/cli/search.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/core/adapters.d.ts.map +0 -1
- package/dist/core/adapters.js.map +0 -1
- package/dist/core/chunker.d.ts.map +0 -1
- package/dist/core/chunker.js.map +0 -1
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/config.js.map +0 -1
- package/dist/core/db.d.ts.map +0 -1
- package/dist/core/db.js.map +0 -1
- package/dist/core/error-handler.d.ts.map +0 -1
- package/dist/core/error-handler.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/ingestion.d.ts.map +0 -1
- package/dist/core/ingestion.js.map +0 -1
- package/dist/core/interfaces.d.ts.map +0 -1
- package/dist/core/interfaces.js.map +0 -1
- package/dist/core/path-manager.d.ts.map +0 -1
- package/dist/core/path-manager.js.map +0 -1
- package/dist/core/search-example.d.ts +0 -25
- package/dist/core/search-example.d.ts.map +0 -1
- package/dist/core/search-example.js +0 -138
- package/dist/core/search-example.js.map +0 -1
- package/dist/core/search-pipeline-example.d.ts +0 -21
- package/dist/core/search-pipeline-example.d.ts.map +0 -1
- package/dist/core/search-pipeline-example.js +0 -188
- package/dist/core/search-pipeline-example.js.map +0 -1
- package/dist/core/search-pipeline.d.ts.map +0 -1
- package/dist/core/search-pipeline.js.map +0 -1
- package/dist/core/search.d.ts.map +0 -1
- package/dist/core/search.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/core/vector-index.d.ts.map +0 -1
- package/dist/core/vector-index.js.map +0 -1
- package/dist/dom-polyfills.d.ts.map +0 -1
- package/dist/dom-polyfills.js.map +0 -1
- package/dist/examples/clean-api-examples.d.ts +0 -44
- package/dist/examples/clean-api-examples.d.ts.map +0 -1
- package/dist/examples/clean-api-examples.js +0 -206
- package/dist/examples/clean-api-examples.js.map +0 -1
- package/dist/factories/index.d.ts.map +0 -1
- package/dist/factories/index.js.map +0 -1
- package/dist/factories/text-factory.d.ts.map +0 -1
- package/dist/factories/text-factory.js.map +0 -1
- package/dist/file-processor.d.ts.map +0 -1
- package/dist/file-processor.js.map +0 -1
- package/dist/index-manager.d.ts.map +0 -1
- package/dist/index-manager.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/indexer.d.ts.map +0 -1
- package/dist/indexer.js.map +0 -1
- package/dist/ingestion.d.ts.map +0 -1
- package/dist/ingestion.js.map +0 -1
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js.map +0 -1
- package/dist/preprocess.d.ts.map +0 -1
- package/dist/preprocess.js.map +0 -1
- package/dist/preprocessors/index.d.ts.map +0 -1
- package/dist/preprocessors/index.js.map +0 -1
- package/dist/preprocessors/mdx.d.ts.map +0 -1
- package/dist/preprocessors/mdx.js.map +0 -1
- package/dist/preprocessors/mermaid.d.ts.map +0 -1
- package/dist/preprocessors/mermaid.js.map +0 -1
- package/dist/preprocessors/registry.d.ts.map +0 -1
- package/dist/preprocessors/registry.js.map +0 -1
- package/dist/search-standalone.d.ts.map +0 -1
- package/dist/search-standalone.js.map +0 -1
- package/dist/search.d.ts.map +0 -1
- package/dist/search.js.map +0 -1
- package/dist/test-utils.d.ts.map +0 -1
- package/dist/test-utils.js.map +0 -1
- package/dist/text/chunker.d.ts.map +0 -1
- package/dist/text/chunker.js.map +0 -1
- package/dist/text/embedder.d.ts.map +0 -1
- package/dist/text/embedder.js.map +0 -1
- package/dist/text/index.d.ts.map +0 -1
- package/dist/text/index.js.map +0 -1
- package/dist/text/preprocessors/index.d.ts.map +0 -1
- package/dist/text/preprocessors/index.js.map +0 -1
- package/dist/text/preprocessors/mdx.d.ts.map +0 -1
- package/dist/text/preprocessors/mdx.js.map +0 -1
- package/dist/text/preprocessors/mermaid.d.ts.map +0 -1
- package/dist/text/preprocessors/mermaid.js.map +0 -1
- package/dist/text/preprocessors/registry.d.ts.map +0 -1
- package/dist/text/preprocessors/registry.js.map +0 -1
- package/dist/text/reranker.d.ts.map +0 -1
- package/dist/text/reranker.js.map +0 -1
- package/dist/text/tokenizer.d.ts.map +0 -1
- package/dist/text/tokenizer.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORE MODULE — Model Registry for Chameleon Architecture
|
|
3
|
+
* Centralized registry of supported models with validation and compatibility checking
|
|
4
|
+
* Model-agnostic registry supporting both text and multimodal models
|
|
5
|
+
*/
|
|
6
|
+
// =============================================================================
|
|
7
|
+
// MODEL REGISTRY
|
|
8
|
+
// =============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Registry of supported models with their metadata and capabilities
|
|
11
|
+
* This registry defines all models compatible with the Chameleon architecture
|
|
12
|
+
*/
|
|
13
|
+
export const SUPPORTED_MODELS = {
|
|
14
|
+
// Text-only models (sentence-transformer type)
|
|
15
|
+
'sentence-transformers/all-MiniLM-L6-v2': {
|
|
16
|
+
name: 'sentence-transformers/all-MiniLM-L6-v2',
|
|
17
|
+
type: 'sentence-transformer',
|
|
18
|
+
dimensions: 384,
|
|
19
|
+
version: '1.0.0',
|
|
20
|
+
supportedContentTypes: ['text'],
|
|
21
|
+
capabilities: {
|
|
22
|
+
supportsText: true,
|
|
23
|
+
supportsImages: false,
|
|
24
|
+
supportsBatchProcessing: true,
|
|
25
|
+
supportsMetadata: true,
|
|
26
|
+
maxBatchSize: 32,
|
|
27
|
+
maxTextLength: 512
|
|
28
|
+
},
|
|
29
|
+
requirements: {
|
|
30
|
+
transformersJsVersion: '>=2.6.0',
|
|
31
|
+
minimumMemory: 256, // MB
|
|
32
|
+
requiredFeatures: ['tokenizers'],
|
|
33
|
+
platformSupport: ['node', 'browser']
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
'Xenova/all-mpnet-base-v2': {
|
|
37
|
+
name: 'Xenova/all-mpnet-base-v2',
|
|
38
|
+
type: 'sentence-transformer',
|
|
39
|
+
dimensions: 768,
|
|
40
|
+
version: '1.0.0',
|
|
41
|
+
supportedContentTypes: ['text'],
|
|
42
|
+
capabilities: {
|
|
43
|
+
supportsText: true,
|
|
44
|
+
supportsImages: false,
|
|
45
|
+
supportsBatchProcessing: true,
|
|
46
|
+
supportsMetadata: true,
|
|
47
|
+
maxBatchSize: 16,
|
|
48
|
+
maxTextLength: 512
|
|
49
|
+
},
|
|
50
|
+
requirements: {
|
|
51
|
+
transformersJsVersion: '>=2.6.0',
|
|
52
|
+
minimumMemory: 512, // MB
|
|
53
|
+
requiredFeatures: ['tokenizers'],
|
|
54
|
+
platformSupport: ['node', 'browser']
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
// Multimodal models (CLIP type)
|
|
58
|
+
// Fixed implementation: Reliable text and image embedding without fallback mechanisms
|
|
59
|
+
'Xenova/clip-vit-base-patch32': {
|
|
60
|
+
name: 'Xenova/clip-vit-base-patch32',
|
|
61
|
+
type: 'clip',
|
|
62
|
+
dimensions: 512,
|
|
63
|
+
version: '1.0.0',
|
|
64
|
+
supportedContentTypes: ['text', 'image'],
|
|
65
|
+
capabilities: {
|
|
66
|
+
supportsText: true, // Fixed: Reliable text embedding using CLIPTextModelWithProjection
|
|
67
|
+
supportsImages: true, // Fixed: Reliable image embedding using CLIPVisionModelWithProjection
|
|
68
|
+
supportsBatchProcessing: true,
|
|
69
|
+
supportsMetadata: true,
|
|
70
|
+
supportsMultimodal: true, // True cross-modal search capabilities
|
|
71
|
+
maxBatchSize: 8,
|
|
72
|
+
maxTextLength: 77, // CLIP's text sequence length limit
|
|
73
|
+
supportedImageFormats: ['jpg', 'jpeg', 'png', 'webp', 'gif']
|
|
74
|
+
},
|
|
75
|
+
requirements: {
|
|
76
|
+
transformersJsVersion: '>=2.8.0',
|
|
77
|
+
minimumMemory: 1024, // MB
|
|
78
|
+
requiredFeatures: ['vision', 'tokenizers'],
|
|
79
|
+
platformSupport: ['node', 'browser']
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
'Xenova/clip-vit-base-patch16': {
|
|
83
|
+
name: 'Xenova/clip-vit-base-patch16',
|
|
84
|
+
type: 'clip',
|
|
85
|
+
dimensions: 512,
|
|
86
|
+
version: '1.0.0',
|
|
87
|
+
supportedContentTypes: ['text', 'image'],
|
|
88
|
+
capabilities: {
|
|
89
|
+
supportsText: true, // Fixed: Reliable text embedding using CLIPTextModelWithProjection
|
|
90
|
+
supportsImages: true, // Fixed: Reliable image embedding using CLIPVisionModelWithProjection
|
|
91
|
+
supportsBatchProcessing: true,
|
|
92
|
+
supportsMetadata: true,
|
|
93
|
+
supportsMultimodal: true, // True cross-modal search capabilities
|
|
94
|
+
maxBatchSize: 4,
|
|
95
|
+
maxTextLength: 77, // CLIP's text sequence length limit
|
|
96
|
+
supportedImageFormats: ['jpg', 'jpeg', 'png', 'webp', 'gif']
|
|
97
|
+
},
|
|
98
|
+
requirements: {
|
|
99
|
+
transformersJsVersion: '>=2.8.0',
|
|
100
|
+
minimumMemory: 1536, // MB
|
|
101
|
+
requiredFeatures: ['vision', 'tokenizers'],
|
|
102
|
+
platformSupport: ['node', 'browser']
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
// =============================================================================
|
|
107
|
+
// MODEL REGISTRY OPERATIONS
|
|
108
|
+
// =============================================================================
|
|
109
|
+
/**
|
|
110
|
+
* Model registry class providing validation and model information services
|
|
111
|
+
* Enhanced with comprehensive validation and compatibility checking
|
|
112
|
+
*/
|
|
113
|
+
export class ModelRegistry {
|
|
114
|
+
/**
|
|
115
|
+
* Gets model information for a given model name
|
|
116
|
+
* @param modelName - Name of the model
|
|
117
|
+
* @returns Model information or null if not supported
|
|
118
|
+
*/
|
|
119
|
+
static getModelInfo(modelName) {
|
|
120
|
+
return SUPPORTED_MODELS[modelName] || null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Validates a model name and returns compatibility information
|
|
124
|
+
* @param modelName - Name of the model to validate
|
|
125
|
+
* @returns Model validation result with errors, warnings, and suggestions
|
|
126
|
+
*/
|
|
127
|
+
static validateModel(modelName) {
|
|
128
|
+
const modelInfo = this.getModelInfo(modelName);
|
|
129
|
+
if (!modelInfo) {
|
|
130
|
+
const suggestions = this.getSimilarModels(modelName);
|
|
131
|
+
return {
|
|
132
|
+
isValid: false,
|
|
133
|
+
errors: [`Model '${modelName}' is not supported`],
|
|
134
|
+
warnings: [],
|
|
135
|
+
suggestions: suggestions.length > 0
|
|
136
|
+
? [`Did you mean: ${suggestions.join(', ')}?`]
|
|
137
|
+
: [`Available models: ${this.getSupportedModels().join(', ')}`]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const warnings = [];
|
|
141
|
+
const suggestions = [];
|
|
142
|
+
// Enhanced validation with detailed checks
|
|
143
|
+
this.validateModelRequirements(modelInfo, warnings, suggestions);
|
|
144
|
+
this.validateModelCapabilities(modelInfo, warnings, suggestions);
|
|
145
|
+
return {
|
|
146
|
+
isValid: true,
|
|
147
|
+
errors: [],
|
|
148
|
+
warnings,
|
|
149
|
+
suggestions
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Validate model requirements and add warnings/suggestions
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
static validateModelRequirements(modelInfo, warnings, suggestions) {
|
|
157
|
+
// Memory requirements
|
|
158
|
+
if (modelInfo.requirements.minimumMemory) {
|
|
159
|
+
if (modelInfo.requirements.minimumMemory > 1024) {
|
|
160
|
+
warnings.push(`Model requires ${modelInfo.requirements.minimumMemory}MB memory`);
|
|
161
|
+
}
|
|
162
|
+
if (modelInfo.requirements.minimumMemory > 2048) {
|
|
163
|
+
suggestions.push('Consider using a smaller model variant for better performance');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Platform support
|
|
167
|
+
if (modelInfo.requirements.platformSupport) {
|
|
168
|
+
const supportedPlatforms = modelInfo.requirements.platformSupport;
|
|
169
|
+
if (!supportedPlatforms.includes('browser')) {
|
|
170
|
+
warnings.push('Model may not work in browser environments');
|
|
171
|
+
}
|
|
172
|
+
if (!supportedPlatforms.includes('node')) {
|
|
173
|
+
warnings.push('Model may not work in Node.js environments');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Feature requirements
|
|
177
|
+
if (modelInfo.requirements.requiredFeatures) {
|
|
178
|
+
const advancedFeatures = ['vision', 'zero-shot-image-classification', 'image-to-text'];
|
|
179
|
+
const hasAdvancedFeatures = modelInfo.requirements.requiredFeatures.some(feature => advancedFeatures.includes(feature));
|
|
180
|
+
if (hasAdvancedFeatures) {
|
|
181
|
+
warnings.push('Model requires advanced transformers.js features');
|
|
182
|
+
suggestions.push('Ensure you have the latest transformers.js version');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Validate model capabilities and add warnings/suggestions
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
static validateModelCapabilities(modelInfo, warnings, suggestions) {
|
|
191
|
+
// Batch size limitations
|
|
192
|
+
if (modelInfo.capabilities.maxBatchSize && modelInfo.capabilities.maxBatchSize < 8) {
|
|
193
|
+
warnings.push(`Model has limited batch size: ${modelInfo.capabilities.maxBatchSize}`);
|
|
194
|
+
suggestions.push('Use smaller batch sizes for optimal performance');
|
|
195
|
+
}
|
|
196
|
+
// Text length limitations
|
|
197
|
+
if (modelInfo.capabilities.maxTextLength && modelInfo.capabilities.maxTextLength < 512) {
|
|
198
|
+
warnings.push(`Model has limited text length: ${modelInfo.capabilities.maxTextLength} characters`);
|
|
199
|
+
suggestions.push('Consider chunking long texts before processing');
|
|
200
|
+
}
|
|
201
|
+
// Image format support
|
|
202
|
+
if (modelInfo.capabilities.supportsImages && modelInfo.capabilities.supportedImageFormats) {
|
|
203
|
+
const commonFormats = ['jpg', 'jpeg', 'png'];
|
|
204
|
+
const supportedCommon = commonFormats.filter(format => modelInfo.capabilities.supportedImageFormats.includes(format));
|
|
205
|
+
if (supportedCommon.length < commonFormats.length) {
|
|
206
|
+
const unsupported = commonFormats.filter(format => !supportedCommon.includes(format));
|
|
207
|
+
warnings.push(`Model may not support all common image formats. Unsupported: ${unsupported.join(', ')}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Performance suggestions for specific model types
|
|
211
|
+
if (modelInfo.type === 'clip') {
|
|
212
|
+
// Highlight fixed CLIP implementation capabilities
|
|
213
|
+
if (modelInfo.capabilities.supportsMultimodal) {
|
|
214
|
+
suggestions.push('CLIP models now support reliable cross-modal search between text and images');
|
|
215
|
+
}
|
|
216
|
+
if (modelInfo.dimensions > 512) {
|
|
217
|
+
suggestions.push('Consider using clip-vit-base-patch32 for better performance');
|
|
218
|
+
}
|
|
219
|
+
if (modelInfo.name.includes('patch16')) {
|
|
220
|
+
suggestions.push('patch16 models are more accurate but slower than patch32');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (modelInfo.type === 'sentence-transformer') {
|
|
224
|
+
if (modelInfo.dimensions > 768) {
|
|
225
|
+
suggestions.push('Consider using all-MiniLM-L6-v2 for faster processing');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Lists all supported models, optionally filtered by type
|
|
231
|
+
* @param modelType - Optional model type filter
|
|
232
|
+
* @returns Array of supported model names
|
|
233
|
+
*/
|
|
234
|
+
static getSupportedModels(modelType) {
|
|
235
|
+
const allModels = Object.keys(SUPPORTED_MODELS);
|
|
236
|
+
if (!modelType) {
|
|
237
|
+
return allModels;
|
|
238
|
+
}
|
|
239
|
+
return allModels.filter(modelName => SUPPORTED_MODELS[modelName].type === modelType);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Gets models that support a specific content type
|
|
243
|
+
* @param contentType - Content type to filter by
|
|
244
|
+
* @returns Array of model names that support the content type
|
|
245
|
+
*/
|
|
246
|
+
static getModelsByContentType(contentType) {
|
|
247
|
+
return Object.keys(SUPPORTED_MODELS).filter(modelName => SUPPORTED_MODELS[modelName].supportedContentTypes.includes(contentType));
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Gets the default model for a given model type
|
|
251
|
+
* @param modelType - Model type to get default for
|
|
252
|
+
* @returns Default model name or null if no default available
|
|
253
|
+
*/
|
|
254
|
+
static getDefaultModel(modelType) {
|
|
255
|
+
const models = this.getSupportedModels(modelType);
|
|
256
|
+
switch (modelType) {
|
|
257
|
+
case 'sentence-transformer':
|
|
258
|
+
return 'sentence-transformers/all-MiniLM-L6-v2';
|
|
259
|
+
case 'clip':
|
|
260
|
+
return 'Xenova/clip-vit-base-patch32';
|
|
261
|
+
default:
|
|
262
|
+
return models.length > 0 ? models[0] : null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Checks if a model supports a specific content type
|
|
267
|
+
* @param modelName - Name of the model
|
|
268
|
+
* @param contentType - Content type to check
|
|
269
|
+
* @returns True if the model supports the content type
|
|
270
|
+
*/
|
|
271
|
+
static supportsContentType(modelName, contentType) {
|
|
272
|
+
const modelInfo = this.getModelInfo(modelName);
|
|
273
|
+
return modelInfo ? modelInfo.supportedContentTypes.includes(contentType) : false;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Gets models similar to the given model name (for suggestions)
|
|
277
|
+
* @param modelName - Model name to find similar models for
|
|
278
|
+
* @returns Array of similar model names
|
|
279
|
+
*/
|
|
280
|
+
static getSimilarModels(modelName) {
|
|
281
|
+
const allModels = Object.keys(SUPPORTED_MODELS);
|
|
282
|
+
const lowerModelName = modelName.toLowerCase();
|
|
283
|
+
// Simple similarity check based on common substrings
|
|
284
|
+
return allModels.filter(supportedModel => {
|
|
285
|
+
const lowerSupported = supportedModel.toLowerCase();
|
|
286
|
+
// Check for common keywords
|
|
287
|
+
const keywords = ['clip', 'mpnet', 'minilm', 'sentence', 'transformer'];
|
|
288
|
+
const modelKeywords = keywords.filter(keyword => lowerModelName.includes(keyword));
|
|
289
|
+
const supportedKeywords = keywords.filter(keyword => lowerSupported.includes(keyword));
|
|
290
|
+
// Return models that share at least one keyword
|
|
291
|
+
return modelKeywords.some(keyword => supportedKeywords.includes(keyword));
|
|
292
|
+
}).slice(0, 3); // Limit to 3 suggestions
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Validates model compatibility with system requirements
|
|
296
|
+
* @param modelName - Name of the model to validate
|
|
297
|
+
* @param systemCapabilities - System capabilities to check against
|
|
298
|
+
* @returns Validation result with compatibility information
|
|
299
|
+
*/
|
|
300
|
+
static validateSystemCompatibility(modelName, systemCapabilities) {
|
|
301
|
+
const modelInfo = this.getModelInfo(modelName);
|
|
302
|
+
if (!modelInfo) {
|
|
303
|
+
return {
|
|
304
|
+
isValid: false,
|
|
305
|
+
errors: [`Model '${modelName}' is not supported`],
|
|
306
|
+
warnings: [],
|
|
307
|
+
suggestions: []
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
const errors = [];
|
|
311
|
+
const warnings = [];
|
|
312
|
+
const suggestions = [];
|
|
313
|
+
// Check memory requirements
|
|
314
|
+
if (systemCapabilities.availableMemory && modelInfo.requirements.minimumMemory) {
|
|
315
|
+
if (systemCapabilities.availableMemory < modelInfo.requirements.minimumMemory) {
|
|
316
|
+
errors.push(`Insufficient memory: ${systemCapabilities.availableMemory}MB available, ` +
|
|
317
|
+
`${modelInfo.requirements.minimumMemory}MB required`);
|
|
318
|
+
// Suggest lighter models
|
|
319
|
+
const lighterModels = this.getSupportedModels(modelInfo.type).filter(name => {
|
|
320
|
+
const info = this.getModelInfo(name);
|
|
321
|
+
return info &&
|
|
322
|
+
info.requirements.minimumMemory &&
|
|
323
|
+
info.requirements.minimumMemory <= systemCapabilities.availableMemory;
|
|
324
|
+
});
|
|
325
|
+
if (lighterModels.length > 0) {
|
|
326
|
+
suggestions.push(`Consider lighter models: ${lighterModels.join(', ')}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// Check platform compatibility
|
|
331
|
+
if (systemCapabilities.platform && modelInfo.requirements.platformSupport) {
|
|
332
|
+
if (!modelInfo.requirements.platformSupport.includes(systemCapabilities.platform)) {
|
|
333
|
+
errors.push(`Platform '${systemCapabilities.platform}' not supported. ` +
|
|
334
|
+
`Supported platforms: ${modelInfo.requirements.platformSupport.join(', ')}`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
isValid: errors.length === 0,
|
|
339
|
+
errors,
|
|
340
|
+
warnings,
|
|
341
|
+
suggestions
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// =============================================================================
|
|
346
|
+
// UTILITY FUNCTIONS
|
|
347
|
+
// =============================================================================
|
|
348
|
+
/**
|
|
349
|
+
* Gets the model type for a given model name
|
|
350
|
+
* @param modelName - Name of the model
|
|
351
|
+
* @returns Model type or null if model not supported
|
|
352
|
+
*/
|
|
353
|
+
export function getModelType(modelName) {
|
|
354
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
355
|
+
return modelInfo ? modelInfo.type : null;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Gets the dimensions for a given model name
|
|
359
|
+
* @param modelName - Name of the model
|
|
360
|
+
* @returns Number of dimensions or null if model not supported
|
|
361
|
+
*/
|
|
362
|
+
export function getModelDimensions(modelName) {
|
|
363
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
364
|
+
return modelInfo ? modelInfo.dimensions : null;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Checks if a model is a text-only model
|
|
368
|
+
* @param modelName - Name of the model
|
|
369
|
+
* @returns True if the model only supports text
|
|
370
|
+
*/
|
|
371
|
+
export function isTextOnlyModel(modelName) {
|
|
372
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
373
|
+
return modelInfo ?
|
|
374
|
+
modelInfo.supportedContentTypes.length === 1 &&
|
|
375
|
+
modelInfo.supportedContentTypes[0] === 'text' :
|
|
376
|
+
false;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Checks if a model is a multimodal model
|
|
380
|
+
* @param modelName - Name of the model
|
|
381
|
+
* @returns True if the model supports multiple content types
|
|
382
|
+
*/
|
|
383
|
+
export function isMultimodalModel(modelName) {
|
|
384
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
385
|
+
return modelInfo ? modelInfo.supportedContentTypes.length > 1 : false;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Gets recommended batch size for a model
|
|
389
|
+
* @param modelName - Name of the model
|
|
390
|
+
* @returns Recommended batch size or default value
|
|
391
|
+
*/
|
|
392
|
+
export function getRecommendedBatchSize(modelName) {
|
|
393
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
394
|
+
return modelInfo?.capabilities.maxBatchSize || 8;
|
|
395
|
+
}
|
|
396
|
+
// =============================================================================
|
|
397
|
+
// CONSTANTS
|
|
398
|
+
// =============================================================================
|
|
399
|
+
/**
|
|
400
|
+
* Default model names for different types
|
|
401
|
+
*/
|
|
402
|
+
export const DEFAULT_MODELS = {
|
|
403
|
+
'sentence-transformer': 'sentence-transformers/all-MiniLM-L6-v2',
|
|
404
|
+
'clip': 'Xenova/clip-vit-base-patch32'
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Model type mappings for backward compatibility
|
|
408
|
+
*/
|
|
409
|
+
export const MODEL_TYPE_ALIASES = {
|
|
410
|
+
'text': 'sentence-transformer',
|
|
411
|
+
'multimodal': 'clip',
|
|
412
|
+
'sentence': 'sentence-transformer',
|
|
413
|
+
'embedding': 'sentence-transformer'
|
|
414
|
+
};
|
|
415
|
+
//# sourceMappingURL=model-registry.js.map
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORE MODULE — Model Validation and Compatibility System
|
|
3
|
+
* Comprehensive validation system for transformers.js compatibility and model support
|
|
4
|
+
* Provides detailed error messages and suggestions for unsupported models
|
|
5
|
+
*/
|
|
6
|
+
import type { ModelValidationResult, ModelInfo, ModelType, TransformersCompatibilityError, ModelValidationError } from './universal-embedder.js';
|
|
7
|
+
/**
|
|
8
|
+
* Transformers.js version information and compatibility matrix
|
|
9
|
+
*/
|
|
10
|
+
export interface TransformersJsInfo {
|
|
11
|
+
version: string;
|
|
12
|
+
supportedFeatures: readonly string[];
|
|
13
|
+
supportedModelTypes: readonly ModelType[];
|
|
14
|
+
knownIssues: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* System capabilities for compatibility checking
|
|
18
|
+
*/
|
|
19
|
+
export interface SystemCapabilities {
|
|
20
|
+
transformersJsVersion?: string;
|
|
21
|
+
availableMemory?: number;
|
|
22
|
+
platform?: 'node' | 'browser' | 'worker';
|
|
23
|
+
gpuSupport?: boolean;
|
|
24
|
+
supportedFeatures?: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Detailed validation result with comprehensive information
|
|
28
|
+
*/
|
|
29
|
+
export interface DetailedValidationResult extends ModelValidationResult {
|
|
30
|
+
modelInfo?: ModelInfo;
|
|
31
|
+
systemCompatibility?: {
|
|
32
|
+
transformersJs: boolean;
|
|
33
|
+
memory: boolean;
|
|
34
|
+
platform: boolean;
|
|
35
|
+
features: boolean;
|
|
36
|
+
};
|
|
37
|
+
recommendations?: {
|
|
38
|
+
alternativeModels: string[];
|
|
39
|
+
systemUpgrades: string[];
|
|
40
|
+
configurationChanges: string[];
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Compatibility matrix for different transformers.js versions
|
|
45
|
+
*/
|
|
46
|
+
export declare const TRANSFORMERS_COMPATIBILITY_MATRIX: Record<string, TransformersJsInfo>;
|
|
47
|
+
/**
|
|
48
|
+
* Comprehensive model validator with transformers.js compatibility checking
|
|
49
|
+
*/
|
|
50
|
+
export declare class ModelValidator {
|
|
51
|
+
private static currentTransformersVersion;
|
|
52
|
+
private static systemCapabilities;
|
|
53
|
+
/**
|
|
54
|
+
* Set the current transformers.js version for compatibility checking
|
|
55
|
+
* @param version - Current transformers.js version
|
|
56
|
+
*/
|
|
57
|
+
static setTransformersVersion(version: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Set system capabilities for compatibility checking
|
|
60
|
+
* @param capabilities - System capabilities
|
|
61
|
+
*/
|
|
62
|
+
static setSystemCapabilities(capabilities: SystemCapabilities): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get the current transformers.js version
|
|
65
|
+
* @returns Current version or null if not set
|
|
66
|
+
*/
|
|
67
|
+
static getTransformersVersion(): string | null;
|
|
68
|
+
/**
|
|
69
|
+
* Detect transformers.js version from the environment
|
|
70
|
+
* @returns Promise resolving to the detected version or null
|
|
71
|
+
*/
|
|
72
|
+
static detectTransformersVersion(): Promise<string | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Validate a model with comprehensive compatibility checking
|
|
75
|
+
* @param modelName - Name of the model to validate
|
|
76
|
+
* @param systemCapabilities - Optional system capabilities override
|
|
77
|
+
* @returns Detailed validation result
|
|
78
|
+
*/
|
|
79
|
+
static validateModelDetailed(modelName: string, systemCapabilities?: SystemCapabilities): Promise<DetailedValidationResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Validate transformers.js version compatibility for a model
|
|
82
|
+
* @param modelInfo - Model information
|
|
83
|
+
* @param transformersVersion - Transformers.js version to check
|
|
84
|
+
* @returns Validation result
|
|
85
|
+
*/
|
|
86
|
+
static validateTransformersCompatibility(modelInfo: ModelInfo, transformersVersion?: string): ModelValidationResult;
|
|
87
|
+
/**
|
|
88
|
+
* Get all models compatible with a specific transformers.js version
|
|
89
|
+
* @param transformersVersion - Transformers.js version
|
|
90
|
+
* @returns Array of compatible model names
|
|
91
|
+
*/
|
|
92
|
+
static getCompatibleModels(transformersVersion?: string): string[];
|
|
93
|
+
/**
|
|
94
|
+
* Get recommended models for a specific use case
|
|
95
|
+
* @param contentTypes - Required content types
|
|
96
|
+
* @param maxMemory - Maximum available memory in MB
|
|
97
|
+
* @param transformersVersion - Transformers.js version
|
|
98
|
+
* @returns Array of recommended model names
|
|
99
|
+
*/
|
|
100
|
+
static getRecommendedModels(contentTypes: string[], maxMemory?: number, transformersVersion?: string): string[];
|
|
101
|
+
/**
|
|
102
|
+
* Check system compatibility for a model
|
|
103
|
+
*/
|
|
104
|
+
private static checkSystemCompatibility;
|
|
105
|
+
/**
|
|
106
|
+
* Generate recommendations based on validation results
|
|
107
|
+
*/
|
|
108
|
+
private static generateRecommendations;
|
|
109
|
+
/**
|
|
110
|
+
* Check version compatibility using semantic versioning
|
|
111
|
+
*/
|
|
112
|
+
private static checkVersionCompatibility;
|
|
113
|
+
/**
|
|
114
|
+
* Get compatibility information for a transformers.js version
|
|
115
|
+
*/
|
|
116
|
+
private static getCompatibilityInfo;
|
|
117
|
+
/**
|
|
118
|
+
* Get similar models for suggestions
|
|
119
|
+
*/
|
|
120
|
+
static getSimilarModels(modelName: string): string[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Enhanced ModelValidationError class with comprehensive error information
|
|
124
|
+
*/
|
|
125
|
+
export declare class EnhancedModelValidationError extends Error implements ModelValidationError {
|
|
126
|
+
readonly modelName: string;
|
|
127
|
+
readonly availableModels: readonly string[];
|
|
128
|
+
readonly errorType: 'not_found' | 'incompatible' | 'unsupported_features';
|
|
129
|
+
readonly suggestions: readonly string[];
|
|
130
|
+
readonly troubleshootingSteps: readonly string[];
|
|
131
|
+
readonly name = "ModelValidationError";
|
|
132
|
+
constructor(modelName: string, availableModels: readonly string[], message: string, errorType?: 'not_found' | 'incompatible' | 'unsupported_features', suggestions?: readonly string[], troubleshootingSteps?: readonly string[]);
|
|
133
|
+
/**
|
|
134
|
+
* Get formatted error message with suggestions and troubleshooting steps
|
|
135
|
+
*/
|
|
136
|
+
getFormattedMessage(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Log the error with proper formatting
|
|
139
|
+
*/
|
|
140
|
+
logError(): void;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Enhanced TransformersCompatibilityError class with version information
|
|
144
|
+
*/
|
|
145
|
+
export declare class EnhancedTransformersCompatibilityError extends Error implements TransformersCompatibilityError {
|
|
146
|
+
readonly modelName: string;
|
|
147
|
+
readonly requiredVersion: string;
|
|
148
|
+
readonly currentVersion: string;
|
|
149
|
+
readonly upgradeInstructions: readonly string[];
|
|
150
|
+
readonly alternativeModels: readonly string[];
|
|
151
|
+
readonly name = "TransformersCompatibilityError";
|
|
152
|
+
constructor(modelName: string, requiredVersion: string, currentVersion: string, message: string, upgradeInstructions?: readonly string[], alternativeModels?: readonly string[]);
|
|
153
|
+
/**
|
|
154
|
+
* Get formatted error message with upgrade instructions
|
|
155
|
+
*/
|
|
156
|
+
getFormattedMessage(): string;
|
|
157
|
+
/**
|
|
158
|
+
* Log the error with proper formatting
|
|
159
|
+
*/
|
|
160
|
+
logError(): void;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a comprehensive model validation error with helpful information
|
|
164
|
+
* @param modelName - Name of the invalid model
|
|
165
|
+
* @param reason - Reason for validation failure
|
|
166
|
+
* @param errorType - Type of validation error
|
|
167
|
+
* @returns Enhanced ModelValidationError instance
|
|
168
|
+
*/
|
|
169
|
+
export declare function createModelValidationError(modelName: string, reason: string, errorType?: 'not_found' | 'incompatible' | 'unsupported_features'): EnhancedModelValidationError;
|
|
170
|
+
/**
|
|
171
|
+
* Create a comprehensive transformers compatibility error with version information
|
|
172
|
+
* @param modelName - Name of the model
|
|
173
|
+
* @param requiredVersion - Required transformers.js version
|
|
174
|
+
* @param currentVersion - Current transformers.js version
|
|
175
|
+
* @returns Enhanced TransformersCompatibilityError instance
|
|
176
|
+
*/
|
|
177
|
+
export declare function createTransformersCompatibilityError(modelName: string, requiredVersion: string, currentVersion: string): EnhancedTransformersCompatibilityError;
|
|
178
|
+
/**
|
|
179
|
+
* Initialize the model validator with system detection
|
|
180
|
+
* @returns Promise resolving to initialization success
|
|
181
|
+
*/
|
|
182
|
+
export declare function initializeModelValidator(): Promise<boolean>;
|
|
183
|
+
/**
|
|
184
|
+
* Comprehensive model validation with detailed error reporting
|
|
185
|
+
* @param modelName - Name of the model to validate
|
|
186
|
+
* @param options - Validation options
|
|
187
|
+
* @returns Promise resolving to validation result or throws enhanced error
|
|
188
|
+
*/
|
|
189
|
+
export declare function validateModelWithDetailedErrors(modelName: string, options?: {
|
|
190
|
+
checkTransformersVersion?: boolean;
|
|
191
|
+
systemCapabilities?: SystemCapabilities;
|
|
192
|
+
throwOnError?: boolean;
|
|
193
|
+
}): Promise<DetailedValidationResult>;
|
|
194
|
+
/**
|
|
195
|
+
* Validate model and provide user-friendly error messages
|
|
196
|
+
* @param modelName - Name of the model to validate
|
|
197
|
+
* @param options - Validation options
|
|
198
|
+
* @returns Promise resolving to true if valid, throws user-friendly error if not
|
|
199
|
+
*/
|
|
200
|
+
export declare function validateModelOrThrow(modelName: string, options?: {
|
|
201
|
+
checkTransformersVersion?: boolean;
|
|
202
|
+
systemCapabilities?: SystemCapabilities;
|
|
203
|
+
logErrors?: boolean;
|
|
204
|
+
}): Promise<boolean>;
|
|
205
|
+
/**
|
|
206
|
+
* Minimum supported transformers.js version
|
|
207
|
+
*/
|
|
208
|
+
export declare const MIN_TRANSFORMERS_VERSION = "2.6.0";
|
|
209
|
+
/**
|
|
210
|
+
* Recommended transformers.js version
|
|
211
|
+
*/
|
|
212
|
+
export declare const RECOMMENDED_TRANSFORMERS_VERSION = "2.8.0";
|
|
213
|
+
/**
|
|
214
|
+
* Default system capabilities for validation
|
|
215
|
+
*/
|
|
216
|
+
export declare const DEFAULT_SYSTEM_CAPABILITIES: SystemCapabilities;
|
|
217
|
+
//# sourceMappingURL=model-validator.d.ts.map
|