rag-lite-ts 1.0.2 → 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.
Files changed (202) hide show
  1. package/README.md +606 -93
  2. package/dist/cli/indexer.js +192 -4
  3. package/dist/cli/search.js +50 -11
  4. package/dist/cli.js +183 -26
  5. package/dist/core/abstract-embedder.d.ts +125 -0
  6. package/dist/core/abstract-embedder.js +264 -0
  7. package/dist/core/actionable-error-messages.d.ts +60 -0
  8. package/dist/core/actionable-error-messages.js +397 -0
  9. package/dist/core/batch-processing-optimizer.d.ts +155 -0
  10. package/dist/core/batch-processing-optimizer.js +541 -0
  11. package/dist/core/chunker.d.ts +2 -0
  12. package/dist/core/cli-database-utils.d.ts +53 -0
  13. package/dist/core/cli-database-utils.js +239 -0
  14. package/dist/core/config.js +10 -3
  15. package/dist/core/content-errors.d.ts +111 -0
  16. package/dist/core/content-errors.js +362 -0
  17. package/dist/core/content-manager.d.ts +343 -0
  18. package/dist/core/content-manager.js +1504 -0
  19. package/dist/core/content-performance-optimizer.d.ts +150 -0
  20. package/dist/core/content-performance-optimizer.js +516 -0
  21. package/dist/core/content-resolver.d.ts +104 -0
  22. package/dist/core/content-resolver.js +285 -0
  23. package/dist/core/cross-modal-search.d.ts +164 -0
  24. package/dist/core/cross-modal-search.js +342 -0
  25. package/dist/core/database-connection-manager.d.ts +109 -0
  26. package/dist/core/database-connection-manager.js +304 -0
  27. package/dist/core/db.d.ts +141 -2
  28. package/dist/core/db.js +631 -89
  29. package/dist/core/embedder-factory.d.ts +176 -0
  30. package/dist/core/embedder-factory.js +338 -0
  31. package/dist/core/index.d.ts +3 -1
  32. package/dist/core/index.js +4 -1
  33. package/dist/core/ingestion.d.ts +85 -15
  34. package/dist/core/ingestion.js +510 -45
  35. package/dist/core/lazy-dependency-loader.d.ts +152 -0
  36. package/dist/core/lazy-dependency-loader.js +453 -0
  37. package/dist/core/mode-detection-service.d.ts +150 -0
  38. package/dist/core/mode-detection-service.js +565 -0
  39. package/dist/core/mode-model-validator.d.ts +92 -0
  40. package/dist/core/mode-model-validator.js +203 -0
  41. package/dist/core/model-registry.d.ts +120 -0
  42. package/dist/core/model-registry.js +415 -0
  43. package/dist/core/model-validator.d.ts +217 -0
  44. package/dist/core/model-validator.js +782 -0
  45. package/dist/core/polymorphic-search-factory.d.ts +154 -0
  46. package/dist/core/polymorphic-search-factory.js +344 -0
  47. package/dist/core/raglite-paths.d.ts +121 -0
  48. package/dist/core/raglite-paths.js +145 -0
  49. package/dist/core/reranking-config.d.ts +42 -0
  50. package/dist/core/reranking-config.js +156 -0
  51. package/dist/core/reranking-factory.d.ts +92 -0
  52. package/dist/core/reranking-factory.js +591 -0
  53. package/dist/core/reranking-strategies.d.ts +325 -0
  54. package/dist/core/reranking-strategies.js +720 -0
  55. package/dist/core/resource-cleanup.d.ts +163 -0
  56. package/dist/core/resource-cleanup.js +371 -0
  57. package/dist/core/resource-manager.d.ts +212 -0
  58. package/dist/core/resource-manager.js +564 -0
  59. package/dist/core/search.d.ts +28 -1
  60. package/dist/core/search.js +83 -5
  61. package/dist/core/streaming-operations.d.ts +145 -0
  62. package/dist/core/streaming-operations.js +409 -0
  63. package/dist/core/types.d.ts +3 -0
  64. package/dist/core/universal-embedder.d.ts +177 -0
  65. package/dist/core/universal-embedder.js +139 -0
  66. package/dist/core/validation-messages.d.ts +99 -0
  67. package/dist/core/validation-messages.js +334 -0
  68. package/dist/core/vector-index.js +7 -8
  69. package/dist/factories/index.d.ts +1 -1
  70. package/dist/factories/text-factory.d.ts +128 -34
  71. package/dist/factories/text-factory.js +346 -97
  72. package/dist/file-processor.d.ts +88 -2
  73. package/dist/file-processor.js +720 -17
  74. package/dist/index.d.ts +9 -0
  75. package/dist/index.js +11 -0
  76. package/dist/ingestion.d.ts +16 -0
  77. package/dist/ingestion.js +21 -0
  78. package/dist/mcp-server.d.ts +35 -3
  79. package/dist/mcp-server.js +1107 -31
  80. package/dist/multimodal/clip-embedder.d.ts +314 -0
  81. package/dist/multimodal/clip-embedder.js +945 -0
  82. package/dist/multimodal/index.d.ts +6 -0
  83. package/dist/multimodal/index.js +6 -0
  84. package/dist/run-error-recovery-tests.d.ts +7 -0
  85. package/dist/run-error-recovery-tests.js +101 -0
  86. package/dist/search.d.ts +26 -0
  87. package/dist/search.js +54 -1
  88. package/dist/test-utils.d.ts +8 -26
  89. package/dist/text/chunker.d.ts +1 -0
  90. package/dist/text/embedder.js +15 -8
  91. package/dist/text/index.d.ts +1 -0
  92. package/dist/text/index.js +1 -0
  93. package/dist/text/reranker.d.ts +1 -2
  94. package/dist/text/reranker.js +17 -47
  95. package/dist/text/sentence-transformer-embedder.d.ts +96 -0
  96. package/dist/text/sentence-transformer-embedder.js +340 -0
  97. package/dist/types.d.ts +39 -0
  98. package/dist/utils/vector-math.d.ts +31 -0
  99. package/dist/utils/vector-math.js +70 -0
  100. package/package.json +15 -3
  101. package/dist/api-errors.d.ts.map +0 -1
  102. package/dist/api-errors.js.map +0 -1
  103. package/dist/cli/indexer.d.ts.map +0 -1
  104. package/dist/cli/indexer.js.map +0 -1
  105. package/dist/cli/search.d.ts.map +0 -1
  106. package/dist/cli/search.js.map +0 -1
  107. package/dist/cli.d.ts.map +0 -1
  108. package/dist/cli.js.map +0 -1
  109. package/dist/config.d.ts.map +0 -1
  110. package/dist/config.js.map +0 -1
  111. package/dist/core/adapters.d.ts.map +0 -1
  112. package/dist/core/adapters.js.map +0 -1
  113. package/dist/core/chunker.d.ts.map +0 -1
  114. package/dist/core/chunker.js.map +0 -1
  115. package/dist/core/config.d.ts.map +0 -1
  116. package/dist/core/config.js.map +0 -1
  117. package/dist/core/db.d.ts.map +0 -1
  118. package/dist/core/db.js.map +0 -1
  119. package/dist/core/error-handler.d.ts.map +0 -1
  120. package/dist/core/error-handler.js.map +0 -1
  121. package/dist/core/index.d.ts.map +0 -1
  122. package/dist/core/index.js.map +0 -1
  123. package/dist/core/ingestion.d.ts.map +0 -1
  124. package/dist/core/ingestion.js.map +0 -1
  125. package/dist/core/interfaces.d.ts.map +0 -1
  126. package/dist/core/interfaces.js.map +0 -1
  127. package/dist/core/path-manager.d.ts.map +0 -1
  128. package/dist/core/path-manager.js.map +0 -1
  129. package/dist/core/search-example.d.ts +0 -25
  130. package/dist/core/search-example.d.ts.map +0 -1
  131. package/dist/core/search-example.js +0 -138
  132. package/dist/core/search-example.js.map +0 -1
  133. package/dist/core/search-pipeline-example.d.ts +0 -21
  134. package/dist/core/search-pipeline-example.d.ts.map +0 -1
  135. package/dist/core/search-pipeline-example.js +0 -188
  136. package/dist/core/search-pipeline-example.js.map +0 -1
  137. package/dist/core/search-pipeline.d.ts.map +0 -1
  138. package/dist/core/search-pipeline.js.map +0 -1
  139. package/dist/core/search.d.ts.map +0 -1
  140. package/dist/core/search.js.map +0 -1
  141. package/dist/core/types.d.ts.map +0 -1
  142. package/dist/core/types.js.map +0 -1
  143. package/dist/core/vector-index.d.ts.map +0 -1
  144. package/dist/core/vector-index.js.map +0 -1
  145. package/dist/dom-polyfills.d.ts.map +0 -1
  146. package/dist/dom-polyfills.js.map +0 -1
  147. package/dist/examples/clean-api-examples.d.ts +0 -44
  148. package/dist/examples/clean-api-examples.d.ts.map +0 -1
  149. package/dist/examples/clean-api-examples.js +0 -206
  150. package/dist/examples/clean-api-examples.js.map +0 -1
  151. package/dist/factories/index.d.ts.map +0 -1
  152. package/dist/factories/index.js.map +0 -1
  153. package/dist/factories/text-factory.d.ts.map +0 -1
  154. package/dist/factories/text-factory.js.map +0 -1
  155. package/dist/file-processor.d.ts.map +0 -1
  156. package/dist/file-processor.js.map +0 -1
  157. package/dist/index-manager.d.ts.map +0 -1
  158. package/dist/index-manager.js.map +0 -1
  159. package/dist/index.d.ts.map +0 -1
  160. package/dist/index.js.map +0 -1
  161. package/dist/indexer.d.ts.map +0 -1
  162. package/dist/indexer.js.map +0 -1
  163. package/dist/ingestion.d.ts.map +0 -1
  164. package/dist/ingestion.js.map +0 -1
  165. package/dist/mcp-server.d.ts.map +0 -1
  166. package/dist/mcp-server.js.map +0 -1
  167. package/dist/preprocess.d.ts.map +0 -1
  168. package/dist/preprocess.js.map +0 -1
  169. package/dist/preprocessors/index.d.ts.map +0 -1
  170. package/dist/preprocessors/index.js.map +0 -1
  171. package/dist/preprocessors/mdx.d.ts.map +0 -1
  172. package/dist/preprocessors/mdx.js.map +0 -1
  173. package/dist/preprocessors/mermaid.d.ts.map +0 -1
  174. package/dist/preprocessors/mermaid.js.map +0 -1
  175. package/dist/preprocessors/registry.d.ts.map +0 -1
  176. package/dist/preprocessors/registry.js.map +0 -1
  177. package/dist/search-standalone.d.ts.map +0 -1
  178. package/dist/search-standalone.js.map +0 -1
  179. package/dist/search.d.ts.map +0 -1
  180. package/dist/search.js.map +0 -1
  181. package/dist/test-utils.d.ts.map +0 -1
  182. package/dist/test-utils.js.map +0 -1
  183. package/dist/text/chunker.d.ts.map +0 -1
  184. package/dist/text/chunker.js.map +0 -1
  185. package/dist/text/embedder.d.ts.map +0 -1
  186. package/dist/text/embedder.js.map +0 -1
  187. package/dist/text/index.d.ts.map +0 -1
  188. package/dist/text/index.js.map +0 -1
  189. package/dist/text/preprocessors/index.d.ts.map +0 -1
  190. package/dist/text/preprocessors/index.js.map +0 -1
  191. package/dist/text/preprocessors/mdx.d.ts.map +0 -1
  192. package/dist/text/preprocessors/mdx.js.map +0 -1
  193. package/dist/text/preprocessors/mermaid.d.ts.map +0 -1
  194. package/dist/text/preprocessors/mermaid.js.map +0 -1
  195. package/dist/text/preprocessors/registry.d.ts.map +0 -1
  196. package/dist/text/preprocessors/registry.js.map +0 -1
  197. package/dist/text/reranker.d.ts.map +0 -1
  198. package/dist/text/reranker.js.map +0 -1
  199. package/dist/text/tokenizer.d.ts.map +0 -1
  200. package/dist/text/tokenizer.js.map +0 -1
  201. package/dist/types.d.ts.map +0 -1
  202. package/dist/types.js.map +0 -1
@@ -0,0 +1,397 @@
1
+ /**
2
+ * CORE MODULE — Actionable Error Messages
3
+ * Provides user-friendly, actionable error messages with specific guidance
4
+ * Replaces technical error messages with helpful troubleshooting steps
5
+ */
6
+ import { dirname, basename } from 'path';
7
+ /**
8
+ * Default configuration for error messages
9
+ */
10
+ const DEFAULT_CONFIG = {
11
+ includeExamples: true,
12
+ includeTroubleshooting: true,
13
+ operationContext: 'operation'
14
+ };
15
+ // =============================================================================
16
+ // FILE AND PATH ERROR MESSAGES
17
+ // =============================================================================
18
+ /**
19
+ * Create actionable error message for missing files
20
+ */
21
+ export function createMissingFileError(filePath, fileType, config = {}) {
22
+ const cfg = { ...DEFAULT_CONFIG, ...config };
23
+ const fileName = basename(filePath);
24
+ const dirName = dirname(filePath);
25
+ const messages = [];
26
+ // Main error message
27
+ switch (fileType) {
28
+ case 'index':
29
+ messages.push(`❌ Vector index file not found: ${filePath}`);
30
+ messages.push('');
31
+ messages.push('🔍 This usually means you need to run ingestion first to create the search index.');
32
+ break;
33
+ case 'database':
34
+ messages.push(`❌ Database file not found: ${filePath}`);
35
+ messages.push('');
36
+ messages.push('🔍 This usually means you need to run ingestion first to create the database.');
37
+ break;
38
+ case 'config':
39
+ messages.push(`❌ Configuration file not found: ${filePath}`);
40
+ messages.push('');
41
+ messages.push('🔍 The configuration file is missing or in the wrong location.');
42
+ break;
43
+ case 'content':
44
+ messages.push(`❌ Content file not found: ${filePath}`);
45
+ messages.push('');
46
+ messages.push('🔍 The content file may have been moved, deleted, or the path is incorrect.');
47
+ break;
48
+ }
49
+ if (cfg.includeTroubleshooting) {
50
+ messages.push('');
51
+ messages.push('🛠️ How to fix this:');
52
+ if (fileType === 'index' || fileType === 'database') {
53
+ messages.push(' 1. Run ingestion to create the required files:');
54
+ messages.push(' raglite ingest <your-documents-directory>');
55
+ messages.push('');
56
+ messages.push(' 2. Or create an ingestion pipeline programmatically:');
57
+ if (cfg.includeExamples) {
58
+ messages.push(' ```typescript');
59
+ messages.push(' import { TextIngestionFactory } from "rag-lite-ts";');
60
+ messages.push(' const pipeline = await TextIngestionFactory.create(');
61
+ messages.push(` "${filePath.endsWith('.bin') ? filePath.replace('.bin', '.sqlite') : filePath}",`);
62
+ messages.push(` "${filePath.endsWith('.sqlite') ? filePath.replace('.sqlite', '.bin') : filePath}"`);
63
+ messages.push(' );');
64
+ messages.push(' await pipeline.ingestDirectory("./your-documents");');
65
+ messages.push(' ```');
66
+ }
67
+ messages.push('');
68
+ messages.push(' 3. Verify the file paths are correct');
69
+ messages.push(` Expected directory: ${dirName}`);
70
+ messages.push(` Expected filename: ${fileName}`);
71
+ }
72
+ else {
73
+ messages.push(` 1. Check if the file exists at: ${filePath}`);
74
+ messages.push(' 2. Verify the file path is correct');
75
+ messages.push(' 3. Check file permissions');
76
+ }
77
+ }
78
+ return new Error(messages.join('\n'));
79
+ }
80
+ /**
81
+ * Create actionable error message for invalid paths
82
+ */
83
+ export function createInvalidPathError(paths, config = {}) {
84
+ const cfg = { ...DEFAULT_CONFIG, ...config };
85
+ const messages = [];
86
+ messages.push('❌ Invalid file paths provided');
87
+ messages.push('');
88
+ const missingPaths = paths.filter(p => !p.value || p.value.trim() === '');
89
+ if (missingPaths.length > 0) {
90
+ messages.push('🔍 Missing required paths:');
91
+ missingPaths.forEach(p => messages.push(` • ${p.name}: not provided`));
92
+ messages.push('');
93
+ }
94
+ if (cfg.includeTroubleshooting) {
95
+ messages.push('🛠️ How to fix this:');
96
+ messages.push(' 1. Provide all required file paths:');
97
+ if (cfg.includeExamples) {
98
+ messages.push(' ```typescript');
99
+ messages.push(' // ✅ Correct usage');
100
+ messages.push(' const search = await TextSearchFactory.create(');
101
+ messages.push(' "./my-index.bin", // Vector index path');
102
+ messages.push(' "./my-database.sqlite" // Database path');
103
+ messages.push(' );');
104
+ messages.push(' ```');
105
+ messages.push('');
106
+ messages.push(' ```typescript');
107
+ messages.push(' // ❌ Incorrect - missing paths');
108
+ messages.push(' const search = await TextSearchFactory.create("", "");');
109
+ messages.push(' ```');
110
+ }
111
+ }
112
+ return new Error(messages.join('\n'));
113
+ }
114
+ // =============================================================================
115
+ // MODEL AND CONFIGURATION ERROR MESSAGES
116
+ // =============================================================================
117
+ /**
118
+ * Create actionable error message for model loading failures
119
+ */
120
+ export function createModelLoadingError(modelName, originalError, config = {}) {
121
+ const cfg = { ...DEFAULT_CONFIG, ...config };
122
+ const messages = [];
123
+ messages.push(`❌ Failed to load embedding model: ${modelName}`);
124
+ messages.push('');
125
+ messages.push(`🔍 Original error: ${originalError}`);
126
+ messages.push('');
127
+ if (cfg.includeTroubleshooting) {
128
+ messages.push('🛠️ How to fix this:');
129
+ if (originalError.includes('network') || originalError.includes('download') || originalError.includes('fetch')) {
130
+ messages.push(' 📡 Network/Download Issues:');
131
+ messages.push(' 1. Check your internet connection');
132
+ messages.push(' 2. Try again in a few minutes (temporary server issues)');
133
+ messages.push(' 3. Check if you\'re behind a firewall or proxy');
134
+ messages.push('');
135
+ }
136
+ if (originalError.includes('memory') || originalError.includes('OOM')) {
137
+ messages.push(' 💾 Memory Issues:');
138
+ messages.push(' 1. Close other applications to free up memory');
139
+ messages.push(' 2. Try a smaller model:');
140
+ messages.push(' • sentence-transformers/all-MiniLM-L6-v2 (lightweight)');
141
+ messages.push(' • Xenova/clip-vit-base-patch32 (for multimodal)');
142
+ messages.push('');
143
+ }
144
+ messages.push(' 🔧 General Solutions:');
145
+ messages.push(' 1. Verify the model name is correct');
146
+ messages.push(' 2. Check available models:');
147
+ if (cfg.includeExamples) {
148
+ messages.push(' ```typescript');
149
+ messages.push(' import { listAvailableModels } from "rag-lite-ts";');
150
+ messages.push(' const models = listAvailableModels();');
151
+ messages.push(' console.log("Available models:", models);');
152
+ messages.push(' ```');
153
+ }
154
+ messages.push(' 3. Try a different model if the current one is problematic');
155
+ }
156
+ return new Error(messages.join('\n'));
157
+ }
158
+ /**
159
+ * Create actionable error message for dimension mismatches
160
+ */
161
+ export function createDimensionMismatchError(expected, actual, context, config = {}) {
162
+ const cfg = { ...DEFAULT_CONFIG, ...config };
163
+ const messages = [];
164
+ messages.push(`❌ Vector dimension mismatch in ${context}`);
165
+ messages.push('');
166
+ messages.push(`🔍 Expected: ${expected} dimensions`);
167
+ messages.push(`🔍 Actual: ${actual} dimensions`);
168
+ messages.push('');
169
+ messages.push('This usually means the model used to create the index is different from the current model.');
170
+ if (cfg.includeTroubleshooting) {
171
+ messages.push('');
172
+ messages.push('🛠️ How to fix this:');
173
+ messages.push(' 1. Rebuild the index with the current model:');
174
+ messages.push(' raglite ingest <directory> --force-rebuild');
175
+ messages.push('');
176
+ messages.push(' 2. Or use the same model that was used to create the index');
177
+ messages.push('');
178
+ messages.push(' 3. Check which model was used originally:');
179
+ if (cfg.includeExamples) {
180
+ messages.push(' ```typescript');
181
+ messages.push(' import { getSearchEngineInfo } from "rag-lite-ts";');
182
+ messages.push(' const info = await getSearchEngineInfo("./database.sqlite");');
183
+ messages.push(' console.log("Original model:", info.modelName);');
184
+ messages.push(' console.log("Original dimensions:", info.modelDimensions);');
185
+ messages.push(' ```');
186
+ }
187
+ }
188
+ return new Error(messages.join('\n'));
189
+ }
190
+ /**
191
+ * Create actionable error message for mode mismatches
192
+ */
193
+ export function createModeMismatchError(expectedMode, actualMode, config = {}) {
194
+ const cfg = { ...DEFAULT_CONFIG, ...config };
195
+ const messages = [];
196
+ messages.push(`❌ Mode mismatch detected`);
197
+ messages.push('');
198
+ messages.push(`🔍 Database is configured for: ${expectedMode} mode`);
199
+ messages.push(`🔍 You requested: ${actualMode} mode`);
200
+ messages.push('');
201
+ messages.push('Each database can only be used with one mode consistently.');
202
+ if (cfg.includeTroubleshooting) {
203
+ messages.push('');
204
+ messages.push('🛠️ How to fix this:');
205
+ messages.push(' 1. Use the existing mode (recommended):');
206
+ if (cfg.includeExamples) {
207
+ messages.push(' ```typescript');
208
+ messages.push(' // Let the system auto-detect the mode');
209
+ messages.push(' const search = await TextSearchFactory.create("./index.bin", "./db.sqlite");');
210
+ messages.push(' ```');
211
+ }
212
+ messages.push('');
213
+ messages.push(' 2. Or rebuild with the new mode:');
214
+ messages.push(` raglite ingest <directory> --mode ${actualMode} --force-rebuild`);
215
+ messages.push('');
216
+ messages.push(' 3. Or create a new database for the different mode:');
217
+ if (cfg.includeExamples) {
218
+ messages.push(' ```typescript');
219
+ messages.push(' const pipeline = await TextIngestionFactory.create(');
220
+ messages.push(' "./new-database.sqlite",');
221
+ messages.push(' "./new-index.bin",');
222
+ messages.push(` { mode: "${actualMode}" }`);
223
+ messages.push(' );');
224
+ messages.push(' ```');
225
+ }
226
+ }
227
+ return new Error(messages.join('\n'));
228
+ }
229
+ // =============================================================================
230
+ // CONTENT AND PROCESSING ERROR MESSAGES
231
+ // =============================================================================
232
+ /**
233
+ * Create actionable error message for empty or invalid content
234
+ */
235
+ export function createInvalidContentError(contentType, issue, config = {}) {
236
+ const cfg = { ...DEFAULT_CONFIG, ...config };
237
+ const messages = [];
238
+ switch (issue) {
239
+ case 'empty':
240
+ messages.push(`❌ Empty ${contentType} content provided`);
241
+ messages.push('');
242
+ messages.push('🔍 Content cannot be empty or contain only whitespace.');
243
+ break;
244
+ case 'invalid_format':
245
+ messages.push(`❌ Invalid ${contentType} format`);
246
+ messages.push('');
247
+ messages.push('🔍 The content format is not supported or is corrupted.');
248
+ break;
249
+ case 'too_large':
250
+ messages.push(`❌ ${contentType} content is too large`);
251
+ messages.push('');
252
+ messages.push('🔍 Content exceeds the maximum allowed size.');
253
+ break;
254
+ case 'unsupported':
255
+ messages.push(`❌ Unsupported ${contentType} content type`);
256
+ messages.push('');
257
+ messages.push('🔍 This content type is not supported in the current mode.');
258
+ break;
259
+ }
260
+ if (cfg.includeTroubleshooting) {
261
+ messages.push('');
262
+ messages.push('🛠️ How to fix this:');
263
+ switch (issue) {
264
+ case 'empty':
265
+ messages.push(' 1. Provide non-empty content');
266
+ messages.push(' 2. Check that your content source is working correctly');
267
+ messages.push(' 3. Verify file reading/processing is working');
268
+ break;
269
+ case 'invalid_format':
270
+ messages.push(' 1. Check the file format is supported');
271
+ messages.push(' 2. Verify the file is not corrupted');
272
+ messages.push(' 3. Try with a different file');
273
+ break;
274
+ case 'too_large':
275
+ messages.push(' 1. Split large content into smaller chunks');
276
+ messages.push(' 2. Increase the maximum content size limit');
277
+ messages.push(' 3. Process content in batches');
278
+ break;
279
+ case 'unsupported':
280
+ messages.push(' 1. Check if you\'re using the right mode:');
281
+ messages.push(' • Text mode: supports text content');
282
+ messages.push(' • Multimodal mode: supports text and images');
283
+ messages.push(' 2. Convert content to a supported format');
284
+ break;
285
+ }
286
+ }
287
+ return new Error(messages.join('\n'));
288
+ }
289
+ // =============================================================================
290
+ // INITIALIZATION AND DEPENDENCY ERROR MESSAGES
291
+ // =============================================================================
292
+ /**
293
+ * Create actionable error message for missing dependencies
294
+ */
295
+ export function createMissingDependencyError(dependencyName, dependencyType, config = {}) {
296
+ const cfg = { ...DEFAULT_CONFIG, ...config };
297
+ const messages = [];
298
+ messages.push(`❌ Missing required ${dependencyType}: ${dependencyName}`);
299
+ messages.push('');
300
+ messages.push(`🔍 The ${dependencyName} ${dependencyType} is required but was not provided or is invalid.`);
301
+ if (cfg.includeTroubleshooting) {
302
+ messages.push('');
303
+ messages.push('🛠️ How to fix this:');
304
+ messages.push(` 1. Ensure ${dependencyName} is properly initialized`);
305
+ messages.push(' 2. Check the initialization order of your components');
306
+ messages.push(' 3. Verify all required parameters are provided');
307
+ if (cfg.includeExamples) {
308
+ messages.push('');
309
+ messages.push(' Example of correct initialization:');
310
+ messages.push(' ```typescript');
311
+ messages.push(' // Make sure all dependencies are created first');
312
+ messages.push(' const embedder = await createEmbedder("model-name");');
313
+ messages.push(' const indexManager = new IndexManager(...);');
314
+ messages.push(' const db = await openDatabase(...);');
315
+ messages.push(' ');
316
+ messages.push(' // Then create the main component');
317
+ messages.push(' const searchEngine = new SearchEngine(embedder, indexManager, db);');
318
+ messages.push(' ```');
319
+ }
320
+ }
321
+ return new Error(messages.join('\n'));
322
+ }
323
+ /**
324
+ * Create actionable error message for factory creation failures
325
+ */
326
+ export function createFactoryCreationError(factoryName, originalError, config = {}) {
327
+ const cfg = { ...DEFAULT_CONFIG, ...config };
328
+ const messages = [];
329
+ messages.push(`❌ ${factoryName} creation failed`);
330
+ messages.push('');
331
+ messages.push(`🔍 Original error: ${originalError}`);
332
+ messages.push('');
333
+ if (cfg.includeTroubleshooting) {
334
+ messages.push('🛠️ Common solutions:');
335
+ messages.push(' 1. Check that all required files exist');
336
+ messages.push(' 2. Verify file paths are correct');
337
+ messages.push(' 3. Ensure you have proper file permissions');
338
+ messages.push(' 4. Check that the model name is valid');
339
+ messages.push(' 5. Verify network connectivity (for model downloads)');
340
+ messages.push('');
341
+ messages.push('🔍 For detailed troubleshooting:');
342
+ messages.push(' 1. Check the original error message above');
343
+ messages.push(' 2. Look for specific error patterns (file not found, network issues, etc.)');
344
+ messages.push(' 3. Try the operation with simpler parameters first');
345
+ }
346
+ return new Error(messages.join('\n'));
347
+ }
348
+ // =============================================================================
349
+ // UTILITY FUNCTIONS
350
+ // =============================================================================
351
+ /**
352
+ * Enhance an existing error with actionable information
353
+ */
354
+ export function enhanceError(originalError, context, suggestions = [], config = {}) {
355
+ const cfg = { ...DEFAULT_CONFIG, ...config };
356
+ const messages = [];
357
+ messages.push(`❌ Error in ${context}`);
358
+ messages.push('');
359
+ messages.push(`🔍 ${originalError.message}`);
360
+ if (suggestions.length > 0) {
361
+ messages.push('');
362
+ messages.push('🛠️ Suggestions:');
363
+ suggestions.forEach((suggestion, index) => {
364
+ messages.push(` ${index + 1}. ${suggestion}`);
365
+ });
366
+ }
367
+ const enhancedError = new Error(messages.join('\n'));
368
+ enhancedError.name = originalError.name;
369
+ enhancedError.stack = originalError.stack;
370
+ return enhancedError;
371
+ }
372
+ /**
373
+ * Create a user-friendly error message with context
374
+ */
375
+ export function createContextualError(message, context, suggestions = [], examples = [], config = {}) {
376
+ const cfg = { ...DEFAULT_CONFIG, ...config };
377
+ const messages = [];
378
+ messages.push(`❌ ${message}`);
379
+ messages.push('');
380
+ messages.push(`🔍 Context: ${context}`);
381
+ if (suggestions.length > 0) {
382
+ messages.push('');
383
+ messages.push('🛠️ How to fix this:');
384
+ suggestions.forEach((suggestion, index) => {
385
+ messages.push(` ${index + 1}. ${suggestion}`);
386
+ });
387
+ }
388
+ if (cfg.includeExamples && examples.length > 0) {
389
+ messages.push('');
390
+ messages.push('💡 Examples:');
391
+ examples.forEach(example => {
392
+ messages.push(` ${example}`);
393
+ });
394
+ }
395
+ return new Error(messages.join('\n'));
396
+ }
397
+ //# sourceMappingURL=actionable-error-messages.js.map
@@ -0,0 +1,155 @@
1
+ /**
2
+ * CORE MODULE — Batch Processing Optimizer
3
+ * Optimizes embedding generation for large multimodal content batches
4
+ * Implements efficient image processing pipelines with progress reporting
5
+ * Creates memory-efficient processing for large image collections
6
+ */
7
+ import type { EmbeddingResult } from '../types.js';
8
+ import type { EmbeddingBatchItem } from './universal-embedder.js';
9
+ /**
10
+ * Configuration for batch processing optimization
11
+ */
12
+ export interface BatchProcessingConfig {
13
+ textBatchSize: number;
14
+ imageBatchSize: number;
15
+ maxConcurrentBatches: number;
16
+ memoryThresholdMB: number;
17
+ enableMemoryMonitoring: boolean;
18
+ enableGarbageCollection: boolean;
19
+ enableProgressReporting: boolean;
20
+ progressReportInterval: number;
21
+ maxRetries: number;
22
+ retryDelayMs: number;
23
+ enableFallbackProcessing: boolean;
24
+ enableParallelProcessing: boolean;
25
+ enableResourcePooling: boolean;
26
+ preloadModels: boolean;
27
+ }
28
+ /**
29
+ * Default batch processing configuration optimized for multimodal content
30
+ */
31
+ export declare const DEFAULT_BATCH_CONFIG: BatchProcessingConfig;
32
+ /**
33
+ * Statistics for batch processing operations
34
+ */
35
+ export interface BatchProcessingStats {
36
+ totalItems: number;
37
+ processedItems: number;
38
+ failedItems: number;
39
+ skippedItems: number;
40
+ totalBatches: number;
41
+ completedBatches: number;
42
+ failedBatches: number;
43
+ processingTimeMs: number;
44
+ averageBatchTimeMs: number;
45
+ itemsPerSecond: number;
46
+ memoryUsageMB: number;
47
+ peakMemoryUsageMB: number;
48
+ retryCount: number;
49
+ fallbackCount: number;
50
+ }
51
+ /**
52
+ * Progress callback for batch processing
53
+ */
54
+ export type BatchProgressCallback = (stats: BatchProcessingStats) => void;
55
+ /**
56
+ * Result of batch processing operation
57
+ */
58
+ export interface BatchProcessingResult {
59
+ results: EmbeddingResult[];
60
+ stats: BatchProcessingStats;
61
+ errors: Array<{
62
+ item: EmbeddingBatchItem;
63
+ error: string;
64
+ batchIndex: number;
65
+ itemIndex: number;
66
+ }>;
67
+ }
68
+ /**
69
+ * Optimized batch processor for multimodal content
70
+ * Handles large collections of text and image content efficiently
71
+ */
72
+ export declare class BatchProcessingOptimizer {
73
+ private config;
74
+ private memoryMonitor;
75
+ private resourcePool;
76
+ private resourceManager;
77
+ constructor(config?: Partial<BatchProcessingConfig>);
78
+ /**
79
+ * Process a large batch of multimodal content with optimization
80
+ */
81
+ processBatch(items: EmbeddingBatchItem[], embedFunction: (item: EmbeddingBatchItem) => Promise<EmbeddingResult>, progressCallback?: BatchProgressCallback): Promise<BatchProcessingResult>;
82
+ /**
83
+ * Process text items in optimized batches
84
+ */
85
+ private processTextBatches;
86
+ /**
87
+ * Process a single text batch with error handling
88
+ */
89
+ private processTextBatch;
90
+ /**
91
+ * Process image items in optimized batches with memory management
92
+ */
93
+ private processImageBatches;
94
+ /**
95
+ * Process a single image batch with memory optimization
96
+ */
97
+ private processImageBatch;
98
+ /**
99
+ * Process batch with fallback to individual item processing
100
+ */
101
+ private processBatchWithFallback;
102
+ /**
103
+ * Preload required models based on content types
104
+ */
105
+ private preloadRequiredModels;
106
+ /**
107
+ * Preload image processing models
108
+ */
109
+ private preloadImageProcessingModels;
110
+ /**
111
+ * Perform memory management operations
112
+ */
113
+ private performMemoryManagement;
114
+ /**
115
+ * Cleanup resources after processing with resource manager integration
116
+ */
117
+ private cleanupResources;
118
+ /**
119
+ * Check if progress should be reported for this batch
120
+ */
121
+ private shouldReportProgress;
122
+ /**
123
+ * Delay execution for specified milliseconds
124
+ */
125
+ private delay;
126
+ /**
127
+ * Get current configuration
128
+ */
129
+ getConfig(): BatchProcessingConfig;
130
+ /**
131
+ * Update configuration
132
+ */
133
+ updateConfig(updates: Partial<BatchProcessingConfig>): void;
134
+ /**
135
+ * Get current memory statistics
136
+ */
137
+ getMemoryStats(): {
138
+ currentMB: number;
139
+ peakMB: number;
140
+ initialMB: number;
141
+ };
142
+ }
143
+ /**
144
+ * Create a batch processing optimizer with default configuration
145
+ */
146
+ export declare function createBatchProcessor(config?: Partial<BatchProcessingConfig>): BatchProcessingOptimizer;
147
+ /**
148
+ * Create a batch processing optimizer optimized for large image collections
149
+ */
150
+ export declare function createImageBatchProcessor(): BatchProcessingOptimizer;
151
+ /**
152
+ * Create a batch processing optimizer optimized for text processing
153
+ */
154
+ export declare function createTextBatchProcessor(): BatchProcessingOptimizer;
155
+ //# sourceMappingURL=batch-processing-optimizer.d.ts.map