rag-lite-ts 2.0.3 → 2.0.4
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/dist/cli/indexer.js +4 -4
- package/dist/cli/search.js +3 -3
- package/dist/cli.js +31 -4
- package/dist/core/actionable-error-messages.js +3 -3
- package/dist/core/content-manager.d.ts +0 -8
- package/dist/core/content-manager.js +2 -30
- package/dist/core/database-connection-manager.js +10 -0
- package/dist/core/db.d.ts +0 -32
- package/dist/core/db.js +11 -68
- package/dist/core/embedder-factory.d.ts +0 -22
- package/dist/core/embedder-factory.js +8 -35
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/ingestion.d.ts +1 -16
- package/dist/core/ingestion.js +1 -30
- package/dist/core/interfaces.d.ts +1 -1
- package/dist/core/interfaces.js +1 -1
- package/dist/core/model-registry.d.ts +0 -4
- package/dist/core/model-registry.js +5 -9
- package/dist/core/search.d.ts +2 -2
- package/dist/core/search.js +2 -2
- package/dist/factories/index.d.ts +11 -29
- package/dist/factories/index.js +12 -29
- package/dist/factories/ingestion-factory.d.ts +200 -0
- package/dist/factories/ingestion-factory.js +475 -0
- package/dist/{core/polymorphic-search-factory.d.ts → factories/search-factory.d.ts} +7 -7
- package/dist/{core/polymorphic-search-factory.js → factories/search-factory.js} +22 -22
- package/dist/index-manager.js +25 -14
- package/dist/index.d.ts +5 -30
- package/dist/index.js +9 -24
- package/dist/ingestion.d.ts +2 -4
- package/dist/ingestion.js +2 -2
- package/dist/mcp-server.js +15 -16
- package/dist/search.js +2 -2
- package/dist/text/embedder.d.ts +0 -11
- package/dist/text/embedder.js +11 -22
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +2 -2
- package/dist/text/reranker.d.ts +0 -10
- package/dist/text/reranker.js +10 -33
- package/package.json +7 -3
- package/dist/factories/polymorphic-factory.d.ts +0 -50
- package/dist/factories/polymorphic-factory.js +0 -159
- package/dist/factories/text-factory.d.ts +0 -560
- package/dist/factories/text-factory.js +0 -982
|
@@ -1,560 +0,0 @@
|
|
|
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
|
-
* - Clear validation and error handling without fallback mechanisms
|
|
9
|
-
* - Supports different embedding models and configurations
|
|
10
|
-
* - Enables clean separation between simple usage and advanced customization
|
|
11
|
-
*
|
|
12
|
-
* MODE SELECTION GUIDE:
|
|
13
|
-
* - Text Mode (default): Optimized for text-only content
|
|
14
|
-
* - Uses sentence-transformer models (fast, accurate for text)
|
|
15
|
-
* - Images converted to text descriptions
|
|
16
|
-
* - Best for: document search, text clustering, semantic similarity
|
|
17
|
-
*
|
|
18
|
-
* - Multimodal Mode: Optimized for mixed text/image content
|
|
19
|
-
* - Uses CLIP models (unified embedding space)
|
|
20
|
-
* - True cross-modal search (text finds images, images find text)
|
|
21
|
-
* - Best for: image search, visual QA, multimodal retrieval
|
|
22
|
-
*
|
|
23
|
-
* USAGE PATTERNS:
|
|
24
|
-
*
|
|
25
|
-
* 1. Simple Search Setup:
|
|
26
|
-
* ```typescript
|
|
27
|
-
* // Create search engine with defaults
|
|
28
|
-
* const search = await TextSearchFactory.create('./index.bin', './db.sqlite');
|
|
29
|
-
* const results = await search.search('query');
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* 2. Custom Configuration:
|
|
33
|
-
* ```typescript
|
|
34
|
-
* // Create with custom options
|
|
35
|
-
* const search = await TextSearchFactory.create('./index.bin', './db.sqlite', {
|
|
36
|
-
* embeddingModel: 'all-MiniLM-L6-v2',
|
|
37
|
-
* enableReranking: true,
|
|
38
|
-
* topK: 20
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* 3. Complete RAG System:
|
|
43
|
-
* ```typescript
|
|
44
|
-
* // Create both ingestion and search
|
|
45
|
-
* const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
|
|
46
|
-
* './index.bin',
|
|
47
|
-
* './db.sqlite'
|
|
48
|
-
* );
|
|
49
|
-
*
|
|
50
|
-
* // Ingest documents
|
|
51
|
-
* await ingestionPipeline.ingestDirectory('./docs');
|
|
52
|
-
*
|
|
53
|
-
* // Search documents
|
|
54
|
-
* const results = await searchEngine.search('query');
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* 4. Clear Error Handling:
|
|
58
|
-
* ```typescript
|
|
59
|
-
* // Create with clear validation and error reporting
|
|
60
|
-
* const search = await TextFactoryHelpers.createSearchWithValidation(
|
|
61
|
-
* './index.bin',
|
|
62
|
-
* './db.sqlite',
|
|
63
|
-
* { enableReranking: true } // Clear errors if issues occur
|
|
64
|
-
* );
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* 5. Mode Selection:
|
|
68
|
-
* ```typescript
|
|
69
|
-
* // Text mode (default) - optimized for text-only content
|
|
70
|
-
* const textIngestion = await TextIngestionFactory.create('./db.sqlite', './index.bin', {
|
|
71
|
-
* mode: 'text',
|
|
72
|
-
* embeddingModel: 'sentence-transformers/all-MiniLM-L6-v2'
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* // Multimodal mode - enables cross-modal search
|
|
76
|
-
* const multimodalIngestion = await TextIngestionFactory.create('./db.sqlite', './index.bin', {
|
|
77
|
-
* mode: 'multimodal',
|
|
78
|
-
* embeddingModel: 'Xenova/clip-vit-base-patch32',
|
|
79
|
-
* rerankingStrategy: 'text-derived'
|
|
80
|
-
* });
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
import { SearchEngine } from '../core/search.js';
|
|
84
|
-
import { IngestionPipeline } from '../core/ingestion.js';
|
|
85
|
-
/**
|
|
86
|
-
* Options for text search factory
|
|
87
|
-
*/
|
|
88
|
-
export interface TextSearchOptions {
|
|
89
|
-
/** Embedding model name override */
|
|
90
|
-
embeddingModel?: string;
|
|
91
|
-
/** Embedding batch size override */
|
|
92
|
-
batchSize?: number;
|
|
93
|
-
/** Reranking model name override */
|
|
94
|
-
rerankingModel?: string;
|
|
95
|
-
/** Whether to enable reranking (default: true) */
|
|
96
|
-
enableReranking?: boolean;
|
|
97
|
-
/** Top-k results to return (default: from config) */
|
|
98
|
-
topK?: number;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Content system configuration options
|
|
102
|
-
*/
|
|
103
|
-
export interface ContentSystemConfig {
|
|
104
|
-
/** Content directory path (default: '.raglite/content') */
|
|
105
|
-
contentDir?: string;
|
|
106
|
-
/** Maximum file size in bytes (default: 50MB) */
|
|
107
|
-
maxFileSize?: number;
|
|
108
|
-
/** Maximum content directory size in bytes (default: 2GB) */
|
|
109
|
-
maxContentDirSize?: number;
|
|
110
|
-
/** Enable content deduplication (default: true) */
|
|
111
|
-
enableDeduplication?: boolean;
|
|
112
|
-
/** Enable storage tracking (default: true) */
|
|
113
|
-
enableStorageTracking?: boolean;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Options for text ingestion factory
|
|
117
|
-
*/
|
|
118
|
-
export interface TextIngestionOptions {
|
|
119
|
-
/** Embedding model name override */
|
|
120
|
-
embeddingModel?: string;
|
|
121
|
-
/** Embedding batch size override */
|
|
122
|
-
batchSize?: number;
|
|
123
|
-
/** Chunk size override */
|
|
124
|
-
chunkSize?: number;
|
|
125
|
-
/** Chunk overlap override */
|
|
126
|
-
chunkOverlap?: number;
|
|
127
|
-
/** Whether to force rebuild the index */
|
|
128
|
-
forceRebuild?: boolean;
|
|
129
|
-
/** Mode for the ingestion pipeline (text or multimodal) */
|
|
130
|
-
mode?: 'text' | 'multimodal';
|
|
131
|
-
/** Reranking strategy for multimodal mode */
|
|
132
|
-
rerankingStrategy?: 'cross-encoder' | 'text-derived' | 'metadata' | 'hybrid' | 'disabled';
|
|
133
|
-
/** Content system configuration */
|
|
134
|
-
contentSystemConfig?: ContentSystemConfig;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Factory for creating text-based SearchEngine instances
|
|
138
|
-
* Handles model loading, database initialization, and index setup
|
|
139
|
-
*
|
|
140
|
-
* This factory abstracts the complex initialization process required for text search:
|
|
141
|
-
* 1. Auto-detects embedding model from database configuration
|
|
142
|
-
* 2. Validates mode-model compatibility (no fallback mechanisms)
|
|
143
|
-
* 3. Loads embedding models with clear error reporting
|
|
144
|
-
* 4. Optionally loads reranking models based on configuration
|
|
145
|
-
* 5. Establishes database connections and initializes schema
|
|
146
|
-
* 6. Loads vector indexes with proper model compatibility checking
|
|
147
|
-
* 7. Creates SearchEngine with proper dependency injection
|
|
148
|
-
*
|
|
149
|
-
* Mode Support:
|
|
150
|
-
* - Automatically detects mode from database (text or multimodal)
|
|
151
|
-
* - Each mode uses its optimal implementation without fallbacks
|
|
152
|
-
* - Clear validation ensures mode-model compatibility
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* // Basic usage
|
|
157
|
-
* const search = await TextSearchFactory.create('./index.bin', './db.sqlite');
|
|
158
|
-
* const results = await search.search('What is machine learning?');
|
|
159
|
-
*
|
|
160
|
-
* // With custom configuration
|
|
161
|
-
* const search = await TextSearchFactory.create('./index.bin', './db.sqlite', {
|
|
162
|
-
* embeddingModel: 'all-MiniLM-L6-v2',
|
|
163
|
-
* enableReranking: true,
|
|
164
|
-
* topK: 15
|
|
165
|
-
* });
|
|
166
|
-
*
|
|
167
|
-
* // With defaults (uses config file paths)
|
|
168
|
-
* const search = await TextSearchFactory.createWithDefaults({
|
|
169
|
-
* enableReranking: false // Faster search
|
|
170
|
-
* });
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
export declare class TextSearchFactory {
|
|
174
|
-
/**
|
|
175
|
-
* Create a SearchEngine configured for text search
|
|
176
|
-
*
|
|
177
|
-
* This method handles the complete initialization process:
|
|
178
|
-
* - Validates that required files exist
|
|
179
|
-
* - Loads text embedding model (with lazy initialization)
|
|
180
|
-
* - Optionally loads reranking model (with clear error reporting)
|
|
181
|
-
* - Opens database connection and initializes schema
|
|
182
|
-
* - Loads vector index with compatibility validation
|
|
183
|
-
* - Creates SearchEngine with dependency injection
|
|
184
|
-
* - Validates the complete setup
|
|
185
|
-
*
|
|
186
|
-
* @param indexPath - Path to the vector index file (must exist)
|
|
187
|
-
* @param dbPath - Path to the SQLite database file (must exist)
|
|
188
|
-
* @param options - Optional configuration overrides
|
|
189
|
-
* @param options.embeddingModel - Override embedding model (default: from config)
|
|
190
|
-
* @param options.batchSize - Override embedding batch size (default: from config)
|
|
191
|
-
* @param options.rerankingModel - Override reranking model (default: from config)
|
|
192
|
-
* @param options.enableReranking - Enable/disable reranking (default: true)
|
|
193
|
-
* @param options.topK - Number of results to return (default: from config)
|
|
194
|
-
* @returns Promise resolving to configured SearchEngine
|
|
195
|
-
* @throws {Error} If required files don't exist or initialization fails
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* // Create search engine for existing index
|
|
200
|
-
* const search = await TextSearchFactory.create('./my-index.bin', './my-db.sqlite');
|
|
201
|
-
*
|
|
202
|
-
* // Search with the created engine
|
|
203
|
-
* const results = await search.search('artificial intelligence');
|
|
204
|
-
* console.log(`Found ${results.length} results`);
|
|
205
|
-
*
|
|
206
|
-
* // Clean up when done
|
|
207
|
-
* await search.cleanup();
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
static create(indexPath: string, dbPath: string, options?: TextSearchOptions): Promise<SearchEngine>;
|
|
211
|
-
/**
|
|
212
|
-
* Create a SearchEngine with automatic path resolution
|
|
213
|
-
* Uses default paths from configuration (config.index_file, config.db_file)
|
|
214
|
-
*
|
|
215
|
-
* This is a convenience method that uses the default file paths from the configuration,
|
|
216
|
-
* making it easy to create a search engine without specifying paths explicitly.
|
|
217
|
-
*
|
|
218
|
-
* @param options - Optional configuration overrides
|
|
219
|
-
* @param options.embeddingModel - Override embedding model
|
|
220
|
-
* @param options.enableReranking - Enable/disable reranking
|
|
221
|
-
* @param options.topK - Number of results to return
|
|
222
|
-
* @returns Promise resolving to configured SearchEngine
|
|
223
|
-
* @throws {Error} If default files don't exist or initialization fails
|
|
224
|
-
*
|
|
225
|
-
* @example
|
|
226
|
-
* ```typescript
|
|
227
|
-
* // Use default paths from config
|
|
228
|
-
* const search = await TextSearchFactory.createWithDefaults();
|
|
229
|
-
*
|
|
230
|
-
* // Use defaults with custom options
|
|
231
|
-
* const search = await TextSearchFactory.createWithDefaults({
|
|
232
|
-
* enableReranking: false,
|
|
233
|
-
* topK: 5
|
|
234
|
-
* });
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
static createWithDefaults(options?: TextSearchOptions): Promise<SearchEngine>;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Factory for creating text-based IngestionPipeline instances
|
|
241
|
-
* Handles model loading, database initialization, and index setup
|
|
242
|
-
*
|
|
243
|
-
* This factory abstracts the complex initialization process required for text ingestion:
|
|
244
|
-
* 1. Creates necessary directories if they don't exist
|
|
245
|
-
* 2. Validates mode-model compatibility (no fallback mechanisms)
|
|
246
|
-
* 3. Loads and validates embedding models with clear error reporting
|
|
247
|
-
* 4. Establishes database connections and initializes schema
|
|
248
|
-
* 5. Stores mode configuration in database for automatic detection
|
|
249
|
-
* 6. Creates or loads vector indexes with proper configuration
|
|
250
|
-
* 7. Creates IngestionPipeline with proper dependency injection
|
|
251
|
-
*
|
|
252
|
-
* Mode Configuration:
|
|
253
|
-
* - Text Mode (default): Uses sentence-transformer models for text-only content
|
|
254
|
-
* - Multimodal Mode: Uses CLIP models for mixed text/image content
|
|
255
|
-
* - Mode is stored in database and auto-detected during search
|
|
256
|
-
* - Clear validation prevents mode-model mismatches
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```typescript
|
|
260
|
-
* // Basic usage
|
|
261
|
-
* const ingestion = await TextIngestionFactory.create('./db.sqlite', './index.bin');
|
|
262
|
-
* await ingestion.ingestDirectory('./documents');
|
|
263
|
-
*
|
|
264
|
-
* // With custom configuration
|
|
265
|
-
* const ingestion = await TextIngestionFactory.create('./db.sqlite', './index.bin', {
|
|
266
|
-
* embeddingModel: 'all-MiniLM-L6-v2',
|
|
267
|
-
* chunkSize: 512,
|
|
268
|
-
* chunkOverlap: 50,
|
|
269
|
-
* forceRebuild: true
|
|
270
|
-
* });
|
|
271
|
-
*
|
|
272
|
-
* // With defaults
|
|
273
|
-
* const ingestion = await TextIngestionFactory.createWithDefaults({
|
|
274
|
-
* batchSize: 32 // Faster processing
|
|
275
|
-
* });
|
|
276
|
-
* ```
|
|
277
|
-
*/
|
|
278
|
-
export declare class TextIngestionFactory {
|
|
279
|
-
/**
|
|
280
|
-
* Create an IngestionPipeline configured for text ingestion
|
|
281
|
-
*
|
|
282
|
-
* This method handles the complete initialization process:
|
|
283
|
-
* - Creates necessary directories if they don't exist
|
|
284
|
-
* - Loads text embedding model (with lazy initialization)
|
|
285
|
-
* - Opens database connection and initializes schema
|
|
286
|
-
* - Creates or loads vector index (with force rebuild option)
|
|
287
|
-
* - Creates IngestionPipeline with dependency injection
|
|
288
|
-
* - Validates the complete setup
|
|
289
|
-
*
|
|
290
|
-
* @param dbPath - Path to the SQLite database file (will be created if doesn't exist)
|
|
291
|
-
* @param indexPath - Path to the vector index file (will be created if doesn't exist)
|
|
292
|
-
* @param options - Optional configuration overrides
|
|
293
|
-
* @param options.embeddingModel - Override embedding model (default: from config)
|
|
294
|
-
* @param options.batchSize - Override embedding batch size (default: from config)
|
|
295
|
-
* @param options.chunkSize - Override chunk size (default: from config)
|
|
296
|
-
* @param options.chunkOverlap - Override chunk overlap (default: from config)
|
|
297
|
-
* @param options.forceRebuild - Force rebuild of existing index (default: false)
|
|
298
|
-
* @param options.contentSystemConfig - Content system configuration options
|
|
299
|
-
* @param options.contentSystemConfig.contentDir - Content directory path (default: '.raglite/content')
|
|
300
|
-
* @param options.contentSystemConfig.maxFileSize - Maximum file size in bytes (default: 50MB)
|
|
301
|
-
* @param options.contentSystemConfig.maxContentDirSize - Maximum content directory size (default: 2GB)
|
|
302
|
-
* @param options.contentSystemConfig.enableDeduplication - Enable content deduplication (default: true)
|
|
303
|
-
* @param options.contentSystemConfig.enableStorageTracking - Enable storage tracking (default: true)
|
|
304
|
-
* @returns Promise resolving to configured IngestionPipeline
|
|
305
|
-
* @throws {Error} If initialization fails
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* ```typescript
|
|
309
|
-
* // Create ingestion pipeline with default content system
|
|
310
|
-
* const ingestion = await TextIngestionFactory.create('./my-db.sqlite', './my-index.bin');
|
|
311
|
-
*
|
|
312
|
-
* // Create with custom content system configuration
|
|
313
|
-
* const ingestion = await TextIngestionFactory.create('./my-db.sqlite', './my-index.bin', {
|
|
314
|
-
* contentSystemConfig: {
|
|
315
|
-
* contentDir: './custom-content',
|
|
316
|
-
* maxFileSize: 100 * 1024 * 1024, // 100MB
|
|
317
|
-
* maxContentDirSize: 5 * 1024 * 1024 * 1024, // 5GB
|
|
318
|
-
* enableDeduplication: true
|
|
319
|
-
* }
|
|
320
|
-
* });
|
|
321
|
-
*
|
|
322
|
-
* // Ingest documents from directory
|
|
323
|
-
* const result = await ingestion.ingestDirectory('./documents');
|
|
324
|
-
* console.log(`Processed ${result.documentsProcessed} documents`);
|
|
325
|
-
*
|
|
326
|
-
* // Ingest content from memory (MCP integration)
|
|
327
|
-
* const contentId = await ingestion.ingestFromMemory(buffer, {
|
|
328
|
-
* displayName: 'uploaded-file.pdf',
|
|
329
|
-
* contentType: 'application/pdf'
|
|
330
|
-
* });
|
|
331
|
-
*
|
|
332
|
-
* // Clean up when done
|
|
333
|
-
* await ingestion.cleanup();
|
|
334
|
-
* ```
|
|
335
|
-
*/
|
|
336
|
-
static create(dbPath: string, indexPath: string, options?: TextIngestionOptions): Promise<IngestionPipeline>;
|
|
337
|
-
/**
|
|
338
|
-
* Create an IngestionPipeline with automatic path resolution
|
|
339
|
-
* Uses default paths based on current working directory
|
|
340
|
-
* @param options - Optional configuration overrides
|
|
341
|
-
* @returns Promise resolving to configured IngestionPipeline
|
|
342
|
-
*/
|
|
343
|
-
static createWithDefaults(options?: TextIngestionOptions): Promise<IngestionPipeline>;
|
|
344
|
-
/**
|
|
345
|
-
* Handles mode storage during ingestion
|
|
346
|
-
* Creates or validates system info based on the provided mode and options
|
|
347
|
-
* @private
|
|
348
|
-
*/
|
|
349
|
-
private static handleModeStorage;
|
|
350
|
-
/**
|
|
351
|
-
* Updates system info in the database
|
|
352
|
-
* @private
|
|
353
|
-
*/
|
|
354
|
-
private static updateSystemInfo;
|
|
355
|
-
/**
|
|
356
|
-
* Validates and prepares content system configuration
|
|
357
|
-
* @private
|
|
358
|
-
*/
|
|
359
|
-
private static validateAndPrepareContentSystemConfig;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Convenience factory to create both search and ingestion instances
|
|
363
|
-
* Useful for applications that need both capabilities with shared configuration
|
|
364
|
-
*
|
|
365
|
-
* This factory creates a complete RAG (Retrieval-Augmented Generation) system
|
|
366
|
-
* by initializing both ingestion and search capabilities with shared resources.
|
|
367
|
-
* The ingestion pipeline is created first to handle directory creation and
|
|
368
|
-
* initial setup, then the search engine is created to use the same resources.
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* ```typescript
|
|
372
|
-
* // Create complete RAG system
|
|
373
|
-
* const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
|
|
374
|
-
* './index.bin',
|
|
375
|
-
* './db.sqlite'
|
|
376
|
-
* );
|
|
377
|
-
*
|
|
378
|
-
* // First, ingest some documents
|
|
379
|
-
* await ingestionPipeline.ingestDirectory('./knowledge-base');
|
|
380
|
-
*
|
|
381
|
-
* // Then search the ingested content
|
|
382
|
-
* const results = await searchEngine.search('What is the main topic?');
|
|
383
|
-
*
|
|
384
|
-
* // Clean up both instances
|
|
385
|
-
* await Promise.all([
|
|
386
|
-
* searchEngine.cleanup(),
|
|
387
|
-
* ingestionPipeline.cleanup()
|
|
388
|
-
* ]);
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
export declare class TextRAGFactory {
|
|
392
|
-
/**
|
|
393
|
-
* Create both SearchEngine and IngestionPipeline instances
|
|
394
|
-
*
|
|
395
|
-
* This method creates a complete RAG system by:
|
|
396
|
-
* 1. Creating an ingestion pipeline (handles directory creation)
|
|
397
|
-
* 2. Creating a search engine (uses the same database and index)
|
|
398
|
-
* 3. Ensuring both instances use compatible configurations
|
|
399
|
-
*
|
|
400
|
-
* The ingestion pipeline is created first because it handles directory
|
|
401
|
-
* creation and initial setup, while the search engine requires existing
|
|
402
|
-
* files to validate the setup.
|
|
403
|
-
*
|
|
404
|
-
* @param indexPath - Path to the vector index file
|
|
405
|
-
* @param dbPath - Path to the SQLite database file
|
|
406
|
-
* @param searchOptions - Optional search configuration
|
|
407
|
-
* @param searchOptions.enableReranking - Enable reranking for better results
|
|
408
|
-
* @param searchOptions.topK - Number of search results to return
|
|
409
|
-
* @param ingestionOptions - Optional ingestion configuration
|
|
410
|
-
* @param ingestionOptions.chunkSize - Size of text chunks for processing
|
|
411
|
-
* @param ingestionOptions.forceRebuild - Force rebuild of existing index
|
|
412
|
-
* @returns Promise resolving to both configured instances
|
|
413
|
-
* @throws {Error} If initialization of either component fails
|
|
414
|
-
*
|
|
415
|
-
* @example
|
|
416
|
-
* ```typescript
|
|
417
|
-
* // Create with custom options for both components
|
|
418
|
-
* const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
|
|
419
|
-
* './index.bin',
|
|
420
|
-
* './db.sqlite',
|
|
421
|
-
* { enableReranking: true, topK: 15 }, // Search options
|
|
422
|
-
* { chunkSize: 512, forceRebuild: true } // Ingestion options
|
|
423
|
-
* );
|
|
424
|
-
*
|
|
425
|
-
* // Use the complete system
|
|
426
|
-
* await ingestionPipeline.ingestDirectory('./docs');
|
|
427
|
-
* const results = await searchEngine.search('machine learning');
|
|
428
|
-
* ```
|
|
429
|
-
*/
|
|
430
|
-
static createBoth(indexPath: string, dbPath: string, searchOptions?: TextSearchOptions, ingestionOptions?: TextIngestionOptions): Promise<{
|
|
431
|
-
searchEngine: SearchEngine;
|
|
432
|
-
ingestionPipeline: IngestionPipeline;
|
|
433
|
-
}>;
|
|
434
|
-
/**
|
|
435
|
-
* Create both instances with default paths
|
|
436
|
-
* @param searchOptions - Optional search configuration
|
|
437
|
-
* @param ingestionOptions - Optional ingestion configuration
|
|
438
|
-
* @returns Promise resolving to both instances
|
|
439
|
-
*/
|
|
440
|
-
static createBothWithDefaults(searchOptions?: TextSearchOptions, ingestionOptions?: TextIngestionOptions): Promise<{
|
|
441
|
-
searchEngine: SearchEngine;
|
|
442
|
-
ingestionPipeline: IngestionPipeline;
|
|
443
|
-
}>;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Helper functions for common factory patterns and error recovery
|
|
447
|
-
*
|
|
448
|
-
* This class provides utility functions that support the main factory classes
|
|
449
|
-
* with validation, configuration recommendations, and error recovery patterns.
|
|
450
|
-
* These helpers enable more robust factory usage and better error handling.
|
|
451
|
-
*
|
|
452
|
-
* @example
|
|
453
|
-
* ```typescript
|
|
454
|
-
* // Validate files before creating search engine
|
|
455
|
-
* try {
|
|
456
|
-
* TextFactoryHelpers.validateSearchFiles('./index.bin', './db.sqlite');
|
|
457
|
-
* const search = await TextSearchFactory.create('./index.bin', './db.sqlite');
|
|
458
|
-
* } catch (error) {
|
|
459
|
-
* console.error('Files not ready for search:', error.message);
|
|
460
|
-
* }
|
|
461
|
-
*
|
|
462
|
-
* // Get recommended configuration for different use cases
|
|
463
|
-
* const { searchOptions, ingestionOptions } = TextFactoryHelpers.getRecommendedConfig('quality');
|
|
464
|
-
* const search = await TextSearchFactory.create('./index.bin', './db.sqlite', searchOptions);
|
|
465
|
-
*
|
|
466
|
-
* // Create with clear validation and error reporting
|
|
467
|
-
* const search = await TextFactoryHelpers.createSearchWithValidation('./index.bin', './db.sqlite', {
|
|
468
|
-
* enableReranking: true // Will fail clearly if reranking has issues
|
|
469
|
-
* });
|
|
470
|
-
* ```
|
|
471
|
-
*/
|
|
472
|
-
export declare class TextFactoryHelpers {
|
|
473
|
-
/**
|
|
474
|
-
* Validate that required files exist for search operations
|
|
475
|
-
*
|
|
476
|
-
* This method checks that both the vector index and database files exist
|
|
477
|
-
* and provides helpful error messages with suggestions for resolution.
|
|
478
|
-
* Use this before attempting to create a search engine to get better
|
|
479
|
-
* error messages than the generic file not found errors.
|
|
480
|
-
*
|
|
481
|
-
* @param indexPath - Path to vector index file
|
|
482
|
-
* @param dbPath - Path to database file
|
|
483
|
-
* @throws {Error} If either file doesn't exist, with helpful resolution steps
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* ```typescript
|
|
487
|
-
* // Validate before creating search engine
|
|
488
|
-
* try {
|
|
489
|
-
* TextFactoryHelpers.validateSearchFiles('./index.bin', './db.sqlite');
|
|
490
|
-
* console.log('Files are ready for search');
|
|
491
|
-
* } catch (error) {
|
|
492
|
-
* console.error('Search files not ready:', error.message);
|
|
493
|
-
* // Error message includes suggestions like "Run ingestion first"
|
|
494
|
-
* }
|
|
495
|
-
* ```
|
|
496
|
-
*/
|
|
497
|
-
static validateSearchFiles(indexPath: string, dbPath: string): void;
|
|
498
|
-
/**
|
|
499
|
-
* Get recommended configuration for different use cases
|
|
500
|
-
*
|
|
501
|
-
* This method provides pre-configured options optimized for different
|
|
502
|
-
* performance vs quality trade-offs. Use these as starting points
|
|
503
|
-
* and adjust based on your specific requirements.
|
|
504
|
-
*
|
|
505
|
-
* @param useCase - The intended use case scenario
|
|
506
|
-
* @param useCase.fast - Optimized for speed (no reranking, smaller chunks)
|
|
507
|
-
* @param useCase.balanced - Good balance of speed and quality (default)
|
|
508
|
-
* @param useCase.quality - Optimized for best results (reranking enabled, larger chunks)
|
|
509
|
-
* @returns Recommended configuration for both search and ingestion
|
|
510
|
-
*
|
|
511
|
-
* @example
|
|
512
|
-
* ```typescript
|
|
513
|
-
* // Get configuration for quality-focused use case
|
|
514
|
-
* const { searchOptions, ingestionOptions } = TextFactoryHelpers.getRecommendedConfig('quality');
|
|
515
|
-
*
|
|
516
|
-
* // Create instances with recommended settings
|
|
517
|
-
* const ingestion = await TextIngestionFactory.create('./db.sqlite', './index.bin', ingestionOptions);
|
|
518
|
-
* const search = await TextSearchFactory.create('./index.bin', './db.sqlite', searchOptions);
|
|
519
|
-
*
|
|
520
|
-
* // Or use with RAG factory
|
|
521
|
-
* const { searchEngine, ingestionPipeline } = await TextRAGFactory.createBoth(
|
|
522
|
-
* './index.bin',
|
|
523
|
-
* './db.sqlite',
|
|
524
|
-
* searchOptions,
|
|
525
|
-
* ingestionOptions
|
|
526
|
-
* );
|
|
527
|
-
* ```
|
|
528
|
-
*/
|
|
529
|
-
static getRecommendedConfig(useCase: 'fast' | 'balanced' | 'quality'): {
|
|
530
|
-
searchOptions: TextSearchOptions;
|
|
531
|
-
ingestionOptions: TextIngestionOptions;
|
|
532
|
-
};
|
|
533
|
-
/**
|
|
534
|
-
* Create a search engine with clear error reporting
|
|
535
|
-
*
|
|
536
|
-
* This method creates a search engine with the provided options and fails
|
|
537
|
-
* clearly if there are any issues, providing actionable error messages.
|
|
538
|
-
*
|
|
539
|
-
* @param indexPath - Path to vector index file
|
|
540
|
-
* @param dbPath - Path to database file
|
|
541
|
-
* @param options - Configuration options
|
|
542
|
-
* @returns Promise resolving to SearchEngine
|
|
543
|
-
* @throws {Error} If creation fails with clear error message
|
|
544
|
-
*
|
|
545
|
-
* @example
|
|
546
|
-
* ```typescript
|
|
547
|
-
* // Create search engine with clear error handling
|
|
548
|
-
* const search = await TextFactoryHelpers.createSearchWithValidation(
|
|
549
|
-
* './index.bin',
|
|
550
|
-
* './db.sqlite',
|
|
551
|
-
* { enableReranking: true, topK: 20 }
|
|
552
|
-
* );
|
|
553
|
-
*
|
|
554
|
-
* const results = await search.search('query');
|
|
555
|
-
* console.log(`Search created successfully with ${results.length} results`);
|
|
556
|
-
* ```
|
|
557
|
-
*/
|
|
558
|
-
static createSearchWithValidation(indexPath: string, dbPath: string, options?: TextSearchOptions): Promise<SearchEngine>;
|
|
559
|
-
}
|
|
560
|
-
//# sourceMappingURL=text-factory.d.ts.map
|