rag-lite-ts 1.0.1 → 1.0.2

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 (182) hide show
  1. package/README.md +94 -65
  2. package/dist/cli/indexer.d.ts.map +1 -1
  3. package/dist/cli/indexer.js +78 -50
  4. package/dist/cli/indexer.js.map +1 -1
  5. package/dist/cli/search.d.ts.map +1 -1
  6. package/dist/cli/search.js +13 -30
  7. package/dist/cli/search.js.map +1 -1
  8. package/dist/cli.js +2 -2
  9. package/dist/cli.js.map +1 -1
  10. package/dist/config.d.ts +34 -73
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +50 -255
  13. package/dist/config.js.map +1 -1
  14. package/dist/core/adapters.d.ts +93 -0
  15. package/dist/core/adapters.d.ts.map +1 -0
  16. package/dist/core/adapters.js +139 -0
  17. package/dist/core/adapters.js.map +1 -0
  18. package/dist/core/chunker.d.ts +117 -0
  19. package/dist/core/chunker.d.ts.map +1 -0
  20. package/dist/core/chunker.js +73 -0
  21. package/dist/core/chunker.js.map +1 -0
  22. package/dist/core/config.d.ts +102 -0
  23. package/dist/core/config.d.ts.map +1 -0
  24. package/dist/core/config.js +240 -0
  25. package/dist/core/config.js.map +1 -0
  26. package/dist/{db.d.ts → core/db.d.ts} +25 -9
  27. package/dist/core/db.d.ts.map +1 -0
  28. package/dist/{db.js → core/db.js} +86 -16
  29. package/dist/core/db.js.map +1 -0
  30. package/dist/{error-handler.d.ts → core/error-handler.d.ts} +23 -2
  31. package/dist/core/error-handler.d.ts.map +1 -0
  32. package/dist/{error-handler.js → core/error-handler.js} +51 -8
  33. package/dist/core/error-handler.js.map +1 -0
  34. package/dist/core/index.d.ts +57 -0
  35. package/dist/core/index.d.ts.map +1 -0
  36. package/dist/core/index.js +66 -0
  37. package/dist/core/index.js.map +1 -0
  38. package/dist/core/ingestion.d.ts +143 -0
  39. package/dist/core/ingestion.d.ts.map +1 -0
  40. package/dist/core/ingestion.js +347 -0
  41. package/dist/core/ingestion.js.map +1 -0
  42. package/dist/core/interfaces.d.ts +408 -0
  43. package/dist/core/interfaces.d.ts.map +1 -0
  44. package/dist/core/interfaces.js +106 -0
  45. package/dist/core/interfaces.js.map +1 -0
  46. package/dist/{path-manager.d.ts → core/path-manager.d.ts} +5 -0
  47. package/dist/core/path-manager.d.ts.map +1 -0
  48. package/dist/{path-manager.js → core/path-manager.js} +5 -0
  49. package/dist/core/path-manager.js.map +1 -0
  50. package/dist/core/search-example.d.ts +25 -0
  51. package/dist/core/search-example.d.ts.map +1 -0
  52. package/dist/core/search-example.js +138 -0
  53. package/dist/core/search-example.js.map +1 -0
  54. package/dist/core/search-pipeline-example.d.ts +21 -0
  55. package/dist/core/search-pipeline-example.d.ts.map +1 -0
  56. package/dist/core/search-pipeline-example.js +188 -0
  57. package/dist/core/search-pipeline-example.js.map +1 -0
  58. package/dist/core/search-pipeline.d.ts +111 -0
  59. package/dist/core/search-pipeline.d.ts.map +1 -0
  60. package/dist/core/search-pipeline.js +287 -0
  61. package/dist/core/search-pipeline.js.map +1 -0
  62. package/dist/core/search.d.ts +104 -0
  63. package/dist/core/search.d.ts.map +1 -0
  64. package/dist/core/search.js +218 -0
  65. package/dist/core/search.js.map +1 -0
  66. package/dist/core/types.d.ts +63 -0
  67. package/dist/core/types.d.ts.map +1 -0
  68. package/dist/core/types.js +6 -0
  69. package/dist/core/types.js.map +1 -0
  70. package/dist/{vector-index.d.ts → core/vector-index.d.ts} +4 -0
  71. package/dist/core/vector-index.d.ts.map +1 -0
  72. package/dist/{vector-index.js → core/vector-index.js} +19 -0
  73. package/dist/core/vector-index.js.map +1 -0
  74. package/dist/dom-polyfills.d.ts +6 -0
  75. package/dist/dom-polyfills.d.ts.map +1 -0
  76. package/dist/dom-polyfills.js +40 -0
  77. package/dist/dom-polyfills.js.map +1 -0
  78. package/dist/examples/clean-api-examples.d.ts +44 -0
  79. package/dist/examples/clean-api-examples.d.ts.map +1 -0
  80. package/dist/examples/clean-api-examples.js +206 -0
  81. package/dist/examples/clean-api-examples.js.map +1 -0
  82. package/dist/factories/index.d.ts +43 -0
  83. package/dist/factories/index.d.ts.map +1 -0
  84. package/dist/factories/index.js +44 -0
  85. package/dist/factories/index.js.map +1 -0
  86. package/dist/factories/text-factory.d.ts +466 -0
  87. package/dist/factories/text-factory.d.ts.map +1 -0
  88. package/dist/factories/text-factory.js +719 -0
  89. package/dist/factories/text-factory.js.map +1 -0
  90. package/dist/file-processor.d.ts +2 -2
  91. package/dist/file-processor.d.ts.map +1 -1
  92. package/dist/file-processor.js +3 -3
  93. package/dist/file-processor.js.map +1 -1
  94. package/dist/index-manager.d.ts +3 -2
  95. package/dist/index-manager.d.ts.map +1 -1
  96. package/dist/index-manager.js +13 -11
  97. package/dist/index-manager.js.map +1 -1
  98. package/dist/index.d.ts +63 -8
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +91 -16
  101. package/dist/index.js.map +1 -1
  102. package/dist/indexer.js +1 -1
  103. package/dist/indexer.js.map +1 -1
  104. package/dist/ingestion.d.ts +30 -156
  105. package/dist/ingestion.d.ts.map +1 -1
  106. package/dist/ingestion.js +58 -675
  107. package/dist/ingestion.js.map +1 -1
  108. package/dist/mcp-server.js +86 -55
  109. package/dist/mcp-server.js.map +1 -1
  110. package/dist/preprocess.js +1 -1
  111. package/dist/preprocess.js.map +1 -1
  112. package/dist/search-standalone.js +1 -1
  113. package/dist/search-standalone.js.map +1 -1
  114. package/dist/search.d.ts +32 -76
  115. package/dist/search.d.ts.map +1 -1
  116. package/dist/search.js +80 -428
  117. package/dist/search.js.map +1 -1
  118. package/dist/text/chunker.d.ts +32 -0
  119. package/dist/text/chunker.d.ts.map +1 -0
  120. package/dist/{chunker.js → text/chunker.js} +98 -75
  121. package/dist/text/chunker.js.map +1 -0
  122. package/dist/{embedder.d.ts → text/embedder.d.ts} +22 -1
  123. package/dist/text/embedder.d.ts.map +1 -0
  124. package/dist/{embedder.js → text/embedder.js} +71 -4
  125. package/dist/text/embedder.js.map +1 -0
  126. package/dist/text/index.d.ts +7 -0
  127. package/dist/text/index.d.ts.map +1 -0
  128. package/dist/text/index.js +8 -0
  129. package/dist/text/index.js.map +1 -0
  130. package/dist/text/preprocessors/index.d.ts +17 -0
  131. package/dist/text/preprocessors/index.d.ts.map +1 -0
  132. package/dist/text/preprocessors/index.js +38 -0
  133. package/dist/text/preprocessors/index.js.map +1 -0
  134. package/dist/text/preprocessors/mdx.d.ts +25 -0
  135. package/dist/text/preprocessors/mdx.d.ts.map +1 -0
  136. package/dist/text/preprocessors/mdx.js +101 -0
  137. package/dist/text/preprocessors/mdx.js.map +1 -0
  138. package/dist/text/preprocessors/mermaid.d.ts +68 -0
  139. package/dist/text/preprocessors/mermaid.d.ts.map +1 -0
  140. package/dist/text/preprocessors/mermaid.js +330 -0
  141. package/dist/text/preprocessors/mermaid.js.map +1 -0
  142. package/dist/text/preprocessors/registry.d.ts +56 -0
  143. package/dist/text/preprocessors/registry.d.ts.map +1 -0
  144. package/dist/text/preprocessors/registry.js +180 -0
  145. package/dist/text/preprocessors/registry.js.map +1 -0
  146. package/dist/text/reranker.d.ts +60 -0
  147. package/dist/text/reranker.d.ts.map +1 -0
  148. package/dist/{reranker.js → text/reranker.js} +134 -19
  149. package/dist/text/reranker.js.map +1 -0
  150. package/dist/{tokenizer.d.ts → text/tokenizer.d.ts} +1 -0
  151. package/dist/text/tokenizer.d.ts.map +1 -0
  152. package/dist/{tokenizer.js → text/tokenizer.js} +7 -2
  153. package/dist/text/tokenizer.js.map +1 -0
  154. package/dist/types.d.ts +1 -1
  155. package/dist/types.d.ts.map +1 -1
  156. package/package.json +2 -2
  157. package/dist/chunker.d.ts +0 -47
  158. package/dist/chunker.d.ts.map +0 -1
  159. package/dist/chunker.js.map +0 -1
  160. package/dist/db.d.ts.map +0 -1
  161. package/dist/db.js.map +0 -1
  162. package/dist/embedder.d.ts.map +0 -1
  163. package/dist/embedder.js.map +0 -1
  164. package/dist/error-handler.d.ts.map +0 -1
  165. package/dist/error-handler.js.map +0 -1
  166. package/dist/path-manager.d.ts.map +0 -1
  167. package/dist/path-manager.js.map +0 -1
  168. package/dist/reranker.d.ts +0 -40
  169. package/dist/reranker.d.ts.map +0 -1
  170. package/dist/reranker.js.map +0 -1
  171. package/dist/resource-manager-demo.d.ts +0 -7
  172. package/dist/resource-manager-demo.d.ts.map +0 -1
  173. package/dist/resource-manager-demo.js +0 -52
  174. package/dist/resource-manager-demo.js.map +0 -1
  175. package/dist/resource-manager.d.ts +0 -129
  176. package/dist/resource-manager.d.ts.map +0 -1
  177. package/dist/resource-manager.js +0 -389
  178. package/dist/resource-manager.js.map +0 -1
  179. package/dist/tokenizer.d.ts.map +0 -1
  180. package/dist/tokenizer.js.map +0 -1
  181. package/dist/vector-index.d.ts.map +0 -1
  182. package/dist/vector-index.js.map +0 -1
@@ -0,0 +1,466 @@
1
+ /**
2
+ * Factory functions for creating text-specific search and ingestion instances
3
+ * Handles complex initialization logic while providing clean API for common use cases
4
+ *
5
+ * FACTORY PATTERN BENEFITS:
6
+ * - Abstracts complex initialization (model loading, database setup, index initialization)
7
+ * - Provides simple API for common use cases while preserving access to dependency injection
8
+ * - Handles error recovery and validation
9
+ * - Supports different embedding models and configurations
10
+ * - Enables clean separation between simple usage and advanced customization
11
+ *
12
+ * USAGE PATTERNS:
13
+ *
14
+ * 1. Simple Search Setup:
15
+ * ```typescript
16
+ * // Create search engine with defaults
17
+ * const search = await TextSearchFactory.create('./index.bin', './db.sqlite');
18
+ * const results = await search.search('query');
19
+ * ```
20
+ *
21
+ * 2. Custom Configuration:
22
+ * ```typescript
23
+ * // Create with custom options
24
+ * const search = await TextSearchFactory.create('./index.bin', './db.sqlite', {
25
+ * embeddingModel: 'all-MiniLM-L6-v2',
26
+ * enableReranking: true,
27
+ * topK: 20
28
+ * });
29
+ * ```
30
+ *
31
+ * 3. Complete RAG System:
32
+ * ```typescript
33
+ * // Create both ingestion and search
34
+ * const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
35
+ * './index.bin',
36
+ * './db.sqlite'
37
+ * );
38
+ *
39
+ * // Ingest documents
40
+ * await ingestionPipeline.ingestDirectory('./docs');
41
+ *
42
+ * // Search documents
43
+ * const results = await searchEngine.search('query');
44
+ * ```
45
+ *
46
+ * 4. Error Recovery:
47
+ * ```typescript
48
+ * // Create with automatic fallback options
49
+ * const search = await TextFactoryHelpers.createSearchWithFallback(
50
+ * './index.bin',
51
+ * './db.sqlite',
52
+ * { enableReranking: true } // Will fallback to disabled if reranking fails
53
+ * );
54
+ * ```
55
+ */
56
+ import { SearchEngine } from '../core/search.js';
57
+ import { IngestionPipeline } from '../core/ingestion.js';
58
+ /**
59
+ * Options for text search factory
60
+ */
61
+ export interface TextSearchOptions {
62
+ /** Embedding model name override */
63
+ embeddingModel?: string;
64
+ /** Embedding batch size override */
65
+ batchSize?: number;
66
+ /** Reranking model name override */
67
+ rerankingModel?: string;
68
+ /** Whether to enable reranking (default: true) */
69
+ enableReranking?: boolean;
70
+ /** Top-k results to return (default: from config) */
71
+ topK?: number;
72
+ }
73
+ /**
74
+ * Options for text ingestion factory
75
+ */
76
+ export interface TextIngestionOptions {
77
+ /** Embedding model name override */
78
+ embeddingModel?: string;
79
+ /** Embedding batch size override */
80
+ batchSize?: number;
81
+ /** Chunk size override */
82
+ chunkSize?: number;
83
+ /** Chunk overlap override */
84
+ chunkOverlap?: number;
85
+ /** Whether to force rebuild the index */
86
+ forceRebuild?: boolean;
87
+ }
88
+ /**
89
+ * Factory for creating text-based SearchEngine instances
90
+ * Handles model loading, database initialization, and index setup
91
+ *
92
+ * This factory abstracts the complex initialization process required for text search:
93
+ * 1. Loads and validates text embedding models
94
+ * 2. Optionally loads reranking models with fallback handling
95
+ * 3. Establishes database connections and initializes schema
96
+ * 4. Loads vector indexes with proper model compatibility checking
97
+ * 5. Creates SearchEngine with proper dependency injection
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // Basic usage
102
+ * const search = await TextSearchFactory.create('./index.bin', './db.sqlite');
103
+ * const results = await search.search('What is machine learning?');
104
+ *
105
+ * // With custom configuration
106
+ * const search = await TextSearchFactory.create('./index.bin', './db.sqlite', {
107
+ * embeddingModel: 'all-MiniLM-L6-v2',
108
+ * enableReranking: true,
109
+ * topK: 15
110
+ * });
111
+ *
112
+ * // With defaults (uses config file paths)
113
+ * const search = await TextSearchFactory.createWithDefaults({
114
+ * enableReranking: false // Faster search
115
+ * });
116
+ * ```
117
+ */
118
+ export declare class TextSearchFactory {
119
+ /**
120
+ * Create a SearchEngine configured for text search
121
+ *
122
+ * This method handles the complete initialization process:
123
+ * - Validates that required files exist
124
+ * - Loads text embedding model (with lazy initialization)
125
+ * - Optionally loads reranking model (with graceful fallback)
126
+ * - Opens database connection and initializes schema
127
+ * - Loads vector index with compatibility validation
128
+ * - Creates SearchEngine with dependency injection
129
+ * - Validates the complete setup
130
+ *
131
+ * @param indexPath - Path to the vector index file (must exist)
132
+ * @param dbPath - Path to the SQLite database file (must exist)
133
+ * @param options - Optional configuration overrides
134
+ * @param options.embeddingModel - Override embedding model (default: from config)
135
+ * @param options.batchSize - Override embedding batch size (default: from config)
136
+ * @param options.rerankingModel - Override reranking model (default: from config)
137
+ * @param options.enableReranking - Enable/disable reranking (default: true)
138
+ * @param options.topK - Number of results to return (default: from config)
139
+ * @returns Promise resolving to configured SearchEngine
140
+ * @throws {Error} If required files don't exist or initialization fails
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // Create search engine for existing index
145
+ * const search = await TextSearchFactory.create('./my-index.bin', './my-db.sqlite');
146
+ *
147
+ * // Search with the created engine
148
+ * const results = await search.search('artificial intelligence');
149
+ * console.log(`Found ${results.length} results`);
150
+ *
151
+ * // Clean up when done
152
+ * await search.cleanup();
153
+ * ```
154
+ */
155
+ static create(indexPath: string, dbPath: string, options?: TextSearchOptions): Promise<SearchEngine>;
156
+ /**
157
+ * Create a SearchEngine with automatic path resolution
158
+ * Uses default paths from configuration (config.index_file, config.db_file)
159
+ *
160
+ * This is a convenience method that uses the default file paths from the configuration,
161
+ * making it easy to create a search engine without specifying paths explicitly.
162
+ *
163
+ * @param options - Optional configuration overrides
164
+ * @param options.embeddingModel - Override embedding model
165
+ * @param options.enableReranking - Enable/disable reranking
166
+ * @param options.topK - Number of results to return
167
+ * @returns Promise resolving to configured SearchEngine
168
+ * @throws {Error} If default files don't exist or initialization fails
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * // Use default paths from config
173
+ * const search = await TextSearchFactory.createWithDefaults();
174
+ *
175
+ * // Use defaults with custom options
176
+ * const search = await TextSearchFactory.createWithDefaults({
177
+ * enableReranking: false,
178
+ * topK: 5
179
+ * });
180
+ * ```
181
+ */
182
+ static createWithDefaults(options?: TextSearchOptions): Promise<SearchEngine>;
183
+ }
184
+ /**
185
+ * Factory for creating text-based IngestionPipeline instances
186
+ * Handles model loading, database initialization, and index setup
187
+ *
188
+ * This factory abstracts the complex initialization process required for text ingestion:
189
+ * 1. Creates necessary directories if they don't exist
190
+ * 2. Loads and validates text embedding models
191
+ * 3. Establishes database connections and initializes schema
192
+ * 4. Creates or loads vector indexes with proper configuration
193
+ * 5. Creates IngestionPipeline with proper dependency injection
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * // Basic usage
198
+ * const ingestion = await TextIngestionFactory.create('./db.sqlite', './index.bin');
199
+ * await ingestion.ingestDirectory('./documents');
200
+ *
201
+ * // With custom configuration
202
+ * const ingestion = await TextIngestionFactory.create('./db.sqlite', './index.bin', {
203
+ * embeddingModel: 'all-MiniLM-L6-v2',
204
+ * chunkSize: 512,
205
+ * chunkOverlap: 50,
206
+ * forceRebuild: true
207
+ * });
208
+ *
209
+ * // With defaults
210
+ * const ingestion = await TextIngestionFactory.createWithDefaults({
211
+ * batchSize: 32 // Faster processing
212
+ * });
213
+ * ```
214
+ */
215
+ export declare class TextIngestionFactory {
216
+ /**
217
+ * Create an IngestionPipeline configured for text ingestion
218
+ *
219
+ * This method handles the complete initialization process:
220
+ * - Creates necessary directories if they don't exist
221
+ * - Loads text embedding model (with lazy initialization)
222
+ * - Opens database connection and initializes schema
223
+ * - Creates or loads vector index (with force rebuild option)
224
+ * - Creates IngestionPipeline with dependency injection
225
+ * - Validates the complete setup
226
+ *
227
+ * @param dbPath - Path to the SQLite database file (will be created if doesn't exist)
228
+ * @param indexPath - Path to the vector index file (will be created if doesn't exist)
229
+ * @param options - Optional configuration overrides
230
+ * @param options.embeddingModel - Override embedding model (default: from config)
231
+ * @param options.batchSize - Override embedding batch size (default: from config)
232
+ * @param options.chunkSize - Override chunk size (default: from config)
233
+ * @param options.chunkOverlap - Override chunk overlap (default: from config)
234
+ * @param options.forceRebuild - Force rebuild of existing index (default: false)
235
+ * @returns Promise resolving to configured IngestionPipeline
236
+ * @throws {Error} If initialization fails
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // Create ingestion pipeline
241
+ * const ingestion = await TextIngestionFactory.create('./my-db.sqlite', './my-index.bin');
242
+ *
243
+ * // Ingest documents from directory
244
+ * const result = await ingestion.ingestDirectory('./documents');
245
+ * console.log(`Processed ${result.documentsProcessed} documents`);
246
+ *
247
+ * // Ingest single file
248
+ * await ingestion.ingestFile('./document.pdf');
249
+ *
250
+ * // Clean up when done
251
+ * await ingestion.cleanup();
252
+ * ```
253
+ */
254
+ static create(dbPath: string, indexPath: string, options?: TextIngestionOptions): Promise<IngestionPipeline>;
255
+ /**
256
+ * Create an IngestionPipeline with automatic path resolution
257
+ * Uses default paths based on current working directory
258
+ * @param options - Optional configuration overrides
259
+ * @returns Promise resolving to configured IngestionPipeline
260
+ */
261
+ static createWithDefaults(options?: TextIngestionOptions): Promise<IngestionPipeline>;
262
+ }
263
+ /**
264
+ * Convenience factory to create both search and ingestion instances
265
+ * Useful for applications that need both capabilities with shared configuration
266
+ *
267
+ * This factory creates a complete RAG (Retrieval-Augmented Generation) system
268
+ * by initializing both ingestion and search capabilities with shared resources.
269
+ * The ingestion pipeline is created first to handle directory creation and
270
+ * initial setup, then the search engine is created to use the same resources.
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * // Create complete RAG system
275
+ * const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
276
+ * './index.bin',
277
+ * './db.sqlite'
278
+ * );
279
+ *
280
+ * // First, ingest some documents
281
+ * await ingestionPipeline.ingestDirectory('./knowledge-base');
282
+ *
283
+ * // Then search the ingested content
284
+ * const results = await searchEngine.search('What is the main topic?');
285
+ *
286
+ * // Clean up both instances
287
+ * await Promise.all([
288
+ * searchEngine.cleanup(),
289
+ * ingestionPipeline.cleanup()
290
+ * ]);
291
+ * ```
292
+ */
293
+ export declare class TextRAGFactory {
294
+ /**
295
+ * Create both SearchEngine and IngestionPipeline instances
296
+ *
297
+ * This method creates a complete RAG system by:
298
+ * 1. Creating an ingestion pipeline (handles directory creation)
299
+ * 2. Creating a search engine (uses the same database and index)
300
+ * 3. Ensuring both instances use compatible configurations
301
+ *
302
+ * The ingestion pipeline is created first because it handles directory
303
+ * creation and initial setup, while the search engine requires existing
304
+ * files to validate the setup.
305
+ *
306
+ * @param indexPath - Path to the vector index file
307
+ * @param dbPath - Path to the SQLite database file
308
+ * @param searchOptions - Optional search configuration
309
+ * @param searchOptions.enableReranking - Enable reranking for better results
310
+ * @param searchOptions.topK - Number of search results to return
311
+ * @param ingestionOptions - Optional ingestion configuration
312
+ * @param ingestionOptions.chunkSize - Size of text chunks for processing
313
+ * @param ingestionOptions.forceRebuild - Force rebuild of existing index
314
+ * @returns Promise resolving to both configured instances
315
+ * @throws {Error} If initialization of either component fails
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * // Create with custom options for both components
320
+ * const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
321
+ * './index.bin',
322
+ * './db.sqlite',
323
+ * { enableReranking: true, topK: 15 }, // Search options
324
+ * { chunkSize: 512, forceRebuild: true } // Ingestion options
325
+ * );
326
+ *
327
+ * // Use the complete system
328
+ * await ingestionPipeline.ingestDirectory('./docs');
329
+ * const results = await searchEngine.search('machine learning');
330
+ * ```
331
+ */
332
+ static createBoth(indexPath: string, dbPath: string, searchOptions?: TextSearchOptions, ingestionOptions?: TextIngestionOptions): Promise<{
333
+ searchEngine: SearchEngine;
334
+ ingestionPipeline: IngestionPipeline;
335
+ }>;
336
+ /**
337
+ * Create both instances with default paths
338
+ * @param searchOptions - Optional search configuration
339
+ * @param ingestionOptions - Optional ingestion configuration
340
+ * @returns Promise resolving to both instances
341
+ */
342
+ static createBothWithDefaults(searchOptions?: TextSearchOptions, ingestionOptions?: TextIngestionOptions): Promise<{
343
+ searchEngine: SearchEngine;
344
+ ingestionPipeline: IngestionPipeline;
345
+ }>;
346
+ }
347
+ /**
348
+ * Helper functions for common factory patterns and error recovery
349
+ *
350
+ * This class provides utility functions that support the main factory classes
351
+ * with validation, configuration recommendations, and error recovery patterns.
352
+ * These helpers enable more robust factory usage and better error handling.
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * // Validate files before creating search engine
357
+ * try {
358
+ * TextFactoryHelpers.validateSearchFiles('./index.bin', './db.sqlite');
359
+ * const search = await TextSearchFactory.create('./index.bin', './db.sqlite');
360
+ * } catch (error) {
361
+ * console.error('Files not ready for search:', error.message);
362
+ * }
363
+ *
364
+ * // Get recommended configuration for different use cases
365
+ * const { searchOptions, ingestionOptions } = TextFactoryHelpers.getRecommendedConfig('quality');
366
+ * const search = await TextSearchFactory.create('./index.bin', './db.sqlite', searchOptions);
367
+ *
368
+ * // Create with automatic error recovery
369
+ * const search = await TextFactoryHelpers.createSearchWithFallback('./index.bin', './db.sqlite', {
370
+ * enableReranking: true // Will fallback to disabled if reranking fails
371
+ * });
372
+ * ```
373
+ */
374
+ export declare class TextFactoryHelpers {
375
+ /**
376
+ * Validate that required files exist for search operations
377
+ *
378
+ * This method checks that both the vector index and database files exist
379
+ * and provides helpful error messages with suggestions for resolution.
380
+ * Use this before attempting to create a search engine to get better
381
+ * error messages than the generic file not found errors.
382
+ *
383
+ * @param indexPath - Path to vector index file
384
+ * @param dbPath - Path to database file
385
+ * @throws {Error} If either file doesn't exist, with helpful resolution steps
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * // Validate before creating search engine
390
+ * try {
391
+ * TextFactoryHelpers.validateSearchFiles('./index.bin', './db.sqlite');
392
+ * console.log('Files are ready for search');
393
+ * } catch (error) {
394
+ * console.error('Search files not ready:', error.message);
395
+ * // Error message includes suggestions like "Run ingestion first"
396
+ * }
397
+ * ```
398
+ */
399
+ static validateSearchFiles(indexPath: string, dbPath: string): void;
400
+ /**
401
+ * Get recommended configuration for different use cases
402
+ *
403
+ * This method provides pre-configured options optimized for different
404
+ * performance vs quality trade-offs. Use these as starting points
405
+ * and adjust based on your specific requirements.
406
+ *
407
+ * @param useCase - The intended use case scenario
408
+ * @param useCase.fast - Optimized for speed (no reranking, smaller chunks)
409
+ * @param useCase.balanced - Good balance of speed and quality (default)
410
+ * @param useCase.quality - Optimized for best results (reranking enabled, larger chunks)
411
+ * @returns Recommended configuration for both search and ingestion
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * // Get configuration for quality-focused use case
416
+ * const { searchOptions, ingestionOptions } = TextFactoryHelpers.getRecommendedConfig('quality');
417
+ *
418
+ * // Create instances with recommended settings
419
+ * const ingestion = await TextIngestionFactory.create('./db.sqlite', './index.bin', ingestionOptions);
420
+ * const search = await TextSearchFactory.create('./index.bin', './db.sqlite', searchOptions);
421
+ *
422
+ * // Or use with RAG factory
423
+ * const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
424
+ * './index.bin',
425
+ * './db.sqlite',
426
+ * searchOptions,
427
+ * ingestionOptions
428
+ * );
429
+ * ```
430
+ */
431
+ static getRecommendedConfig(useCase: 'fast' | 'balanced' | 'quality'): {
432
+ searchOptions: TextSearchOptions;
433
+ ingestionOptions: TextIngestionOptions;
434
+ };
435
+ /**
436
+ * Create a search engine with automatic error recovery
437
+ *
438
+ * This method attempts to create a search engine with the provided options,
439
+ * and if that fails, it tries again with fallback options (primarily
440
+ * disabling reranking, which is a common source of initialization failures).
441
+ * This provides a more robust way to create search engines in environments
442
+ * where reranking models might not be available or might fail to load.
443
+ *
444
+ * @param indexPath - Path to vector index file
445
+ * @param dbPath - Path to database file
446
+ * @param options - Initial options to try
447
+ * @returns Promise resolving to SearchEngine (possibly with fallback options)
448
+ * @throws {Error} If both original and fallback creation attempts fail
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * // Try to create with reranking, fallback to without if it fails
453
+ * const search = await TextFactoryHelpers.createSearchWithFallback(
454
+ * './index.bin',
455
+ * './db.sqlite',
456
+ * { enableReranking: true, topK: 20 }
457
+ * );
458
+ *
459
+ * // The search engine will work even if reranking model fails to load
460
+ * const results = await search.search('query');
461
+ * console.log(`Search created successfully with ${results.length} results`);
462
+ * ```
463
+ */
464
+ static createSearchWithFallback(indexPath: string, dbPath: string, options?: TextSearchOptions): Promise<SearchEngine>;
465
+ }
466
+ //# sourceMappingURL=text-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-factory.d.ts","sourceRoot":"","sources":["../../src/factories/text-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAWzD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,oCAAoC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,oCAAoC;IACpC,cAAc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