rag-lite-ts 2.1.0 → 2.2.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/dist/{cli → cjs/cli}/indexer.js +1 -1
- package/dist/{cli → cjs/cli}/search.js +5 -10
- package/dist/{core → cjs/core}/binary-index-format.d.ts +28 -2
- package/dist/cjs/core/binary-index-format.js +291 -0
- package/dist/{core → cjs/core}/ingestion.d.ts +5 -1
- package/dist/{core → cjs/core}/ingestion.js +76 -9
- package/dist/{core → cjs/core}/model-validator.js +1 -1
- package/dist/{core → cjs/core}/reranking-strategies.js +4 -5
- package/dist/{core → cjs/core}/search.js +2 -1
- package/dist/{core → cjs/core}/types.d.ts +1 -1
- package/dist/{core → cjs/core}/vector-index.d.ts +4 -0
- package/dist/{core → cjs/core}/vector-index.js +10 -2
- package/dist/{file-processor.d.ts → cjs/file-processor.d.ts} +2 -0
- package/dist/{file-processor.js → cjs/file-processor.js} +20 -0
- package/dist/{index-manager.d.ts → cjs/index-manager.d.ts} +17 -1
- package/dist/{index-manager.js → cjs/index-manager.js} +148 -7
- package/dist/{multimodal → cjs/multimodal}/clip-embedder.js +71 -66
- 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 +471 -0
- package/dist/esm/cli/search.d.ts +7 -0
- package/dist/esm/cli/search.js +332 -0
- package/dist/esm/cli.d.ts +3 -0
- package/dist/esm/cli.js +529 -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 +291 -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 +213 -0
- package/dist/esm/core/db.js +895 -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 +901 -0
- package/dist/esm/core/interfaces.d.ts +408 -0
- package/dist/esm/core/interfaces.js +106 -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.d.ts +72 -0
- package/dist/esm/core/vector-index.js +333 -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 +477 -0
- package/dist/esm/factories/search-factory.d.ts +154 -0
- package/dist/esm/factories/search-factory.js +344 -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 +116 -0
- package/dist/esm/index-manager.js +598 -0
- package/dist/esm/index.d.ts +75 -0
- package/dist/esm/index.js +110 -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 +30 -12
- package/dist/core/binary-index-format.js +0 -122
- /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.d.ts → cjs/cli.d.ts} +0 -0
- /package/dist/{cli.js → cjs/cli.js} +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}/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}/db.d.ts +0 -0
- /package/dist/{core → cjs/core}/db.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}/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}/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-pipeline.js +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.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}/ingestion-factory.js +0 -0
- /package/dist/{factories → cjs/factories}/search-factory.d.ts +0 -0
- /package/dist/{factories → cjs/factories}/search-factory.js +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.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}/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,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORE MODULE — Simple Embedder Creation Function
|
|
3
|
+
*
|
|
4
|
+
* Provides direct model instantiation with clear validation and error handling.
|
|
5
|
+
* No fallback mechanisms - models work reliably or fail clearly with actionable guidance.
|
|
6
|
+
*
|
|
7
|
+
* Supported Models:
|
|
8
|
+
* - Text Mode: sentence-transformers/all-MiniLM-L6-v2, Xenova/all-mpnet-base-v2
|
|
9
|
+
* - Multimodal Mode: Xenova/clip-vit-base-patch32, Xenova/clip-vit-base-patch16
|
|
10
|
+
*
|
|
11
|
+
* Mode Selection Guide:
|
|
12
|
+
* - Use text mode for text-only content (faster, optimized for text similarity)
|
|
13
|
+
* - Use multimodal mode for mixed text/image content (enables cross-modal search)
|
|
14
|
+
*/
|
|
15
|
+
import '../dom-polyfills.js';
|
|
16
|
+
import type { UniversalEmbedder, ModelType, EmbedderCreationOptions } from './universal-embedder.js';
|
|
17
|
+
/**
|
|
18
|
+
* Create a universal embedder for the specified model
|
|
19
|
+
*
|
|
20
|
+
* Simple function-based approach that validates model compatibility and creates
|
|
21
|
+
* the appropriate embedder. Models work reliably without fallback mechanisms -
|
|
22
|
+
* if there's an issue, you'll get clear error messages with actionable guidance.
|
|
23
|
+
*
|
|
24
|
+
* Mode Selection:
|
|
25
|
+
* - Text Mode: Use sentence-transformer models for text-only content
|
|
26
|
+
* - Fast, optimized for text similarity
|
|
27
|
+
* - Best for: document search, semantic similarity, text clustering
|
|
28
|
+
*
|
|
29
|
+
* - Multimodal Mode: Use CLIP models for mixed text/image content
|
|
30
|
+
* - Unified embedding space for text and images
|
|
31
|
+
* - Enables cross-modal search (text queries find images, image queries find text)
|
|
32
|
+
* - Best for: image search, visual question answering, multimodal retrieval
|
|
33
|
+
*
|
|
34
|
+
* @param modelName - Name of the model to create
|
|
35
|
+
* @param options - Optional configuration options
|
|
36
|
+
* @returns Promise resolving to a UniversalEmbedder instance
|
|
37
|
+
* @throws {Error} If model is not supported or validation fails
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Text mode - optimized for text-only content
|
|
42
|
+
* const textEmbedder = await createEmbedder('sentence-transformers/all-MiniLM-L6-v2');
|
|
43
|
+
* const textResult = await textEmbedder.embedText('machine learning');
|
|
44
|
+
*
|
|
45
|
+
* // Multimodal mode - enables cross-modal search
|
|
46
|
+
* const clipEmbedder = await createEmbedder('Xenova/clip-vit-base-patch32');
|
|
47
|
+
* const textResult = await clipEmbedder.embedText('red sports car');
|
|
48
|
+
* const imageResult = await clipEmbedder.embedImage('./car.jpg');
|
|
49
|
+
*
|
|
50
|
+
* // Create with custom options
|
|
51
|
+
* const embedder = await createEmbedder('sentence-transformers/all-MiniLM-L6-v2', {
|
|
52
|
+
* maxBatchSize: 16,
|
|
53
|
+
* cachePath: './models'
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function createEmbedder(modelName: string, options?: EmbedderCreationOptions): Promise<UniversalEmbedder>;
|
|
58
|
+
/**
|
|
59
|
+
* Get supported models for a specific content type
|
|
60
|
+
* Convenience function for filtering models by capability
|
|
61
|
+
*
|
|
62
|
+
* @param contentType - Content type to filter by ('text', 'image', etc.)
|
|
63
|
+
* @returns Array of model names that support the content type
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const textModels = getSupportedModelsForContentType('text');
|
|
68
|
+
* const imageModels = getSupportedModelsForContentType('image');
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function getSupportedModelsForContentType(contentType: string): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Get recommended model for a specific use case
|
|
74
|
+
*
|
|
75
|
+
* Provides intelligent model selection based on content types and constraints.
|
|
76
|
+
* Returns models that work reliably for the specified requirements.
|
|
77
|
+
*
|
|
78
|
+
* Mode Selection Guide:
|
|
79
|
+
* - Text only (['text']): Returns sentence-transformer models
|
|
80
|
+
* - Fast, optimized for text similarity
|
|
81
|
+
* - Best for document search and text clustering
|
|
82
|
+
*
|
|
83
|
+
* - Text + Images (['text', 'image']): Returns CLIP models
|
|
84
|
+
* - Unified embedding space for cross-modal search
|
|
85
|
+
* - Text queries can find images, image queries can find text
|
|
86
|
+
* - Best for visual search and multimodal retrieval
|
|
87
|
+
*
|
|
88
|
+
* @param contentTypes - Required content types
|
|
89
|
+
* @param constraints - Optional constraints (memory, performance, etc.)
|
|
90
|
+
* @param constraints.maxMemory - Maximum memory in MB
|
|
91
|
+
* @param constraints.preferPerformance - Prefer faster models
|
|
92
|
+
* @param constraints.preferAccuracy - Prefer more accurate models
|
|
93
|
+
* @returns Recommended model name or null if no suitable model found
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // Get best text model (fast, optimized for text)
|
|
98
|
+
* const textModel = getRecommendedModel(['text']);
|
|
99
|
+
* // Returns: 'sentence-transformers/all-MiniLM-L6-v2'
|
|
100
|
+
*
|
|
101
|
+
* // Get best multimodal model (enables cross-modal search)
|
|
102
|
+
* const multimodalModel = getRecommendedModel(['text', 'image']);
|
|
103
|
+
* // Returns: 'Xenova/clip-vit-base-patch32'
|
|
104
|
+
*
|
|
105
|
+
* // Get performance-optimized model
|
|
106
|
+
* const fastModel = getRecommendedModel(['text'], { preferPerformance: true });
|
|
107
|
+
*
|
|
108
|
+
* // Get accuracy-optimized model
|
|
109
|
+
* const accurateModel = getRecommendedModel(['text'], { preferAccuracy: true });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function getRecommendedModel(contentTypes: string[], constraints?: {
|
|
113
|
+
maxMemory?: number;
|
|
114
|
+
preferPerformance?: boolean;
|
|
115
|
+
preferAccuracy?: boolean;
|
|
116
|
+
}): string | null;
|
|
117
|
+
/**
|
|
118
|
+
* Validate model compatibility before creation
|
|
119
|
+
* Useful for checking compatibility without creating the embedder
|
|
120
|
+
*
|
|
121
|
+
* @param modelName - Name of the model to validate
|
|
122
|
+
* @returns Promise resolving to validation result
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const isValid = await validateModelCompatibility('sentence-transformers/all-MiniLM-L6-v2');
|
|
127
|
+
* if (isValid) {
|
|
128
|
+
* const embedder = await createEmbedder('sentence-transformers/all-MiniLM-L6-v2');
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function validateModelCompatibility(modelName: string): Promise<boolean>;
|
|
133
|
+
/**
|
|
134
|
+
* List all available models with their capabilities
|
|
135
|
+
* Useful for displaying model options to users
|
|
136
|
+
*
|
|
137
|
+
* @returns Array of model information objects
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const models = listAvailableModels();
|
|
142
|
+
* models.forEach(model => {
|
|
143
|
+
* console.log(`${model.name}: ${model.supportedContentTypes.join(', ')}`);
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function listAvailableModels(): Array<{
|
|
148
|
+
name: string;
|
|
149
|
+
type: ModelType;
|
|
150
|
+
dimensions: number;
|
|
151
|
+
supportedContentTypes: readonly string[];
|
|
152
|
+
memoryRequirement: number | undefined;
|
|
153
|
+
}>;
|
|
154
|
+
//# sourceMappingURL=embedder-factory.d.ts.map
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORE MODULE — Simple Embedder Creation Function
|
|
3
|
+
*
|
|
4
|
+
* Provides direct model instantiation with clear validation and error handling.
|
|
5
|
+
* No fallback mechanisms - models work reliably or fail clearly with actionable guidance.
|
|
6
|
+
*
|
|
7
|
+
* Supported Models:
|
|
8
|
+
* - Text Mode: sentence-transformers/all-MiniLM-L6-v2, Xenova/all-mpnet-base-v2
|
|
9
|
+
* - Multimodal Mode: Xenova/clip-vit-base-patch32, Xenova/clip-vit-base-patch16
|
|
10
|
+
*
|
|
11
|
+
* Mode Selection Guide:
|
|
12
|
+
* - Use text mode for text-only content (faster, optimized for text similarity)
|
|
13
|
+
* - Use multimodal mode for mixed text/image content (enables cross-modal search)
|
|
14
|
+
*/
|
|
15
|
+
// Ensure DOM polyfills are set up before any transformers.js usage
|
|
16
|
+
import '../dom-polyfills.js';
|
|
17
|
+
import { ModelRegistry } from './model-registry.js';
|
|
18
|
+
import { ModelValidator } from './model-validator.js';
|
|
19
|
+
import { createModelValidationError } from './model-validator.js';
|
|
20
|
+
import { createValidationErrorMessage } from './validation-messages.js';
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// SIMPLE EMBEDDER CREATION FUNCTION
|
|
23
|
+
// =============================================================================
|
|
24
|
+
/**
|
|
25
|
+
* Create a universal embedder for the specified model
|
|
26
|
+
*
|
|
27
|
+
* Simple function-based approach that validates model compatibility and creates
|
|
28
|
+
* the appropriate embedder. Models work reliably without fallback mechanisms -
|
|
29
|
+
* if there's an issue, you'll get clear error messages with actionable guidance.
|
|
30
|
+
*
|
|
31
|
+
* Mode Selection:
|
|
32
|
+
* - Text Mode: Use sentence-transformer models for text-only content
|
|
33
|
+
* - Fast, optimized for text similarity
|
|
34
|
+
* - Best for: document search, semantic similarity, text clustering
|
|
35
|
+
*
|
|
36
|
+
* - Multimodal Mode: Use CLIP models for mixed text/image content
|
|
37
|
+
* - Unified embedding space for text and images
|
|
38
|
+
* - Enables cross-modal search (text queries find images, image queries find text)
|
|
39
|
+
* - Best for: image search, visual question answering, multimodal retrieval
|
|
40
|
+
*
|
|
41
|
+
* @param modelName - Name of the model to create
|
|
42
|
+
* @param options - Optional configuration options
|
|
43
|
+
* @returns Promise resolving to a UniversalEmbedder instance
|
|
44
|
+
* @throws {Error} If model is not supported or validation fails
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Text mode - optimized for text-only content
|
|
49
|
+
* const textEmbedder = await createEmbedder('sentence-transformers/all-MiniLM-L6-v2');
|
|
50
|
+
* const textResult = await textEmbedder.embedText('machine learning');
|
|
51
|
+
*
|
|
52
|
+
* // Multimodal mode - enables cross-modal search
|
|
53
|
+
* const clipEmbedder = await createEmbedder('Xenova/clip-vit-base-patch32');
|
|
54
|
+
* const textResult = await clipEmbedder.embedText('red sports car');
|
|
55
|
+
* const imageResult = await clipEmbedder.embedImage('./car.jpg');
|
|
56
|
+
*
|
|
57
|
+
* // Create with custom options
|
|
58
|
+
* const embedder = await createEmbedder('sentence-transformers/all-MiniLM-L6-v2', {
|
|
59
|
+
* maxBatchSize: 16,
|
|
60
|
+
* cachePath: './models'
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export async function createEmbedder(modelName, options = {}) {
|
|
65
|
+
// Step 0: Ensure polyfills are set up before any transformers.js usage
|
|
66
|
+
if (typeof globalThis.self === 'undefined') {
|
|
67
|
+
globalThis.self = globalThis;
|
|
68
|
+
}
|
|
69
|
+
if (typeof global.self === 'undefined') {
|
|
70
|
+
global.self = global;
|
|
71
|
+
}
|
|
72
|
+
// Step 1: Initialize model validator if not already done
|
|
73
|
+
if (!ModelValidator.getTransformersVersion()) {
|
|
74
|
+
await ModelValidator.detectTransformersVersion();
|
|
75
|
+
}
|
|
76
|
+
// Step 1: Validate the model
|
|
77
|
+
const modelInfo = ModelRegistry.getModelInfo(modelName);
|
|
78
|
+
if (!modelInfo) {
|
|
79
|
+
const errorMessage = createValidationErrorMessage(modelName, 'not_found', {
|
|
80
|
+
suggestions: ModelRegistry.getSupportedModels()
|
|
81
|
+
});
|
|
82
|
+
console.error(errorMessage);
|
|
83
|
+
throw createModelValidationError(modelName, 'Model not found in supported models registry');
|
|
84
|
+
}
|
|
85
|
+
// Step 2: Perform detailed validation
|
|
86
|
+
try {
|
|
87
|
+
const detailedValidation = await ModelValidator.validateModelDetailed(modelName);
|
|
88
|
+
if (!detailedValidation.isValid) {
|
|
89
|
+
const firstError = detailedValidation.errors[0] || 'Validation failed';
|
|
90
|
+
const errorMessage = createValidationErrorMessage(modelName, 'version_incompatible', {
|
|
91
|
+
required: modelInfo.requirements.transformersJsVersion,
|
|
92
|
+
current: ModelValidator.getTransformersVersion() || 'unknown'
|
|
93
|
+
});
|
|
94
|
+
console.error(errorMessage);
|
|
95
|
+
throw createModelValidationError(modelName, firstError);
|
|
96
|
+
}
|
|
97
|
+
// Log warnings if any
|
|
98
|
+
if (detailedValidation.warnings.length > 0) {
|
|
99
|
+
console.warn(`⚠️ Warnings for model '${modelName}':`);
|
|
100
|
+
detailedValidation.warnings.forEach(warning => console.warn(` • ${warning}`));
|
|
101
|
+
}
|
|
102
|
+
// Log suggestions if any
|
|
103
|
+
if (detailedValidation.suggestions.length > 0) {
|
|
104
|
+
console.info(`💡 Suggestions for model '${modelName}':`);
|
|
105
|
+
detailedValidation.suggestions.forEach(suggestion => console.info(` • ${suggestion}`));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
// Re-throw validation errors
|
|
110
|
+
if (error instanceof Error && error.name === 'ModelValidationError') {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
// Handle unexpected validation errors
|
|
114
|
+
console.warn(`Warning: Could not perform detailed validation for '${modelName}': ${error}`);
|
|
115
|
+
console.info('Proceeding with basic validation only...');
|
|
116
|
+
}
|
|
117
|
+
// Step 3: Create the appropriate embedder based on model type
|
|
118
|
+
const modelType = modelInfo.type;
|
|
119
|
+
switch (modelType) {
|
|
120
|
+
case 'sentence-transformer':
|
|
121
|
+
return await createSentenceTransformerEmbedder(modelName, options);
|
|
122
|
+
case 'clip':
|
|
123
|
+
return await createCLIPEmbedder(modelName, options);
|
|
124
|
+
default:
|
|
125
|
+
const errorMessage = createValidationErrorMessage(modelName, 'not_found', {
|
|
126
|
+
suggestions: [`Unsupported model type: ${modelType}`]
|
|
127
|
+
});
|
|
128
|
+
console.error(errorMessage);
|
|
129
|
+
throw createModelValidationError(modelName, `Unsupported model type: ${modelType}. Supported types: sentence-transformer, clip`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// =============================================================================
|
|
133
|
+
// MODEL-SPECIFIC CREATION FUNCTIONS
|
|
134
|
+
// =============================================================================
|
|
135
|
+
/**
|
|
136
|
+
* Create a sentence transformer embedder using lazy loading
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
async function createSentenceTransformerEmbedder(modelName, options) {
|
|
140
|
+
// Use lazy loading to avoid loading text dependencies unless needed
|
|
141
|
+
const { LazyEmbedderLoader } = await import('./lazy-dependency-loader.js');
|
|
142
|
+
return LazyEmbedderLoader.loadSentenceTransformerEmbedder(modelName, options);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a CLIP embedder using lazy loading
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
async function createCLIPEmbedder(modelName, options) {
|
|
149
|
+
// Use lazy loading to avoid loading multimodal dependencies unless needed
|
|
150
|
+
const { LazyEmbedderLoader } = await import('./lazy-dependency-loader.js');
|
|
151
|
+
return LazyEmbedderLoader.loadCLIPEmbedder(modelName, options);
|
|
152
|
+
}
|
|
153
|
+
// =============================================================================
|
|
154
|
+
// UTILITY FUNCTIONS
|
|
155
|
+
// =============================================================================
|
|
156
|
+
/**
|
|
157
|
+
* Get supported models for a specific content type
|
|
158
|
+
* Convenience function for filtering models by capability
|
|
159
|
+
*
|
|
160
|
+
* @param contentType - Content type to filter by ('text', 'image', etc.)
|
|
161
|
+
* @returns Array of model names that support the content type
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const textModels = getSupportedModelsForContentType('text');
|
|
166
|
+
* const imageModels = getSupportedModelsForContentType('image');
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export function getSupportedModelsForContentType(contentType) {
|
|
170
|
+
return ModelRegistry.getModelsByContentType(contentType);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get recommended model for a specific use case
|
|
174
|
+
*
|
|
175
|
+
* Provides intelligent model selection based on content types and constraints.
|
|
176
|
+
* Returns models that work reliably for the specified requirements.
|
|
177
|
+
*
|
|
178
|
+
* Mode Selection Guide:
|
|
179
|
+
* - Text only (['text']): Returns sentence-transformer models
|
|
180
|
+
* - Fast, optimized for text similarity
|
|
181
|
+
* - Best for document search and text clustering
|
|
182
|
+
*
|
|
183
|
+
* - Text + Images (['text', 'image']): Returns CLIP models
|
|
184
|
+
* - Unified embedding space for cross-modal search
|
|
185
|
+
* - Text queries can find images, image queries can find text
|
|
186
|
+
* - Best for visual search and multimodal retrieval
|
|
187
|
+
*
|
|
188
|
+
* @param contentTypes - Required content types
|
|
189
|
+
* @param constraints - Optional constraints (memory, performance, etc.)
|
|
190
|
+
* @param constraints.maxMemory - Maximum memory in MB
|
|
191
|
+
* @param constraints.preferPerformance - Prefer faster models
|
|
192
|
+
* @param constraints.preferAccuracy - Prefer more accurate models
|
|
193
|
+
* @returns Recommended model name or null if no suitable model found
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // Get best text model (fast, optimized for text)
|
|
198
|
+
* const textModel = getRecommendedModel(['text']);
|
|
199
|
+
* // Returns: 'sentence-transformers/all-MiniLM-L6-v2'
|
|
200
|
+
*
|
|
201
|
+
* // Get best multimodal model (enables cross-modal search)
|
|
202
|
+
* const multimodalModel = getRecommendedModel(['text', 'image']);
|
|
203
|
+
* // Returns: 'Xenova/clip-vit-base-patch32'
|
|
204
|
+
*
|
|
205
|
+
* // Get performance-optimized model
|
|
206
|
+
* const fastModel = getRecommendedModel(['text'], { preferPerformance: true });
|
|
207
|
+
*
|
|
208
|
+
* // Get accuracy-optimized model
|
|
209
|
+
* const accurateModel = getRecommendedModel(['text'], { preferAccuracy: true });
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export function getRecommendedModel(contentTypes, constraints = {}) {
|
|
213
|
+
const transformersVersion = ModelValidator.getTransformersVersion();
|
|
214
|
+
const compatibleModels = ModelValidator.getRecommendedModels(contentTypes, constraints.maxMemory, transformersVersion || undefined);
|
|
215
|
+
if (compatibleModels.length === 0) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
// Apply preference-based sorting
|
|
219
|
+
if (constraints.preferPerformance) {
|
|
220
|
+
// Prefer smaller, faster models
|
|
221
|
+
const performanceOrder = [
|
|
222
|
+
'sentence-transformers/all-MiniLM-L6-v2',
|
|
223
|
+
'Xenova/clip-vit-base-patch32',
|
|
224
|
+
'Xenova/all-mpnet-base-v2',
|
|
225
|
+
'Xenova/clip-vit-base-patch16'
|
|
226
|
+
];
|
|
227
|
+
for (const preferred of performanceOrder) {
|
|
228
|
+
if (compatibleModels.includes(preferred)) {
|
|
229
|
+
return preferred;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (constraints.preferAccuracy) {
|
|
234
|
+
// Prefer larger, more accurate models
|
|
235
|
+
const accuracyOrder = [
|
|
236
|
+
'Xenova/all-mpnet-base-v2',
|
|
237
|
+
'Xenova/clip-vit-base-patch16',
|
|
238
|
+
'sentence-transformers/all-MiniLM-L6-v2',
|
|
239
|
+
'Xenova/clip-vit-base-patch32'
|
|
240
|
+
];
|
|
241
|
+
for (const preferred of accuracyOrder) {
|
|
242
|
+
if (compatibleModels.includes(preferred)) {
|
|
243
|
+
return preferred;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Default: return first compatible model
|
|
248
|
+
return compatibleModels[0];
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Validate model compatibility before creation
|
|
252
|
+
* Useful for checking compatibility without creating the embedder
|
|
253
|
+
*
|
|
254
|
+
* @param modelName - Name of the model to validate
|
|
255
|
+
* @returns Promise resolving to validation result
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const isValid = await validateModelCompatibility('sentence-transformers/all-MiniLM-L6-v2');
|
|
260
|
+
* if (isValid) {
|
|
261
|
+
* const embedder = await createEmbedder('sentence-transformers/all-MiniLM-L6-v2');
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
export async function validateModelCompatibility(modelName) {
|
|
266
|
+
try {
|
|
267
|
+
const validation = await ModelValidator.validateModelDetailed(modelName);
|
|
268
|
+
return validation.isValid;
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
console.warn(`Validation failed for '${modelName}': ${error}`);
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* List all available models with their capabilities
|
|
277
|
+
* Useful for displaying model options to users
|
|
278
|
+
*
|
|
279
|
+
* @returns Array of model information objects
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* const models = listAvailableModels();
|
|
284
|
+
* models.forEach(model => {
|
|
285
|
+
* console.log(`${model.name}: ${model.supportedContentTypes.join(', ')}`);
|
|
286
|
+
* });
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
export function listAvailableModels() {
|
|
290
|
+
return ModelRegistry.getSupportedModels().map(modelName => {
|
|
291
|
+
const info = ModelRegistry.getModelInfo(modelName);
|
|
292
|
+
return {
|
|
293
|
+
name: info.name,
|
|
294
|
+
type: info.type,
|
|
295
|
+
dimensions: info.dimensions,
|
|
296
|
+
supportedContentTypes: info.supportedContentTypes,
|
|
297
|
+
memoryRequirement: info.requirements.minimumMemory
|
|
298
|
+
};
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
// =============================================================================
|
|
302
|
+
// BACKWARD COMPATIBILITY - REMOVED
|
|
303
|
+
// =============================================================================
|
|
304
|
+
// The UniversalEmbedderFactory object has been removed as it was only a thin
|
|
305
|
+
// wrapper around the new API with deprecation warnings. Use the following instead:
|
|
306
|
+
//
|
|
307
|
+
// - UniversalEmbedderFactory.create() → createEmbedder()
|
|
308
|
+
// - UniversalEmbedderFactory.validateModel() → ModelRegistry.validateModel()
|
|
309
|
+
// - UniversalEmbedderFactory.getModelInfo() → ModelRegistry.getModelInfo()
|
|
310
|
+
// - UniversalEmbedderFactory.getSupportedModels() → ModelRegistry.getSupportedModels()
|
|
311
|
+
//# sourceMappingURL=embedder-factory.js.map
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
* Error categories for different types of failures
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ErrorCategory {
|
|
9
|
+
CONFIGURATION = "Configuration",
|
|
10
|
+
DATABASE = "Database",
|
|
11
|
+
MODEL = "Model",
|
|
12
|
+
INDEX = "Index",
|
|
13
|
+
FILE_SYSTEM = "File System",
|
|
14
|
+
EMBEDDING = "Embedding",
|
|
15
|
+
NETWORK = "Network",
|
|
16
|
+
VALIDATION = "Validation",
|
|
17
|
+
GENERAL = "General"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error severity levels
|
|
21
|
+
*/
|
|
22
|
+
export declare enum ErrorSeverity {
|
|
23
|
+
FATAL = "FATAL",// System must exit immediately
|
|
24
|
+
ERROR = "ERROR",// Operation failed but system can continue
|
|
25
|
+
WARNING = "WARNING",// Potential issue but operation can continue
|
|
26
|
+
INFO = "INFO"
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Interface for providing implementation-specific error context
|
|
30
|
+
* Allows dependency injection of model-specific error messages and suggestions
|
|
31
|
+
*/
|
|
32
|
+
export interface ErrorContext {
|
|
33
|
+
getErrorMessage(error: Error, context: string): string;
|
|
34
|
+
getSuggestions(error: Error, context: string): string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Enhanced error class with category and severity
|
|
38
|
+
*/
|
|
39
|
+
export declare class CategorizedError extends Error {
|
|
40
|
+
category: ErrorCategory;
|
|
41
|
+
severity: ErrorSeverity;
|
|
42
|
+
exitCode: number;
|
|
43
|
+
originalError?: Error | undefined;
|
|
44
|
+
constructor(message: string, category: ErrorCategory, severity?: ErrorSeverity, exitCode?: number, originalError?: Error | undefined);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Set the global error context for dependency injection
|
|
48
|
+
* @param errorContext - Implementation-specific error context
|
|
49
|
+
*/
|
|
50
|
+
export declare function setErrorContext(errorContext: ErrorContext): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get the current error context
|
|
53
|
+
* @returns Current error context
|
|
54
|
+
*/
|
|
55
|
+
export declare function getErrorContext(): ErrorContext;
|
|
56
|
+
/**
|
|
57
|
+
* Handle errors with appropriate logging and exit behavior
|
|
58
|
+
* Supports dependency injection of implementation-specific error contexts
|
|
59
|
+
* @param error - Error to handle
|
|
60
|
+
* @param context - Context where error occurred
|
|
61
|
+
* @param options - Handling options
|
|
62
|
+
*/
|
|
63
|
+
export declare function handleError(error: Error | string, context: string, options?: {
|
|
64
|
+
category?: ErrorCategory;
|
|
65
|
+
severity?: ErrorSeverity;
|
|
66
|
+
exitCode?: number;
|
|
67
|
+
skipError?: boolean;
|
|
68
|
+
showStack?: boolean;
|
|
69
|
+
errorContext?: ErrorContext;
|
|
70
|
+
}): void;
|
|
71
|
+
/**
|
|
72
|
+
* Wrapper for try-catch blocks with consistent error handling
|
|
73
|
+
* @param operation - Function to execute
|
|
74
|
+
* @param context - Context description
|
|
75
|
+
* @param options - Error handling options
|
|
76
|
+
*/
|
|
77
|
+
export declare function safeExecute<T>(operation: () => Promise<T> | T, context: string, options?: {
|
|
78
|
+
category?: ErrorCategory;
|
|
79
|
+
severity?: ErrorSeverity;
|
|
80
|
+
exitCode?: number;
|
|
81
|
+
skipError?: boolean;
|
|
82
|
+
fallbackValue?: T;
|
|
83
|
+
errorContext?: ErrorContext;
|
|
84
|
+
}): Promise<T | undefined>;
|
|
85
|
+
/**
|
|
86
|
+
* Validate that a condition is true, throw categorized error if not
|
|
87
|
+
* @param condition - Condition to check
|
|
88
|
+
* @param message - Error message if condition fails
|
|
89
|
+
* @param category - Error category
|
|
90
|
+
* @param exitCode - Exit code for fatal errors
|
|
91
|
+
*/
|
|
92
|
+
export declare function assert(condition: boolean, message: string, category?: ErrorCategory, exitCode?: number): asserts condition;
|
|
93
|
+
/**
|
|
94
|
+
* Log progress with error context
|
|
95
|
+
* @param message - Progress message
|
|
96
|
+
* @param current - Current progress value
|
|
97
|
+
* @param total - Total progress value
|
|
98
|
+
*/
|
|
99
|
+
export declare function logProgress(message: string, current?: number, total?: number): void;
|
|
100
|
+
/**
|
|
101
|
+
* Create a categorized error for common scenarios
|
|
102
|
+
*/
|
|
103
|
+
export declare const createError: {
|
|
104
|
+
configuration: (message: string, exitCode?: 3) => CategorizedError;
|
|
105
|
+
database: (message: string, exitCode?: 5) => CategorizedError;
|
|
106
|
+
model: (message: string, exitCode?: 6) => CategorizedError;
|
|
107
|
+
index: (message: string, exitCode?: 7) => CategorizedError;
|
|
108
|
+
fileSystem: (message: string, exitCode?: 4) => CategorizedError;
|
|
109
|
+
embedding: (message: string, severity?: ErrorSeverity) => CategorizedError;
|
|
110
|
+
validation: (message: string, exitCode?: 2) => CategorizedError;
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=error-handler.d.ts.map
|