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,145 @@
1
+ /**
2
+ * RAG-lite Path Management
3
+ *
4
+ * Manages the standardized .raglite directory structure as specified in the design:
5
+ * .raglite/
6
+ * ├── db.sqlite # Database
7
+ * ├── index.bin # Vector index
8
+ * └── content/ # Content directory
9
+ */
10
+ import { join, resolve, dirname } from 'path';
11
+ import { existsSync, mkdirSync } from 'fs';
12
+ /**
13
+ * Resolves and creates the standardized .raglite directory structure
14
+ *
15
+ * @param config - Configuration for RAG-lite paths
16
+ * @returns Resolved paths for all RAG-lite components
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Use default structure in current directory
21
+ * const paths = resolveRagLitePaths();
22
+ * // Results in:
23
+ * // .raglite/db.sqlite
24
+ * // .raglite/index.bin
25
+ * // .raglite/content/
26
+ *
27
+ * // Use custom base directory
28
+ * const paths = resolveRagLitePaths({ baseDir: './my-project' });
29
+ * // Results in:
30
+ * // my-project/.raglite/db.sqlite
31
+ * // my-project/.raglite/index.bin
32
+ * // my-project/.raglite/content/
33
+ * ```
34
+ */
35
+ export function resolveRagLitePaths(config = {}) {
36
+ const { baseDir = process.cwd(), dbFilename = 'db.sqlite', indexFilename = 'index.bin', contentDirname = 'content' } = config;
37
+ // Resolve base directory to absolute path
38
+ const absoluteBaseDir = resolve(baseDir);
39
+ // Create .raglite directory structure
40
+ const ragliteDir = join(absoluteBaseDir, '.raglite');
41
+ const dbPath = join(ragliteDir, dbFilename);
42
+ const indexPath = join(ragliteDir, indexFilename);
43
+ const contentDir = join(ragliteDir, contentDirname);
44
+ return {
45
+ ragliteDir,
46
+ dbPath,
47
+ indexPath,
48
+ contentDir
49
+ };
50
+ }
51
+ /**
52
+ * Ensures the .raglite directory structure exists
53
+ *
54
+ * @param paths - RAG-lite paths to create
55
+ * @throws {Error} If directory creation fails
56
+ */
57
+ export function ensureRagLiteStructure(paths) {
58
+ try {
59
+ // Create .raglite directory
60
+ if (!existsSync(paths.ragliteDir)) {
61
+ mkdirSync(paths.ragliteDir, { recursive: true });
62
+ }
63
+ // Create content directory
64
+ if (!existsSync(paths.contentDir)) {
65
+ mkdirSync(paths.contentDir, { recursive: true });
66
+ }
67
+ }
68
+ catch (error) {
69
+ throw new Error(`Failed to create .raglite directory structure: ${error instanceof Error ? error.message : String(error)}`);
70
+ }
71
+ }
72
+ /**
73
+ * Migrates from user-specified paths to standardized .raglite structure
74
+ *
75
+ * This function helps transition from the current approach where users specify
76
+ * arbitrary paths to the standardized .raglite structure.
77
+ *
78
+ * @param userDbPath - User-specified database path
79
+ * @param userIndexPath - User-specified index path
80
+ * @param config - Configuration for the target .raglite structure
81
+ * @returns Resolved .raglite paths and migration info
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // Migrate from user paths to .raglite structure
86
+ * const migration = migrateToRagLiteStructure('./my-db.sqlite', './my-index.bin');
87
+ *
88
+ * console.log('Target paths:', migration.paths);
89
+ * console.log('Migration needed:', migration.needsMigration);
90
+ *
91
+ * if (migration.needsMigration) {
92
+ * console.log('Files will be moved from:');
93
+ * console.log(' DB:', migration.sourceDbPath, '->', migration.paths.dbPath);
94
+ * console.log(' Index:', migration.sourceIndexPath, '->', migration.paths.indexPath);
95
+ * }
96
+ * ```
97
+ */
98
+ export function migrateToRagLiteStructure(userDbPath, userIndexPath, config = {}) {
99
+ // Determine base directory from user paths
100
+ const dbDir = dirname(resolve(userDbPath));
101
+ const indexDir = dirname(resolve(userIndexPath));
102
+ // Use the directory containing the database as the base directory
103
+ // This preserves the user's intended project location
104
+ const baseDir = config.baseDir || dbDir;
105
+ // Resolve target .raglite paths
106
+ const paths = resolveRagLitePaths({ ...config, baseDir });
107
+ // Check if migration is needed
108
+ const resolvedUserDbPath = resolve(userDbPath);
109
+ const resolvedUserIndexPath = resolve(userIndexPath);
110
+ const needsMigration = (resolvedUserDbPath !== paths.dbPath ||
111
+ resolvedUserIndexPath !== paths.indexPath);
112
+ return {
113
+ paths,
114
+ needsMigration,
115
+ sourceDbPath: resolvedUserDbPath,
116
+ sourceIndexPath: resolvedUserIndexPath
117
+ };
118
+ }
119
+ /**
120
+ * Gets the standardized .raglite paths for a given project directory
121
+ *
122
+ * This is the recommended way to get RAG-lite paths for new projects.
123
+ *
124
+ * @param projectDir - Project directory (default: current working directory)
125
+ * @returns Standardized RAG-lite paths
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // For current directory
130
+ * const paths = getStandardRagLitePaths();
131
+ *
132
+ * // For specific project
133
+ * const paths = getStandardRagLitePaths('./my-project');
134
+ *
135
+ * // Use with factories
136
+ * const search = await SearchFactory.create(paths.indexPath, paths.dbPath);
137
+ * const ingestion = await IngestionFactory.create(paths.dbPath, paths.indexPath);
138
+ * ```
139
+ */
140
+ export function getStandardRagLitePaths(projectDir = process.cwd()) {
141
+ const paths = resolveRagLitePaths({ baseDir: projectDir });
142
+ ensureRagLiteStructure(paths);
143
+ return paths;
144
+ }
145
+ //# sourceMappingURL=raglite-paths.js.map
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Simple Reranking Configuration System
3
+ *
4
+ * Provides straightforward configuration types and validation for different
5
+ * reranking strategies without complex interface patterns.
6
+ */
7
+ export type RerankingStrategyType = 'cross-encoder' | 'text-derived' | 'metadata' | 'hybrid' | 'disabled';
8
+ export interface RerankingConfig {
9
+ strategy: RerankingStrategyType;
10
+ model?: string;
11
+ enabled: boolean;
12
+ weights?: {
13
+ semantic?: number;
14
+ metadata?: number;
15
+ visual?: number;
16
+ };
17
+ fallback?: RerankingStrategyType;
18
+ }
19
+ export declare const DEFAULT_TEXT_RERANKING_CONFIG: RerankingConfig;
20
+ export declare const DEFAULT_MULTIMODAL_RERANKING_CONFIG: RerankingConfig;
21
+ export declare function validateRerankingStrategy(strategy: string): strategy is RerankingStrategyType;
22
+ export declare function validateRerankingConfig(config: Partial<RerankingConfig>): RerankingConfig;
23
+ export declare function getDefaultRerankingConfig(mode: 'text' | 'multimodal'): RerankingConfig;
24
+ export declare function isStrategySupported(strategy: RerankingStrategyType, mode: 'text' | 'multimodal'): boolean;
25
+ export declare function getSupportedStrategies(mode: 'text' | 'multimodal'): RerankingStrategyType[];
26
+ export declare class RerankingConfigBuilder {
27
+ private config;
28
+ strategy(strategy: RerankingStrategyType): this;
29
+ model(model: string): this;
30
+ enabled(enabled: boolean): this;
31
+ weights(weights: {
32
+ semantic?: number;
33
+ metadata?: number;
34
+ visual?: number;
35
+ }): this;
36
+ fallback(fallback: RerankingStrategyType): this;
37
+ build(): RerankingConfig;
38
+ static textMode(): RerankingConfigBuilder;
39
+ static multimodalMode(): RerankingConfigBuilder;
40
+ static disabled(): RerankingConfigBuilder;
41
+ }
42
+ //# sourceMappingURL=reranking-config.d.ts.map
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Simple Reranking Configuration System
3
+ *
4
+ * Provides straightforward configuration types and validation for different
5
+ * reranking strategies without complex interface patterns.
6
+ */
7
+ // Default configurations for different modes
8
+ export const DEFAULT_TEXT_RERANKING_CONFIG = {
9
+ strategy: 'cross-encoder',
10
+ enabled: true,
11
+ fallback: 'disabled'
12
+ };
13
+ export const DEFAULT_MULTIMODAL_RERANKING_CONFIG = {
14
+ strategy: 'text-derived',
15
+ enabled: true,
16
+ weights: {
17
+ semantic: 0.7,
18
+ metadata: 0.3
19
+ },
20
+ fallback: 'metadata'
21
+ };
22
+ // Strategy validation without complex interface patterns
23
+ export function validateRerankingStrategy(strategy) {
24
+ const validStrategies = [
25
+ 'cross-encoder',
26
+ 'text-derived',
27
+ 'metadata',
28
+ 'hybrid',
29
+ 'disabled'
30
+ ];
31
+ return validStrategies.includes(strategy);
32
+ }
33
+ // Simple strategy validation with clear error messages
34
+ export function validateRerankingConfig(config) {
35
+ if (!config.strategy) {
36
+ throw new Error('Reranking strategy is required');
37
+ }
38
+ if (!validateRerankingStrategy(config.strategy)) {
39
+ const validStrategies = ['cross-encoder', 'text-derived', 'metadata', 'hybrid', 'disabled'];
40
+ throw new Error(`Invalid reranking strategy '${config.strategy}'. ` +
41
+ `Valid strategies: ${validStrategies.join(', ')}`);
42
+ }
43
+ // Validate weights if provided
44
+ if (config.weights) {
45
+ const { semantic, metadata, visual } = config.weights;
46
+ if (semantic !== undefined && (semantic < 0 || semantic > 1)) {
47
+ throw new Error('Semantic weight must be between 0 and 1');
48
+ }
49
+ if (metadata !== undefined && (metadata < 0 || metadata > 1)) {
50
+ throw new Error('Metadata weight must be between 0 and 1');
51
+ }
52
+ if (visual !== undefined && (visual < 0 || visual > 1)) {
53
+ throw new Error('Visual weight must be between 0 and 1');
54
+ }
55
+ // Ensure weights sum to reasonable value for hybrid strategy
56
+ if (config.strategy === 'hybrid') {
57
+ const totalWeight = (semantic || 0) + (metadata || 0) + (visual || 0);
58
+ if (totalWeight === 0) {
59
+ throw new Error('Hybrid strategy requires at least one weight to be greater than 0');
60
+ }
61
+ }
62
+ }
63
+ // Validate fallback strategy if provided
64
+ if (config.fallback && !validateRerankingStrategy(config.fallback)) {
65
+ const validStrategies = ['cross-encoder', 'text-derived', 'metadata', 'hybrid', 'disabled'];
66
+ throw new Error(`Invalid fallback strategy '${config.fallback}'. ` +
67
+ `Valid strategies: ${validStrategies.join(', ')}`);
68
+ }
69
+ return {
70
+ strategy: config.strategy,
71
+ enabled: config.enabled ?? true,
72
+ model: config.model,
73
+ weights: config.weights,
74
+ fallback: config.fallback || 'disabled'
75
+ };
76
+ }
77
+ // Get appropriate default configuration based on mode
78
+ export function getDefaultRerankingConfig(mode) {
79
+ switch (mode) {
80
+ case 'text':
81
+ return { ...DEFAULT_TEXT_RERANKING_CONFIG };
82
+ case 'multimodal':
83
+ return { ...DEFAULT_MULTIMODAL_RERANKING_CONFIG };
84
+ default:
85
+ throw new Error(`Unknown mode: ${mode}`);
86
+ }
87
+ }
88
+ // Check if a strategy is supported for a given mode
89
+ export function isStrategySupported(strategy, mode) {
90
+ switch (mode) {
91
+ case 'text':
92
+ return strategy === 'cross-encoder' || strategy === 'disabled';
93
+ case 'multimodal':
94
+ return ['text-derived', 'metadata', 'hybrid', 'disabled'].includes(strategy);
95
+ default:
96
+ return false;
97
+ }
98
+ }
99
+ // Get supported strategies for a mode
100
+ export function getSupportedStrategies(mode) {
101
+ switch (mode) {
102
+ case 'text':
103
+ return ['cross-encoder', 'disabled'];
104
+ case 'multimodal':
105
+ return ['text-derived', 'metadata', 'hybrid', 'disabled'];
106
+ default:
107
+ return ['disabled'];
108
+ }
109
+ }
110
+ // Simple configuration builder for common scenarios
111
+ export class RerankingConfigBuilder {
112
+ config = {};
113
+ strategy(strategy) {
114
+ this.config.strategy = strategy;
115
+ return this;
116
+ }
117
+ model(model) {
118
+ this.config.model = model;
119
+ return this;
120
+ }
121
+ enabled(enabled) {
122
+ this.config.enabled = enabled;
123
+ return this;
124
+ }
125
+ weights(weights) {
126
+ this.config.weights = weights;
127
+ return this;
128
+ }
129
+ fallback(fallback) {
130
+ this.config.fallback = fallback;
131
+ return this;
132
+ }
133
+ build() {
134
+ return validateRerankingConfig(this.config);
135
+ }
136
+ // Convenience methods for common configurations
137
+ static textMode() {
138
+ return new RerankingConfigBuilder()
139
+ .strategy('cross-encoder')
140
+ .enabled(true)
141
+ .fallback('disabled');
142
+ }
143
+ static multimodalMode() {
144
+ return new RerankingConfigBuilder()
145
+ .strategy('text-derived')
146
+ .enabled(true)
147
+ .weights({ semantic: 0.7, metadata: 0.3 })
148
+ .fallback('metadata');
149
+ }
150
+ static disabled() {
151
+ return new RerankingConfigBuilder()
152
+ .strategy('disabled')
153
+ .enabled(false);
154
+ }
155
+ }
156
+ //# sourceMappingURL=reranking-config.js.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Simple Reranking Creation Function
3
+ *
4
+ * Implements createReranker function with simple conditional logic and automatic
5
+ * fallback mechanism for failed strategy initialization. Follows the design
6
+ * principle of using simple functions over complex factory patterns.
7
+ */
8
+ import type { RerankFunction } from './types.js';
9
+ import type { RerankingStrategyType, RerankingConfig } from './reranking-config.js';
10
+ /**
11
+ * Simple reranking creation function with conditional logic
12
+ *
13
+ * Creates appropriate reranking function based on mode and strategy with
14
+ * automatic fallback mechanism for failed strategy initialization.
15
+ *
16
+ * @param mode - Operating mode ('text' or 'multimodal')
17
+ * @param strategy - Desired reranking strategy
18
+ * @param config - Optional configuration for the strategy
19
+ * @returns RerankFunction or undefined if reranking is disabled
20
+ */
21
+ export declare function createReranker(mode: 'text' | 'multimodal', strategy?: RerankingStrategyType, config?: Partial<RerankingConfig>): RerankFunction | undefined;
22
+ /**
23
+ * Create reranker with automatic mode detection
24
+ *
25
+ * This is a convenience function that automatically detects the appropriate
26
+ * default strategy based on mode and creates the reranker.
27
+ *
28
+ * @param mode - Operating mode ('text' or 'multimodal')
29
+ * @param config - Optional configuration override
30
+ * @returns RerankFunction or undefined if reranking is disabled
31
+ */
32
+ export declare function createDefaultReranker(mode: 'text' | 'multimodal', config?: Partial<RerankingConfig>): RerankFunction | undefined;
33
+ /**
34
+ * Check if reranking is available for a given mode and strategy
35
+ *
36
+ * This function can be used to test if a reranking strategy can be created
37
+ * without actually creating it.
38
+ *
39
+ * @param mode - Operating mode ('text' or 'multimodal')
40
+ * @param strategy - Reranking strategy to test
41
+ * @returns Promise<boolean> indicating if the strategy is available
42
+ */
43
+ export declare function isRerankingAvailable(mode: 'text' | 'multimodal', strategy?: RerankingStrategyType): Promise<boolean>;
44
+ /**
45
+ * Get comprehensive information about available reranking strategies for a mode
46
+ *
47
+ * @param mode - Operating mode ('text' or 'multimodal')
48
+ * @returns Object with strategy information and availability
49
+ */
50
+ export declare function getRerankingInfo(mode: 'text' | 'multimodal'): Promise<{
51
+ mode: "text" | "multimodal";
52
+ defaultStrategy: RerankingStrategyType;
53
+ strategies: {
54
+ strategy: RerankingStrategyType;
55
+ supported: boolean;
56
+ available: boolean;
57
+ isDefault: boolean;
58
+ checkDuration: number;
59
+ error: string | undefined;
60
+ }[];
61
+ hasAvailableStrategies: boolean;
62
+ }>;
63
+ /**
64
+ * Test reranking system health and error recovery
65
+ *
66
+ * @param mode - Operating mode to test
67
+ * @returns Comprehensive health report
68
+ */
69
+ export declare function testRerankingHealth(mode: 'text' | 'multimodal'): Promise<{
70
+ mode: 'text' | 'multimodal';
71
+ overallHealth: 'healthy' | 'degraded' | 'failed';
72
+ defaultStrategyWorking: boolean;
73
+ fallbackSystemWorking: boolean;
74
+ strategyTests: Array<{
75
+ strategy: RerankingStrategyType;
76
+ success: boolean;
77
+ duration: number;
78
+ error?: string;
79
+ }>;
80
+ recommendations: string[];
81
+ }>;
82
+ /**
83
+ * Get reranking system statistics and performance metrics
84
+ */
85
+ export declare function getRerankingStats(): {
86
+ totalCreationAttempts: number;
87
+ successfulCreations: number;
88
+ failedCreations: number;
89
+ fallbacksTriggered: number;
90
+ strategiesUsed: Record<RerankingStrategyType, number>;
91
+ };
92
+ //# sourceMappingURL=reranking-factory.d.ts.map