rag-lite-ts 2.1.1 → 2.3.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.
- package/README.md +88 -5
- package/dist/{cli → cjs/cli}/indexer.js +73 -15
- package/dist/cjs/cli/ui-server.d.ts +5 -0
- package/dist/cjs/cli/ui-server.js +152 -0
- package/dist/{cli.js → cjs/cli.js} +25 -6
- package/dist/{core → cjs/core}/binary-index-format.js +6 -3
- package/dist/{core → cjs/core}/db.d.ts +56 -0
- package/dist/{core → cjs/core}/db.js +105 -0
- package/dist/{core → cjs/core}/ingestion.js +3 -0
- package/dist/cjs/core/knowledge-base-manager.d.ts +109 -0
- package/dist/cjs/core/knowledge-base-manager.js +256 -0
- package/dist/{core → cjs/core}/model-validator.js +1 -1
- package/dist/{core → cjs/core}/search-pipeline.js +1 -1
- package/dist/{core → cjs/core}/search.js +1 -1
- package/dist/cjs/core/vector-index-messages.d.ts +52 -0
- package/dist/cjs/core/vector-index-messages.js +5 -0
- package/dist/cjs/core/vector-index-worker.d.ts +6 -0
- package/dist/cjs/core/vector-index-worker.js +304 -0
- package/dist/cjs/core/vector-index.d.ts +107 -0
- package/dist/cjs/core/vector-index.js +344 -0
- package/dist/{factories → cjs/factories}/ingestion-factory.js +3 -7
- package/dist/{factories → cjs/factories}/search-factory.js +11 -0
- package/dist/{index-manager.d.ts → cjs/index-manager.d.ts} +23 -3
- package/dist/{index-manager.js → cjs/index-manager.js} +84 -15
- package/dist/{index.d.ts → cjs/index.d.ts} +2 -1
- package/dist/{index.js → cjs/index.js} +3 -1
- package/dist/esm/api-errors.d.ts +90 -0
- package/dist/esm/api-errors.js +320 -0
- package/dist/esm/cli/indexer.d.ts +11 -0
- package/dist/esm/cli/indexer.js +529 -0
- package/dist/esm/cli/search.d.ts +7 -0
- package/dist/esm/cli/search.js +332 -0
- package/dist/esm/cli/ui-server.d.ts +5 -0
- package/dist/esm/cli/ui-server.js +152 -0
- package/dist/esm/cli.d.ts +3 -0
- package/dist/esm/cli.js +548 -0
- package/dist/esm/config.d.ts +51 -0
- package/dist/esm/config.js +79 -0
- package/dist/esm/core/abstract-embedder.d.ts +125 -0
- package/dist/esm/core/abstract-embedder.js +264 -0
- package/dist/esm/core/actionable-error-messages.d.ts +60 -0
- package/dist/esm/core/actionable-error-messages.js +397 -0
- package/dist/esm/core/adapters.d.ts +93 -0
- package/dist/esm/core/adapters.js +139 -0
- package/dist/esm/core/batch-processing-optimizer.d.ts +155 -0
- package/dist/esm/core/batch-processing-optimizer.js +536 -0
- package/dist/esm/core/binary-index-format.d.ts +78 -0
- package/dist/esm/core/binary-index-format.js +294 -0
- package/dist/esm/core/chunker.d.ts +119 -0
- package/dist/esm/core/chunker.js +73 -0
- package/dist/esm/core/cli-database-utils.d.ts +53 -0
- package/dist/esm/core/cli-database-utils.js +239 -0
- package/dist/esm/core/config.d.ts +102 -0
- package/dist/esm/core/config.js +247 -0
- package/dist/esm/core/content-errors.d.ts +111 -0
- package/dist/esm/core/content-errors.js +362 -0
- package/dist/esm/core/content-manager.d.ts +335 -0
- package/dist/esm/core/content-manager.js +1476 -0
- package/dist/esm/core/content-performance-optimizer.d.ts +150 -0
- package/dist/esm/core/content-performance-optimizer.js +516 -0
- package/dist/esm/core/content-resolver.d.ts +104 -0
- package/dist/esm/core/content-resolver.js +285 -0
- package/dist/esm/core/cross-modal-search.d.ts +164 -0
- package/dist/esm/core/cross-modal-search.js +342 -0
- package/dist/esm/core/database-connection-manager.d.ts +109 -0
- package/dist/esm/core/database-connection-manager.js +310 -0
- package/dist/esm/core/db.d.ts +269 -0
- package/dist/esm/core/db.js +1000 -0
- package/dist/esm/core/embedder-factory.d.ts +154 -0
- package/dist/esm/core/embedder-factory.js +311 -0
- package/dist/esm/core/error-handler.d.ts +112 -0
- package/dist/esm/core/error-handler.js +239 -0
- package/dist/esm/core/index.d.ts +59 -0
- package/dist/esm/core/index.js +69 -0
- package/dist/esm/core/ingestion.d.ts +202 -0
- package/dist/esm/core/ingestion.js +904 -0
- package/dist/esm/core/interfaces.d.ts +408 -0
- package/dist/esm/core/interfaces.js +106 -0
- package/dist/esm/core/knowledge-base-manager.d.ts +109 -0
- package/dist/esm/core/knowledge-base-manager.js +256 -0
- package/dist/esm/core/lazy-dependency-loader.d.ts +147 -0
- package/dist/esm/core/lazy-dependency-loader.js +435 -0
- package/dist/esm/core/mode-detection-service.d.ts +150 -0
- package/dist/esm/core/mode-detection-service.js +565 -0
- package/dist/esm/core/mode-model-validator.d.ts +92 -0
- package/dist/esm/core/mode-model-validator.js +203 -0
- package/dist/esm/core/model-registry.d.ts +116 -0
- package/dist/esm/core/model-registry.js +411 -0
- package/dist/esm/core/model-validator.d.ts +217 -0
- package/dist/esm/core/model-validator.js +782 -0
- package/dist/esm/core/path-manager.d.ts +47 -0
- package/dist/esm/core/path-manager.js +71 -0
- package/dist/esm/core/raglite-paths.d.ts +121 -0
- package/dist/esm/core/raglite-paths.js +145 -0
- package/dist/esm/core/reranking-config.d.ts +42 -0
- package/dist/esm/core/reranking-config.js +147 -0
- package/dist/esm/core/reranking-factory.d.ts +92 -0
- package/dist/esm/core/reranking-factory.js +410 -0
- package/dist/esm/core/reranking-strategies.d.ts +310 -0
- package/dist/esm/core/reranking-strategies.js +650 -0
- package/dist/esm/core/resource-cleanup.d.ts +163 -0
- package/dist/esm/core/resource-cleanup.js +371 -0
- package/dist/esm/core/resource-manager.d.ts +212 -0
- package/dist/esm/core/resource-manager.js +564 -0
- package/dist/esm/core/search-pipeline.d.ts +111 -0
- package/dist/esm/core/search-pipeline.js +287 -0
- package/dist/esm/core/search.d.ts +141 -0
- package/dist/esm/core/search.js +320 -0
- package/dist/esm/core/streaming-operations.d.ts +145 -0
- package/dist/esm/core/streaming-operations.js +409 -0
- package/dist/esm/core/types.d.ts +66 -0
- package/dist/esm/core/types.js +6 -0
- package/dist/esm/core/universal-embedder.d.ts +177 -0
- package/dist/esm/core/universal-embedder.js +139 -0
- package/dist/esm/core/validation-messages.d.ts +99 -0
- package/dist/esm/core/validation-messages.js +334 -0
- package/dist/esm/core/vector-index-messages.d.ts +52 -0
- package/dist/esm/core/vector-index-messages.js +5 -0
- package/dist/esm/core/vector-index-worker.d.ts +6 -0
- package/dist/esm/core/vector-index-worker.js +304 -0
- package/dist/esm/core/vector-index.d.ts +107 -0
- package/dist/esm/core/vector-index.js +344 -0
- package/dist/esm/dom-polyfills.d.ts +6 -0
- package/dist/esm/dom-polyfills.js +37 -0
- package/dist/esm/factories/index.d.ts +27 -0
- package/dist/esm/factories/index.js +29 -0
- package/dist/esm/factories/ingestion-factory.d.ts +200 -0
- package/dist/esm/factories/ingestion-factory.js +473 -0
- package/dist/esm/factories/search-factory.d.ts +154 -0
- package/dist/esm/factories/search-factory.js +355 -0
- package/dist/esm/file-processor.d.ts +147 -0
- package/dist/esm/file-processor.js +963 -0
- package/dist/esm/index-manager.d.ts +136 -0
- package/dist/esm/index-manager.js +667 -0
- package/dist/esm/index.d.ts +76 -0
- package/dist/esm/index.js +112 -0
- package/dist/esm/indexer.d.ts +7 -0
- package/dist/esm/indexer.js +54 -0
- package/dist/esm/ingestion.d.ts +63 -0
- package/dist/esm/ingestion.js +124 -0
- package/dist/esm/mcp-server.d.ts +46 -0
- package/dist/esm/mcp-server.js +1820 -0
- package/dist/esm/multimodal/clip-embedder.d.ts +327 -0
- package/dist/esm/multimodal/clip-embedder.js +996 -0
- package/dist/esm/multimodal/index.d.ts +6 -0
- package/dist/esm/multimodal/index.js +6 -0
- package/dist/esm/preprocess.d.ts +19 -0
- package/dist/esm/preprocess.js +203 -0
- package/dist/esm/preprocessors/index.d.ts +17 -0
- package/dist/esm/preprocessors/index.js +38 -0
- package/dist/esm/preprocessors/mdx.d.ts +25 -0
- package/dist/esm/preprocessors/mdx.js +101 -0
- package/dist/esm/preprocessors/mermaid.d.ts +68 -0
- package/dist/esm/preprocessors/mermaid.js +329 -0
- package/dist/esm/preprocessors/registry.d.ts +56 -0
- package/dist/esm/preprocessors/registry.js +179 -0
- package/dist/esm/run-error-recovery-tests.d.ts +7 -0
- package/dist/esm/run-error-recovery-tests.js +101 -0
- package/dist/esm/search-standalone.d.ts +7 -0
- package/dist/esm/search-standalone.js +117 -0
- package/dist/esm/search.d.ts +99 -0
- package/dist/esm/search.js +177 -0
- package/dist/esm/test-utils.d.ts +18 -0
- package/dist/esm/test-utils.js +27 -0
- package/dist/esm/text/chunker.d.ts +33 -0
- package/dist/esm/text/chunker.js +279 -0
- package/dist/esm/text/embedder.d.ts +111 -0
- package/dist/esm/text/embedder.js +386 -0
- package/dist/esm/text/index.d.ts +8 -0
- package/dist/esm/text/index.js +9 -0
- package/dist/esm/text/preprocessors/index.d.ts +17 -0
- package/dist/esm/text/preprocessors/index.js +38 -0
- package/dist/esm/text/preprocessors/mdx.d.ts +25 -0
- package/dist/esm/text/preprocessors/mdx.js +101 -0
- package/dist/esm/text/preprocessors/mermaid.d.ts +68 -0
- package/dist/esm/text/preprocessors/mermaid.js +330 -0
- package/dist/esm/text/preprocessors/registry.d.ts +56 -0
- package/dist/esm/text/preprocessors/registry.js +180 -0
- package/dist/esm/text/reranker.d.ts +49 -0
- package/dist/esm/text/reranker.js +274 -0
- package/dist/esm/text/sentence-transformer-embedder.d.ts +96 -0
- package/dist/esm/text/sentence-transformer-embedder.js +340 -0
- package/dist/esm/text/tokenizer.d.ts +22 -0
- package/dist/esm/text/tokenizer.js +64 -0
- package/dist/esm/types.d.ts +83 -0
- package/dist/esm/types.js +3 -0
- package/dist/esm/utils/vector-math.d.ts +31 -0
- package/dist/esm/utils/vector-math.js +70 -0
- package/package.json +39 -14
- package/dist/core/vector-index.d.ts +0 -72
- package/dist/core/vector-index.js +0 -331
- /package/dist/{api-errors.d.ts → cjs/api-errors.d.ts} +0 -0
- /package/dist/{api-errors.js → cjs/api-errors.js} +0 -0
- /package/dist/{cli → cjs/cli}/indexer.d.ts +0 -0
- /package/dist/{cli → cjs/cli}/search.d.ts +0 -0
- /package/dist/{cli → cjs/cli}/search.js +0 -0
- /package/dist/{cli.d.ts → cjs/cli.d.ts} +0 -0
- /package/dist/{config.d.ts → cjs/config.d.ts} +0 -0
- /package/dist/{config.js → cjs/config.js} +0 -0
- /package/dist/{core → cjs/core}/abstract-embedder.d.ts +0 -0
- /package/dist/{core → cjs/core}/abstract-embedder.js +0 -0
- /package/dist/{core → cjs/core}/actionable-error-messages.d.ts +0 -0
- /package/dist/{core → cjs/core}/actionable-error-messages.js +0 -0
- /package/dist/{core → cjs/core}/adapters.d.ts +0 -0
- /package/dist/{core → cjs/core}/adapters.js +0 -0
- /package/dist/{core → cjs/core}/batch-processing-optimizer.d.ts +0 -0
- /package/dist/{core → cjs/core}/batch-processing-optimizer.js +0 -0
- /package/dist/{core → cjs/core}/binary-index-format.d.ts +0 -0
- /package/dist/{core → cjs/core}/chunker.d.ts +0 -0
- /package/dist/{core → cjs/core}/chunker.js +0 -0
- /package/dist/{core → cjs/core}/cli-database-utils.d.ts +0 -0
- /package/dist/{core → cjs/core}/cli-database-utils.js +0 -0
- /package/dist/{core → cjs/core}/config.d.ts +0 -0
- /package/dist/{core → cjs/core}/config.js +0 -0
- /package/dist/{core → cjs/core}/content-errors.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-errors.js +0 -0
- /package/dist/{core → cjs/core}/content-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-manager.js +0 -0
- /package/dist/{core → cjs/core}/content-performance-optimizer.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-performance-optimizer.js +0 -0
- /package/dist/{core → cjs/core}/content-resolver.d.ts +0 -0
- /package/dist/{core → cjs/core}/content-resolver.js +0 -0
- /package/dist/{core → cjs/core}/cross-modal-search.d.ts +0 -0
- /package/dist/{core → cjs/core}/cross-modal-search.js +0 -0
- /package/dist/{core → cjs/core}/database-connection-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/database-connection-manager.js +0 -0
- /package/dist/{core → cjs/core}/embedder-factory.d.ts +0 -0
- /package/dist/{core → cjs/core}/embedder-factory.js +0 -0
- /package/dist/{core → cjs/core}/error-handler.d.ts +0 -0
- /package/dist/{core → cjs/core}/error-handler.js +0 -0
- /package/dist/{core → cjs/core}/index.d.ts +0 -0
- /package/dist/{core → cjs/core}/index.js +0 -0
- /package/dist/{core → cjs/core}/ingestion.d.ts +0 -0
- /package/dist/{core → cjs/core}/interfaces.d.ts +0 -0
- /package/dist/{core → cjs/core}/interfaces.js +0 -0
- /package/dist/{core → cjs/core}/lazy-dependency-loader.d.ts +0 -0
- /package/dist/{core → cjs/core}/lazy-dependency-loader.js +0 -0
- /package/dist/{core → cjs/core}/mode-detection-service.d.ts +0 -0
- /package/dist/{core → cjs/core}/mode-detection-service.js +0 -0
- /package/dist/{core → cjs/core}/mode-model-validator.d.ts +0 -0
- /package/dist/{core → cjs/core}/mode-model-validator.js +0 -0
- /package/dist/{core → cjs/core}/model-registry.d.ts +0 -0
- /package/dist/{core → cjs/core}/model-registry.js +0 -0
- /package/dist/{core → cjs/core}/model-validator.d.ts +0 -0
- /package/dist/{core → cjs/core}/path-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/path-manager.js +0 -0
- /package/dist/{core → cjs/core}/raglite-paths.d.ts +0 -0
- /package/dist/{core → cjs/core}/raglite-paths.js +0 -0
- /package/dist/{core → cjs/core}/reranking-config.d.ts +0 -0
- /package/dist/{core → cjs/core}/reranking-config.js +0 -0
- /package/dist/{core → cjs/core}/reranking-factory.d.ts +0 -0
- /package/dist/{core → cjs/core}/reranking-factory.js +0 -0
- /package/dist/{core → cjs/core}/reranking-strategies.d.ts +0 -0
- /package/dist/{core → cjs/core}/reranking-strategies.js +0 -0
- /package/dist/{core → cjs/core}/resource-cleanup.d.ts +0 -0
- /package/dist/{core → cjs/core}/resource-cleanup.js +0 -0
- /package/dist/{core → cjs/core}/resource-manager.d.ts +0 -0
- /package/dist/{core → cjs/core}/resource-manager.js +0 -0
- /package/dist/{core → cjs/core}/search-pipeline.d.ts +0 -0
- /package/dist/{core → cjs/core}/search.d.ts +0 -0
- /package/dist/{core → cjs/core}/streaming-operations.d.ts +0 -0
- /package/dist/{core → cjs/core}/streaming-operations.js +0 -0
- /package/dist/{core → cjs/core}/types.d.ts +0 -0
- /package/dist/{core → cjs/core}/types.js +0 -0
- /package/dist/{core → cjs/core}/universal-embedder.d.ts +0 -0
- /package/dist/{core → cjs/core}/universal-embedder.js +0 -0
- /package/dist/{core → cjs/core}/validation-messages.d.ts +0 -0
- /package/dist/{core → cjs/core}/validation-messages.js +0 -0
- /package/dist/{dom-polyfills.d.ts → cjs/dom-polyfills.d.ts} +0 -0
- /package/dist/{dom-polyfills.js → cjs/dom-polyfills.js} +0 -0
- /package/dist/{factories → cjs/factories}/index.d.ts +0 -0
- /package/dist/{factories → cjs/factories}/index.js +0 -0
- /package/dist/{factories → cjs/factories}/ingestion-factory.d.ts +0 -0
- /package/dist/{factories → cjs/factories}/search-factory.d.ts +0 -0
- /package/dist/{file-processor.d.ts → cjs/file-processor.d.ts} +0 -0
- /package/dist/{file-processor.js → cjs/file-processor.js} +0 -0
- /package/dist/{indexer.d.ts → cjs/indexer.d.ts} +0 -0
- /package/dist/{indexer.js → cjs/indexer.js} +0 -0
- /package/dist/{ingestion.d.ts → cjs/ingestion.d.ts} +0 -0
- /package/dist/{ingestion.js → cjs/ingestion.js} +0 -0
- /package/dist/{mcp-server.d.ts → cjs/mcp-server.d.ts} +0 -0
- /package/dist/{mcp-server.js → cjs/mcp-server.js} +0 -0
- /package/dist/{multimodal → cjs/multimodal}/clip-embedder.d.ts +0 -0
- /package/dist/{multimodal → cjs/multimodal}/clip-embedder.js +0 -0
- /package/dist/{multimodal → cjs/multimodal}/index.d.ts +0 -0
- /package/dist/{multimodal → cjs/multimodal}/index.js +0 -0
- /package/dist/{preprocess.d.ts → cjs/preprocess.d.ts} +0 -0
- /package/dist/{preprocess.js → cjs/preprocess.js} +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/index.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/index.js +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mdx.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mdx.js +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mermaid.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/mermaid.js +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/registry.d.ts +0 -0
- /package/dist/{preprocessors → cjs/preprocessors}/registry.js +0 -0
- /package/dist/{run-error-recovery-tests.d.ts → cjs/run-error-recovery-tests.d.ts} +0 -0
- /package/dist/{run-error-recovery-tests.js → cjs/run-error-recovery-tests.js} +0 -0
- /package/dist/{search-standalone.d.ts → cjs/search-standalone.d.ts} +0 -0
- /package/dist/{search-standalone.js → cjs/search-standalone.js} +0 -0
- /package/dist/{search.d.ts → cjs/search.d.ts} +0 -0
- /package/dist/{search.js → cjs/search.js} +0 -0
- /package/dist/{test-utils.d.ts → cjs/test-utils.d.ts} +0 -0
- /package/dist/{test-utils.js → cjs/test-utils.js} +0 -0
- /package/dist/{text → cjs/text}/chunker.d.ts +0 -0
- /package/dist/{text → cjs/text}/chunker.js +0 -0
- /package/dist/{text → cjs/text}/embedder.d.ts +0 -0
- /package/dist/{text → cjs/text}/embedder.js +0 -0
- /package/dist/{text → cjs/text}/index.d.ts +0 -0
- /package/dist/{text → cjs/text}/index.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/index.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/index.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mdx.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mdx.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mermaid.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/mermaid.js +0 -0
- /package/dist/{text → cjs/text}/preprocessors/registry.d.ts +0 -0
- /package/dist/{text → cjs/text}/preprocessors/registry.js +0 -0
- /package/dist/{text → cjs/text}/reranker.d.ts +0 -0
- /package/dist/{text → cjs/text}/reranker.js +0 -0
- /package/dist/{text → cjs/text}/sentence-transformer-embedder.d.ts +0 -0
- /package/dist/{text → cjs/text}/sentence-transformer-embedder.js +0 -0
- /package/dist/{text → cjs/text}/tokenizer.d.ts +0 -0
- /package/dist/{text → cjs/text}/tokenizer.js +0 -0
- /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/dist/{types.js → cjs/types.js} +0 -0
- /package/dist/{utils → cjs/utils}/vector-math.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/vector-math.js +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORE MODULE — Shared between text-only (rag-lite-ts) and future multimodal (rag-lite-mm)
|
|
3
|
+
* Model-agnostic. No transformer or modality-specific logic.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Manages document path storage and resolution strategies
|
|
7
|
+
* Model-agnostic - works with any content type (text, image, etc.)
|
|
8
|
+
*/
|
|
9
|
+
export declare class DocumentPathManager {
|
|
10
|
+
private strategy;
|
|
11
|
+
private basePath;
|
|
12
|
+
constructor(strategy: 'absolute' | 'relative', basePath: string);
|
|
13
|
+
/**
|
|
14
|
+
* Convert absolute file path to storage path based on strategy
|
|
15
|
+
* @param absolutePath - The absolute file path
|
|
16
|
+
* @returns Path to store in database
|
|
17
|
+
*/
|
|
18
|
+
toStoragePath(absolutePath: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Convert storage path back to absolute path for file operations
|
|
21
|
+
* @param storagePath - Path stored in database
|
|
22
|
+
* @returns Absolute path for file operations
|
|
23
|
+
*/
|
|
24
|
+
toAbsolutePath(storagePath: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get the current strategy
|
|
27
|
+
*/
|
|
28
|
+
getStrategy(): 'absolute' | 'relative';
|
|
29
|
+
/**
|
|
30
|
+
* Get the current base path
|
|
31
|
+
*/
|
|
32
|
+
getBasePath(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new path manager with different base path (for search/retrieval)
|
|
35
|
+
* @param newBasePath - New base path to use
|
|
36
|
+
* @returns New DocumentPathManager instance
|
|
37
|
+
*/
|
|
38
|
+
withBasePath(newBasePath: string): DocumentPathManager;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new path manager with different strategy
|
|
41
|
+
* @param newStrategy - New strategy to use
|
|
42
|
+
* @param newBasePath - Optional new base path
|
|
43
|
+
* @returns New DocumentPathManager instance
|
|
44
|
+
*/
|
|
45
|
+
withStrategy(newStrategy: 'absolute' | 'relative', newBasePath?: string): DocumentPathManager;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=path-manager.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORE MODULE — Shared between text-only (rag-lite-ts) and future multimodal (rag-lite-mm)
|
|
3
|
+
* Model-agnostic. No transformer or modality-specific logic.
|
|
4
|
+
*/
|
|
5
|
+
import { relative, resolve, isAbsolute } from 'path';
|
|
6
|
+
/**
|
|
7
|
+
* Manages document path storage and resolution strategies
|
|
8
|
+
* Model-agnostic - works with any content type (text, image, etc.)
|
|
9
|
+
*/
|
|
10
|
+
export class DocumentPathManager {
|
|
11
|
+
strategy;
|
|
12
|
+
basePath;
|
|
13
|
+
constructor(strategy, basePath) {
|
|
14
|
+
this.strategy = strategy;
|
|
15
|
+
this.basePath = basePath;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert absolute file path to storage path based on strategy
|
|
19
|
+
* @param absolutePath - The absolute file path
|
|
20
|
+
* @returns Path to store in database
|
|
21
|
+
*/
|
|
22
|
+
toStoragePath(absolutePath) {
|
|
23
|
+
if (this.strategy === 'absolute') {
|
|
24
|
+
return absolutePath;
|
|
25
|
+
}
|
|
26
|
+
// For relative strategy, store path relative to base
|
|
27
|
+
return relative(this.basePath, absolutePath);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Convert storage path back to absolute path for file operations
|
|
31
|
+
* @param storagePath - Path stored in database
|
|
32
|
+
* @returns Absolute path for file operations
|
|
33
|
+
*/
|
|
34
|
+
toAbsolutePath(storagePath) {
|
|
35
|
+
if (isAbsolute(storagePath)) {
|
|
36
|
+
return storagePath;
|
|
37
|
+
}
|
|
38
|
+
// Resolve relative path against base path
|
|
39
|
+
return resolve(this.basePath, storagePath);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the current strategy
|
|
43
|
+
*/
|
|
44
|
+
getStrategy() {
|
|
45
|
+
return this.strategy;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the current base path
|
|
49
|
+
*/
|
|
50
|
+
getBasePath() {
|
|
51
|
+
return this.basePath;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a new path manager with different base path (for search/retrieval)
|
|
55
|
+
* @param newBasePath - New base path to use
|
|
56
|
+
* @returns New DocumentPathManager instance
|
|
57
|
+
*/
|
|
58
|
+
withBasePath(newBasePath) {
|
|
59
|
+
return new DocumentPathManager(this.strategy, newBasePath);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a new path manager with different strategy
|
|
63
|
+
* @param newStrategy - New strategy to use
|
|
64
|
+
* @param newBasePath - Optional new base path
|
|
65
|
+
* @returns New DocumentPathManager instance
|
|
66
|
+
*/
|
|
67
|
+
withStrategy(newStrategy, newBasePath) {
|
|
68
|
+
return new DocumentPathManager(newStrategy, newBasePath || this.basePath);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=path-manager.js.map
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* RAG-lite directory structure configuration
|
|
12
|
+
*/
|
|
13
|
+
export interface RagLiteConfig {
|
|
14
|
+
/** Base directory for RAG-lite files (default: current working directory) */
|
|
15
|
+
baseDir?: string;
|
|
16
|
+
/** Custom database filename (default: 'db.sqlite') */
|
|
17
|
+
dbFilename?: string;
|
|
18
|
+
/** Custom index filename (default: 'index.bin') */
|
|
19
|
+
indexFilename?: string;
|
|
20
|
+
/** Custom content directory name (default: 'content') */
|
|
21
|
+
contentDirname?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolved RAG-lite paths
|
|
25
|
+
*/
|
|
26
|
+
export interface RagLitePaths {
|
|
27
|
+
/** Base .raglite directory */
|
|
28
|
+
ragliteDir: string;
|
|
29
|
+
/** Database file path */
|
|
30
|
+
dbPath: string;
|
|
31
|
+
/** Vector index file path */
|
|
32
|
+
indexPath: string;
|
|
33
|
+
/** Content directory path */
|
|
34
|
+
contentDir: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves and creates the standardized .raglite directory structure
|
|
38
|
+
*
|
|
39
|
+
* @param config - Configuration for RAG-lite paths
|
|
40
|
+
* @returns Resolved paths for all RAG-lite components
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Use default structure in current directory
|
|
45
|
+
* const paths = resolveRagLitePaths();
|
|
46
|
+
* // Results in:
|
|
47
|
+
* // .raglite/db.sqlite
|
|
48
|
+
* // .raglite/index.bin
|
|
49
|
+
* // .raglite/content/
|
|
50
|
+
*
|
|
51
|
+
* // Use custom base directory
|
|
52
|
+
* const paths = resolveRagLitePaths({ baseDir: './my-project' });
|
|
53
|
+
* // Results in:
|
|
54
|
+
* // my-project/.raglite/db.sqlite
|
|
55
|
+
* // my-project/.raglite/index.bin
|
|
56
|
+
* // my-project/.raglite/content/
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveRagLitePaths(config?: RagLiteConfig): RagLitePaths;
|
|
60
|
+
/**
|
|
61
|
+
* Ensures the .raglite directory structure exists
|
|
62
|
+
*
|
|
63
|
+
* @param paths - RAG-lite paths to create
|
|
64
|
+
* @throws {Error} If directory creation fails
|
|
65
|
+
*/
|
|
66
|
+
export declare function ensureRagLiteStructure(paths: RagLitePaths): void;
|
|
67
|
+
/**
|
|
68
|
+
* Migrates from user-specified paths to standardized .raglite structure
|
|
69
|
+
*
|
|
70
|
+
* This function helps transition from the current approach where users specify
|
|
71
|
+
* arbitrary paths to the standardized .raglite structure.
|
|
72
|
+
*
|
|
73
|
+
* @param userDbPath - User-specified database path
|
|
74
|
+
* @param userIndexPath - User-specified index path
|
|
75
|
+
* @param config - Configuration for the target .raglite structure
|
|
76
|
+
* @returns Resolved .raglite paths and migration info
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Migrate from user paths to .raglite structure
|
|
81
|
+
* const migration = migrateToRagLiteStructure('./my-db.sqlite', './my-index.bin');
|
|
82
|
+
*
|
|
83
|
+
* console.log('Target paths:', migration.paths);
|
|
84
|
+
* console.log('Migration needed:', migration.needsMigration);
|
|
85
|
+
*
|
|
86
|
+
* if (migration.needsMigration) {
|
|
87
|
+
* console.log('Files will be moved from:');
|
|
88
|
+
* console.log(' DB:', migration.sourceDbPath, '->', migration.paths.dbPath);
|
|
89
|
+
* console.log(' Index:', migration.sourceIndexPath, '->', migration.paths.indexPath);
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function migrateToRagLiteStructure(userDbPath: string, userIndexPath: string, config?: RagLiteConfig): {
|
|
94
|
+
paths: RagLitePaths;
|
|
95
|
+
needsMigration: boolean;
|
|
96
|
+
sourceDbPath: string;
|
|
97
|
+
sourceIndexPath: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Gets the standardized .raglite paths for a given project directory
|
|
101
|
+
*
|
|
102
|
+
* This is the recommended way to get RAG-lite paths for new projects.
|
|
103
|
+
*
|
|
104
|
+
* @param projectDir - Project directory (default: current working directory)
|
|
105
|
+
* @returns Standardized RAG-lite paths
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // For current directory
|
|
110
|
+
* const paths = getStandardRagLitePaths();
|
|
111
|
+
*
|
|
112
|
+
* // For specific project
|
|
113
|
+
* const paths = getStandardRagLitePaths('./my-project');
|
|
114
|
+
*
|
|
115
|
+
* // Use with factories
|
|
116
|
+
* const search = await SearchFactory.create(paths.indexPath, paths.dbPath);
|
|
117
|
+
* const ingestion = await IngestionFactory.create(paths.dbPath, paths.indexPath);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function getStandardRagLitePaths(projectDir?: string): RagLitePaths;
|
|
121
|
+
//# sourceMappingURL=raglite-paths.d.ts.map
|
|
@@ -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' | '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,147 @@
|
|
|
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: 'disabled'
|
|
21
|
+
};
|
|
22
|
+
// Strategy validation without complex interface patterns
|
|
23
|
+
export function validateRerankingStrategy(strategy) {
|
|
24
|
+
const validStrategies = [
|
|
25
|
+
'cross-encoder',
|
|
26
|
+
'text-derived',
|
|
27
|
+
'disabled'
|
|
28
|
+
];
|
|
29
|
+
return validStrategies.includes(strategy);
|
|
30
|
+
}
|
|
31
|
+
// Simple strategy validation with clear error messages
|
|
32
|
+
export function validateRerankingConfig(config) {
|
|
33
|
+
if (!config.strategy) {
|
|
34
|
+
throw new Error('Reranking strategy is required');
|
|
35
|
+
}
|
|
36
|
+
if (!validateRerankingStrategy(config.strategy)) {
|
|
37
|
+
const validStrategies = ['cross-encoder', 'text-derived', 'disabled'];
|
|
38
|
+
throw new Error(`Invalid reranking strategy '${config.strategy}'. ` +
|
|
39
|
+
`Valid strategies: ${validStrategies.join(', ')}`);
|
|
40
|
+
}
|
|
41
|
+
// Validate weights if provided
|
|
42
|
+
if (config.weights) {
|
|
43
|
+
const { semantic, metadata, visual } = config.weights;
|
|
44
|
+
if (semantic !== undefined && (semantic < 0 || semantic > 1)) {
|
|
45
|
+
throw new Error('Semantic weight must be between 0 and 1');
|
|
46
|
+
}
|
|
47
|
+
if (metadata !== undefined && (metadata < 0 || metadata > 1)) {
|
|
48
|
+
throw new Error('Metadata weight must be between 0 and 1');
|
|
49
|
+
}
|
|
50
|
+
if (visual !== undefined && (visual < 0 || visual > 1)) {
|
|
51
|
+
throw new Error('Visual weight must be between 0 and 1');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Validate fallback strategy if provided
|
|
55
|
+
if (config.fallback && !validateRerankingStrategy(config.fallback)) {
|
|
56
|
+
const validStrategies = ['cross-encoder', 'text-derived', 'disabled'];
|
|
57
|
+
throw new Error(`Invalid fallback strategy '${config.fallback}'. ` +
|
|
58
|
+
`Valid strategies: ${validStrategies.join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
strategy: config.strategy,
|
|
62
|
+
enabled: config.strategy === 'disabled' ? false : (config.enabled ?? true),
|
|
63
|
+
model: config.model,
|
|
64
|
+
weights: config.weights,
|
|
65
|
+
fallback: config.fallback || 'disabled'
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// Get appropriate default configuration based on mode
|
|
69
|
+
export function getDefaultRerankingConfig(mode) {
|
|
70
|
+
switch (mode) {
|
|
71
|
+
case 'text':
|
|
72
|
+
return { ...DEFAULT_TEXT_RERANKING_CONFIG };
|
|
73
|
+
case 'multimodal':
|
|
74
|
+
return { ...DEFAULT_MULTIMODAL_RERANKING_CONFIG };
|
|
75
|
+
default:
|
|
76
|
+
throw new Error(`Unknown mode: ${mode}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Check if a strategy is supported for a given mode
|
|
80
|
+
export function isStrategySupported(strategy, mode) {
|
|
81
|
+
switch (mode) {
|
|
82
|
+
case 'text':
|
|
83
|
+
return strategy === 'cross-encoder' || strategy === 'disabled';
|
|
84
|
+
case 'multimodal':
|
|
85
|
+
return ['text-derived', 'disabled'].includes(strategy);
|
|
86
|
+
default:
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Get supported strategies for a mode
|
|
91
|
+
export function getSupportedStrategies(mode) {
|
|
92
|
+
switch (mode) {
|
|
93
|
+
case 'text':
|
|
94
|
+
return ['cross-encoder', 'disabled'];
|
|
95
|
+
case 'multimodal':
|
|
96
|
+
return ['text-derived', 'disabled'];
|
|
97
|
+
default:
|
|
98
|
+
return ['disabled'];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Simple configuration builder for common scenarios
|
|
102
|
+
export class RerankingConfigBuilder {
|
|
103
|
+
config = {};
|
|
104
|
+
strategy(strategy) {
|
|
105
|
+
this.config.strategy = strategy;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
model(model) {
|
|
109
|
+
this.config.model = model;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
enabled(enabled) {
|
|
113
|
+
this.config.enabled = enabled;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
weights(weights) {
|
|
117
|
+
this.config.weights = weights;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
fallback(fallback) {
|
|
121
|
+
this.config.fallback = fallback;
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
build() {
|
|
125
|
+
return validateRerankingConfig(this.config);
|
|
126
|
+
}
|
|
127
|
+
// Convenience methods for common configurations
|
|
128
|
+
static textMode() {
|
|
129
|
+
return new RerankingConfigBuilder()
|
|
130
|
+
.strategy('cross-encoder')
|
|
131
|
+
.enabled(true)
|
|
132
|
+
.fallback('disabled');
|
|
133
|
+
}
|
|
134
|
+
static multimodalMode() {
|
|
135
|
+
return new RerankingConfigBuilder()
|
|
136
|
+
.strategy('text-derived')
|
|
137
|
+
.enabled(true)
|
|
138
|
+
.weights({ semantic: 0.7, metadata: 0.3 })
|
|
139
|
+
.fallback('disabled');
|
|
140
|
+
}
|
|
141
|
+
static disabled() {
|
|
142
|
+
return new RerankingConfigBuilder()
|
|
143
|
+
.strategy('disabled')
|
|
144
|
+
.enabled(false);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# 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
|