@juspay/neurolink 9.1.1 → 9.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/CHANGELOG.md +27 -0
- package/README.md +106 -37
- package/dist/agent/directTools.d.ts +11 -11
- package/dist/cli/commands/config.d.ts +6 -6
- package/dist/cli/commands/rag.d.ts +19 -0
- package/dist/cli/commands/rag.js +756 -0
- package/dist/cli/factories/commandFactory.js +146 -83
- package/dist/cli/parser.js +4 -1
- package/dist/core/baseProvider.d.ts +43 -30
- package/dist/core/baseProvider.js +98 -138
- package/dist/core/conversationMemoryFactory.d.ts +2 -2
- package/dist/core/conversationMemoryFactory.js +2 -2
- package/dist/core/conversationMemoryInitializer.d.ts +1 -2
- package/dist/core/conversationMemoryInitializer.js +2 -2
- package/dist/core/infrastructure/baseError.d.ts +21 -0
- package/dist/core/infrastructure/baseError.js +22 -0
- package/dist/core/infrastructure/baseFactory.d.ts +21 -0
- package/dist/core/infrastructure/baseFactory.js +54 -0
- package/dist/core/infrastructure/baseRegistry.d.ts +21 -0
- package/dist/core/infrastructure/baseRegistry.js +49 -0
- package/dist/core/infrastructure/index.d.ts +5 -0
- package/dist/core/infrastructure/index.js +5 -0
- package/dist/core/infrastructure/retry.d.ts +7 -0
- package/dist/core/infrastructure/retry.js +20 -0
- package/dist/core/infrastructure/typedEventEmitter.d.ts +8 -0
- package/dist/core/infrastructure/typedEventEmitter.js +23 -0
- package/dist/core/redisConversationMemoryManager.d.ts +1 -6
- package/dist/core/redisConversationMemoryManager.js +7 -19
- package/dist/factories/providerFactory.d.ts +5 -3
- package/dist/factories/providerFactory.js +31 -24
- package/dist/image-gen/ImageGenService.d.ts +143 -0
- package/dist/image-gen/ImageGenService.js +345 -0
- package/dist/image-gen/imageGenTools.d.ts +126 -0
- package/dist/image-gen/imageGenTools.js +304 -0
- package/dist/image-gen/index.d.ts +46 -0
- package/dist/image-gen/index.js +48 -0
- package/dist/image-gen/types.d.ts +237 -0
- package/dist/image-gen/types.js +24 -0
- package/dist/index.d.ts +46 -12
- package/dist/index.js +88 -36
- package/dist/lib/agent/directTools.d.ts +8 -8
- package/dist/lib/core/baseProvider.d.ts +43 -30
- package/dist/lib/core/baseProvider.js +98 -138
- package/dist/lib/core/conversationMemoryFactory.d.ts +2 -2
- package/dist/lib/core/conversationMemoryFactory.js +2 -2
- package/dist/lib/core/conversationMemoryInitializer.d.ts +1 -2
- package/dist/lib/core/conversationMemoryInitializer.js +2 -2
- package/dist/lib/core/infrastructure/baseError.d.ts +21 -0
- package/dist/lib/core/infrastructure/baseError.js +23 -0
- package/dist/lib/core/infrastructure/baseFactory.d.ts +21 -0
- package/dist/lib/core/infrastructure/baseFactory.js +55 -0
- package/dist/lib/core/infrastructure/baseRegistry.d.ts +21 -0
- package/dist/lib/core/infrastructure/baseRegistry.js +50 -0
- package/dist/lib/core/infrastructure/index.d.ts +5 -0
- package/dist/lib/core/infrastructure/index.js +6 -0
- package/dist/lib/core/infrastructure/retry.d.ts +7 -0
- package/dist/lib/core/infrastructure/retry.js +21 -0
- package/dist/lib/core/infrastructure/typedEventEmitter.d.ts +8 -0
- package/dist/lib/core/infrastructure/typedEventEmitter.js +24 -0
- package/dist/lib/core/redisConversationMemoryManager.d.ts +1 -6
- package/dist/lib/core/redisConversationMemoryManager.js +7 -19
- package/dist/lib/factories/providerFactory.d.ts +5 -3
- package/dist/lib/factories/providerFactory.js +31 -24
- package/dist/lib/image-gen/ImageGenService.d.ts +143 -0
- package/dist/lib/image-gen/ImageGenService.js +346 -0
- package/dist/lib/image-gen/imageGenTools.d.ts +126 -0
- package/dist/lib/image-gen/imageGenTools.js +305 -0
- package/dist/lib/image-gen/index.d.ts +46 -0
- package/dist/lib/image-gen/index.js +49 -0
- package/dist/lib/image-gen/types.d.ts +237 -0
- package/dist/lib/image-gen/types.js +25 -0
- package/dist/lib/index.d.ts +46 -12
- package/dist/lib/index.js +88 -36
- package/dist/lib/mcp/index.d.ts +6 -5
- package/dist/lib/mcp/index.js +7 -5
- package/dist/lib/neurolink.d.ts +11 -13
- package/dist/lib/neurolink.js +95 -29
- package/dist/lib/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/lib/processors/base/BaseFileProcessor.js +614 -0
- package/dist/lib/processors/base/index.d.ts +14 -0
- package/dist/lib/processors/base/index.js +20 -0
- package/dist/lib/processors/base/types.d.ts +593 -0
- package/dist/lib/processors/base/types.js +77 -0
- package/dist/lib/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/lib/processors/cli/fileProcessorCli.js +389 -0
- package/dist/lib/processors/cli/index.d.ts +37 -0
- package/dist/lib/processors/cli/index.js +50 -0
- package/dist/lib/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/lib/processors/code/ConfigProcessor.js +401 -0
- package/dist/lib/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/lib/processors/code/SourceCodeProcessor.js +305 -0
- package/dist/lib/processors/code/index.d.ts +44 -0
- package/dist/lib/processors/code/index.js +61 -0
- package/dist/lib/processors/config/fileTypes.d.ts +283 -0
- package/dist/lib/processors/config/fileTypes.js +521 -0
- package/dist/lib/processors/config/index.d.ts +32 -0
- package/dist/lib/processors/config/index.js +93 -0
- package/dist/lib/processors/config/languageMap.d.ts +66 -0
- package/dist/lib/processors/config/languageMap.js +411 -0
- package/dist/lib/processors/config/mimeTypes.d.ts +376 -0
- package/dist/lib/processors/config/mimeTypes.js +339 -0
- package/dist/lib/processors/config/sizeLimits.d.ts +194 -0
- package/dist/lib/processors/config/sizeLimits.js +247 -0
- package/dist/lib/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/lib/processors/data/JsonProcessor.js +204 -0
- package/dist/lib/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/lib/processors/data/XmlProcessor.js +284 -0
- package/dist/lib/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/lib/processors/data/YamlProcessor.js +295 -0
- package/dist/lib/processors/data/index.d.ts +49 -0
- package/dist/lib/processors/data/index.js +77 -0
- package/dist/lib/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/lib/processors/document/ExcelProcessor.js +520 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/lib/processors/document/OpenDocumentProcessor.js +211 -0
- package/dist/lib/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/lib/processors/document/RtfProcessor.js +362 -0
- package/dist/lib/processors/document/WordProcessor.d.ts +168 -0
- package/dist/lib/processors/document/WordProcessor.js +354 -0
- package/dist/lib/processors/document/index.d.ts +54 -0
- package/dist/lib/processors/document/index.js +91 -0
- package/dist/lib/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/lib/processors/errors/FileErrorCode.js +256 -0
- package/dist/lib/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/lib/processors/errors/errorHelpers.js +379 -0
- package/dist/lib/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/lib/processors/errors/errorSerializer.js +508 -0
- package/dist/lib/processors/errors/index.d.ts +46 -0
- package/dist/lib/processors/errors/index.js +50 -0
- package/dist/lib/processors/index.d.ts +76 -0
- package/dist/lib/processors/index.js +113 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/lib/processors/integration/FileProcessorIntegration.js +273 -0
- package/dist/lib/processors/integration/index.d.ts +42 -0
- package/dist/lib/processors/integration/index.js +45 -0
- package/dist/lib/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/lib/processors/markup/HtmlProcessor.js +250 -0
- package/dist/lib/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/lib/processors/markup/MarkdownProcessor.js +245 -0
- package/dist/lib/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/lib/processors/markup/SvgProcessor.js +241 -0
- package/dist/lib/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/lib/processors/markup/TextProcessor.js +189 -0
- package/dist/lib/processors/markup/index.d.ts +66 -0
- package/dist/lib/processors/markup/index.js +103 -0
- package/dist/lib/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/lib/processors/registry/ProcessorRegistry.js +609 -0
- package/dist/lib/processors/registry/index.d.ts +12 -0
- package/dist/lib/processors/registry/index.js +17 -0
- package/dist/lib/processors/registry/types.d.ts +53 -0
- package/dist/lib/processors/registry/types.js +11 -0
- package/dist/lib/providers/amazonBedrock.d.ts +15 -2
- package/dist/lib/providers/amazonBedrock.js +65 -8
- package/dist/lib/providers/anthropic.d.ts +3 -3
- package/dist/lib/providers/anthropic.js +10 -7
- package/dist/lib/providers/googleAiStudio.d.ts +5 -5
- package/dist/lib/providers/googleAiStudio.js +10 -7
- package/dist/lib/providers/googleVertex.d.ts +16 -4
- package/dist/lib/providers/googleVertex.js +72 -16
- package/dist/lib/providers/litellm.d.ts +3 -3
- package/dist/lib/providers/litellm.js +10 -10
- package/dist/lib/providers/mistral.d.ts +3 -3
- package/dist/lib/providers/mistral.js +7 -6
- package/dist/lib/providers/ollama.d.ts +3 -4
- package/dist/lib/providers/ollama.js +7 -8
- package/dist/lib/providers/openAI.d.ts +14 -2
- package/dist/lib/providers/openAI.js +60 -6
- package/dist/lib/providers/openRouter.d.ts +2 -2
- package/dist/lib/providers/openRouter.js +10 -6
- package/dist/lib/providers/sagemaker/language-model.d.ts +2 -2
- package/dist/lib/rag/ChunkerFactory.d.ts +91 -0
- package/dist/lib/rag/ChunkerFactory.js +321 -0
- package/dist/lib/rag/ChunkerRegistry.d.ts +91 -0
- package/dist/lib/rag/ChunkerRegistry.js +422 -0
- package/dist/lib/rag/chunkers/BaseChunker.d.ts +53 -0
- package/dist/lib/rag/chunkers/BaseChunker.js +144 -0
- package/dist/lib/rag/chunkers/CharacterChunker.d.ts +18 -0
- package/dist/lib/rag/chunkers/CharacterChunker.js +29 -0
- package/dist/lib/rag/chunkers/HTMLChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/HTMLChunker.js +39 -0
- package/dist/lib/rag/chunkers/JSONChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/JSONChunker.js +69 -0
- package/dist/lib/rag/chunkers/LaTeXChunker.d.ts +15 -0
- package/dist/lib/rag/chunkers/LaTeXChunker.js +64 -0
- package/dist/lib/rag/chunkers/MarkdownChunker.d.ts +15 -0
- package/dist/lib/rag/chunkers/MarkdownChunker.js +103 -0
- package/dist/lib/rag/chunkers/RecursiveChunker.d.ts +27 -0
- package/dist/lib/rag/chunkers/RecursiveChunker.js +140 -0
- package/dist/lib/rag/chunkers/SemanticMarkdownChunker.d.ts +22 -0
- package/dist/lib/rag/chunkers/SemanticMarkdownChunker.js +139 -0
- package/dist/lib/rag/chunkers/SentenceChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/SentenceChunker.js +67 -0
- package/dist/lib/rag/chunkers/TokenChunker.d.ts +19 -0
- package/dist/lib/rag/chunkers/TokenChunker.js +62 -0
- package/dist/lib/rag/chunkers/index.d.ts +15 -0
- package/dist/lib/rag/chunkers/index.js +16 -0
- package/dist/lib/rag/chunking/characterChunker.d.ts +16 -0
- package/dist/lib/rag/chunking/characterChunker.js +143 -0
- package/dist/lib/rag/chunking/chunkerRegistry.d.ts +67 -0
- package/dist/lib/rag/chunking/chunkerRegistry.js +195 -0
- package/dist/lib/rag/chunking/htmlChunker.d.ts +34 -0
- package/dist/lib/rag/chunking/htmlChunker.js +248 -0
- package/dist/lib/rag/chunking/index.d.ts +15 -0
- package/dist/lib/rag/chunking/index.js +18 -0
- package/dist/lib/rag/chunking/jsonChunker.d.ts +20 -0
- package/dist/lib/rag/chunking/jsonChunker.js +282 -0
- package/dist/lib/rag/chunking/latexChunker.d.ts +26 -0
- package/dist/lib/rag/chunking/latexChunker.js +252 -0
- package/dist/lib/rag/chunking/markdownChunker.d.ts +19 -0
- package/dist/lib/rag/chunking/markdownChunker.js +202 -0
- package/dist/lib/rag/chunking/recursiveChunker.d.ts +19 -0
- package/dist/lib/rag/chunking/recursiveChunker.js +149 -0
- package/dist/lib/rag/chunking/semanticChunker.d.ts +41 -0
- package/dist/lib/rag/chunking/semanticChunker.js +307 -0
- package/dist/lib/rag/chunking/sentenceChunker.d.ts +25 -0
- package/dist/lib/rag/chunking/sentenceChunker.js +231 -0
- package/dist/lib/rag/chunking/tokenChunker.d.ts +36 -0
- package/dist/lib/rag/chunking/tokenChunker.js +184 -0
- package/dist/lib/rag/document/MDocument.d.ts +198 -0
- package/dist/lib/rag/document/MDocument.js +393 -0
- package/dist/lib/rag/document/index.d.ts +5 -0
- package/dist/lib/rag/document/index.js +6 -0
- package/dist/lib/rag/document/loaders.d.ts +201 -0
- package/dist/lib/rag/document/loaders.js +501 -0
- package/dist/lib/rag/errors/RAGError.d.ts +244 -0
- package/dist/lib/rag/errors/RAGError.js +275 -0
- package/dist/lib/rag/errors/index.d.ts +6 -0
- package/dist/lib/rag/errors/index.js +7 -0
- package/dist/lib/rag/graphRag/graphRAG.d.ts +115 -0
- package/dist/lib/rag/graphRag/graphRAG.js +385 -0
- package/dist/lib/rag/graphRag/index.d.ts +4 -0
- package/dist/lib/rag/graphRag/index.js +5 -0
- package/dist/lib/rag/index.d.ts +103 -0
- package/dist/lib/rag/index.js +142 -0
- package/dist/lib/rag/metadata/MetadataExtractorFactory.d.ts +157 -0
- package/dist/lib/rag/metadata/MetadataExtractorFactory.js +419 -0
- package/dist/lib/rag/metadata/MetadataExtractorRegistry.d.ts +99 -0
- package/dist/lib/rag/metadata/MetadataExtractorRegistry.js +363 -0
- package/dist/lib/rag/metadata/index.d.ts +6 -0
- package/dist/lib/rag/metadata/index.js +10 -0
- package/dist/lib/rag/metadata/metadataExtractor.d.ts +69 -0
- package/dist/lib/rag/metadata/metadataExtractor.js +278 -0
- package/dist/lib/rag/pipeline/RAGPipeline.d.ts +235 -0
- package/dist/lib/rag/pipeline/RAGPipeline.js +402 -0
- package/dist/lib/rag/pipeline/contextAssembly.d.ts +126 -0
- package/dist/lib/rag/pipeline/contextAssembly.js +338 -0
- package/dist/lib/rag/pipeline/index.d.ts +5 -0
- package/dist/lib/rag/pipeline/index.js +6 -0
- package/dist/lib/rag/ragIntegration.d.ts +38 -0
- package/dist/lib/rag/ragIntegration.js +212 -0
- package/dist/lib/rag/reranker/RerankerFactory.d.ts +184 -0
- package/dist/lib/rag/reranker/RerankerFactory.js +431 -0
- package/dist/lib/rag/reranker/RerankerRegistry.d.ts +119 -0
- package/dist/lib/rag/reranker/RerankerRegistry.js +403 -0
- package/dist/lib/rag/reranker/index.d.ts +6 -0
- package/dist/lib/rag/reranker/index.js +10 -0
- package/dist/lib/rag/reranker/reranker.d.ts +71 -0
- package/dist/lib/rag/reranker/reranker.js +278 -0
- package/dist/lib/rag/resilience/CircuitBreaker.d.ts +215 -0
- package/dist/lib/rag/resilience/CircuitBreaker.js +432 -0
- package/dist/lib/rag/resilience/RetryHandler.d.ts +115 -0
- package/dist/lib/rag/resilience/RetryHandler.js +301 -0
- package/dist/lib/rag/resilience/index.d.ts +7 -0
- package/dist/lib/rag/resilience/index.js +8 -0
- package/dist/lib/rag/retrieval/hybridSearch.d.ts +94 -0
- package/dist/lib/rag/retrieval/hybridSearch.js +314 -0
- package/dist/lib/rag/retrieval/index.d.ts +5 -0
- package/dist/lib/rag/retrieval/index.js +6 -0
- package/dist/lib/rag/retrieval/vectorQueryTool.d.ts +93 -0
- package/dist/lib/rag/retrieval/vectorQueryTool.js +290 -0
- package/dist/lib/rag/types.d.ts +768 -0
- package/dist/lib/rag/types.js +9 -0
- package/dist/lib/server/index.d.ts +15 -11
- package/dist/lib/server/index.js +55 -51
- package/dist/lib/server/utils/validation.d.ts +2 -2
- package/dist/lib/types/common.d.ts +0 -1
- package/dist/lib/types/fileTypes.d.ts +1 -1
- package/dist/lib/types/generateTypes.d.ts +42 -8
- package/dist/lib/types/generateTypes.js +1 -1
- package/dist/lib/types/index.d.ts +25 -24
- package/dist/lib/types/index.js +21 -20
- package/dist/lib/types/modelTypes.d.ts +16 -16
- package/dist/lib/types/pptTypes.d.ts +14 -2
- package/dist/lib/types/pptTypes.js +16 -0
- package/dist/lib/types/streamTypes.d.ts +28 -8
- package/dist/lib/types/streamTypes.js +1 -1
- package/dist/lib/utils/async/delay.d.ts +40 -0
- package/dist/lib/utils/async/delay.js +43 -0
- package/dist/lib/utils/async/index.d.ts +23 -0
- package/dist/lib/utils/async/index.js +24 -0
- package/dist/lib/utils/async/retry.d.ts +141 -0
- package/dist/lib/utils/async/retry.js +172 -0
- package/dist/lib/utils/async/withTimeout.d.ts +73 -0
- package/dist/lib/utils/async/withTimeout.js +97 -0
- package/dist/lib/utils/fileDetector.d.ts +7 -1
- package/dist/lib/utils/fileDetector.js +91 -18
- package/dist/lib/utils/json/extract.d.ts +103 -0
- package/dist/lib/utils/json/extract.js +249 -0
- package/dist/lib/utils/json/index.d.ts +36 -0
- package/dist/lib/utils/json/index.js +37 -0
- package/dist/lib/utils/json/safeParse.d.ts +137 -0
- package/dist/lib/utils/json/safeParse.js +191 -0
- package/dist/lib/utils/messageBuilder.d.ts +2 -2
- package/dist/lib/utils/messageBuilder.js +15 -7
- package/dist/lib/utils/modelRouter.d.ts +4 -4
- package/dist/lib/utils/modelRouter.js +4 -4
- package/dist/lib/utils/sanitizers/filename.d.ts +137 -0
- package/dist/lib/utils/sanitizers/filename.js +366 -0
- package/dist/lib/utils/sanitizers/html.d.ts +170 -0
- package/dist/lib/utils/sanitizers/html.js +326 -0
- package/dist/lib/utils/sanitizers/index.d.ts +26 -0
- package/dist/lib/utils/sanitizers/index.js +30 -0
- package/dist/lib/utils/sanitizers/svg.d.ts +81 -0
- package/dist/lib/utils/sanitizers/svg.js +483 -0
- package/dist/mcp/index.d.ts +6 -5
- package/dist/mcp/index.js +7 -5
- package/dist/neurolink.d.ts +11 -13
- package/dist/neurolink.js +95 -29
- package/dist/processors/base/BaseFileProcessor.d.ts +273 -0
- package/dist/processors/base/BaseFileProcessor.js +613 -0
- package/dist/processors/base/index.d.ts +14 -0
- package/dist/processors/base/index.js +19 -0
- package/dist/processors/base/types.d.ts +593 -0
- package/dist/processors/base/types.js +76 -0
- package/dist/processors/cli/fileProcessorCli.d.ts +163 -0
- package/dist/processors/cli/fileProcessorCli.js +388 -0
- package/dist/processors/cli/index.d.ts +37 -0
- package/dist/processors/cli/index.js +49 -0
- package/dist/processors/code/ConfigProcessor.d.ts +171 -0
- package/dist/processors/code/ConfigProcessor.js +400 -0
- package/dist/processors/code/SourceCodeProcessor.d.ts +174 -0
- package/dist/processors/code/SourceCodeProcessor.js +304 -0
- package/dist/processors/code/index.d.ts +44 -0
- package/dist/processors/code/index.js +60 -0
- package/dist/processors/config/fileTypes.d.ts +283 -0
- package/dist/processors/config/fileTypes.js +520 -0
- package/dist/processors/config/index.d.ts +32 -0
- package/dist/processors/config/index.js +92 -0
- package/dist/processors/config/languageMap.d.ts +66 -0
- package/dist/processors/config/languageMap.js +410 -0
- package/dist/processors/config/mimeTypes.d.ts +376 -0
- package/dist/processors/config/mimeTypes.js +338 -0
- package/dist/processors/config/sizeLimits.d.ts +194 -0
- package/dist/processors/config/sizeLimits.js +246 -0
- package/dist/processors/data/JsonProcessor.d.ts +122 -0
- package/dist/processors/data/JsonProcessor.js +203 -0
- package/dist/processors/data/XmlProcessor.d.ts +160 -0
- package/dist/processors/data/XmlProcessor.js +283 -0
- package/dist/processors/data/YamlProcessor.d.ts +163 -0
- package/dist/processors/data/YamlProcessor.js +294 -0
- package/dist/processors/data/index.d.ts +49 -0
- package/dist/processors/data/index.js +76 -0
- package/dist/processors/document/ExcelProcessor.d.ts +238 -0
- package/dist/processors/document/ExcelProcessor.js +519 -0
- package/dist/processors/document/OpenDocumentProcessor.d.ts +69 -0
- package/dist/processors/document/OpenDocumentProcessor.js +210 -0
- package/dist/processors/document/RtfProcessor.d.ts +152 -0
- package/dist/processors/document/RtfProcessor.js +361 -0
- package/dist/processors/document/WordProcessor.d.ts +168 -0
- package/dist/processors/document/WordProcessor.js +353 -0
- package/dist/processors/document/index.d.ts +54 -0
- package/dist/processors/document/index.js +90 -0
- package/dist/processors/errors/FileErrorCode.d.ts +98 -0
- package/dist/processors/errors/FileErrorCode.js +255 -0
- package/dist/processors/errors/errorHelpers.d.ts +151 -0
- package/dist/processors/errors/errorHelpers.js +378 -0
- package/dist/processors/errors/errorSerializer.d.ts +139 -0
- package/dist/processors/errors/errorSerializer.js +507 -0
- package/dist/processors/errors/index.d.ts +46 -0
- package/dist/processors/errors/index.js +49 -0
- package/dist/processors/index.d.ts +76 -0
- package/dist/processors/index.js +112 -0
- package/dist/processors/integration/FileProcessorIntegration.d.ts +244 -0
- package/dist/processors/integration/FileProcessorIntegration.js +272 -0
- package/dist/processors/integration/index.d.ts +42 -0
- package/dist/processors/integration/index.js +44 -0
- package/dist/processors/markup/HtmlProcessor.d.ts +169 -0
- package/dist/processors/markup/HtmlProcessor.js +249 -0
- package/dist/processors/markup/MarkdownProcessor.d.ts +165 -0
- package/dist/processors/markup/MarkdownProcessor.js +244 -0
- package/dist/processors/markup/SvgProcessor.d.ts +156 -0
- package/dist/processors/markup/SvgProcessor.js +240 -0
- package/dist/processors/markup/TextProcessor.d.ts +135 -0
- package/dist/processors/markup/TextProcessor.js +188 -0
- package/dist/processors/markup/index.d.ts +66 -0
- package/dist/processors/markup/index.js +102 -0
- package/dist/processors/registry/ProcessorRegistry.d.ts +334 -0
- package/dist/processors/registry/ProcessorRegistry.js +608 -0
- package/dist/processors/registry/index.d.ts +12 -0
- package/dist/processors/registry/index.js +16 -0
- package/dist/processors/registry/types.d.ts +53 -0
- package/dist/processors/registry/types.js +10 -0
- package/dist/providers/amazonBedrock.d.ts +15 -2
- package/dist/providers/amazonBedrock.js +65 -8
- package/dist/providers/anthropic.d.ts +3 -3
- package/dist/providers/anthropic.js +10 -7
- package/dist/providers/googleAiStudio.d.ts +5 -5
- package/dist/providers/googleAiStudio.js +10 -7
- package/dist/providers/googleVertex.d.ts +16 -4
- package/dist/providers/googleVertex.js +72 -16
- package/dist/providers/litellm.d.ts +3 -3
- package/dist/providers/litellm.js +10 -10
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/mistral.js +7 -6
- package/dist/providers/ollama.d.ts +3 -4
- package/dist/providers/ollama.js +7 -8
- package/dist/providers/openAI.d.ts +14 -2
- package/dist/providers/openAI.js +60 -6
- package/dist/providers/openRouter.d.ts +2 -2
- package/dist/providers/openRouter.js +10 -6
- package/dist/rag/ChunkerFactory.d.ts +91 -0
- package/dist/rag/ChunkerFactory.js +320 -0
- package/dist/rag/ChunkerRegistry.d.ts +91 -0
- package/dist/rag/ChunkerRegistry.js +421 -0
- package/dist/rag/chunkers/BaseChunker.d.ts +53 -0
- package/dist/rag/chunkers/BaseChunker.js +143 -0
- package/dist/rag/chunkers/CharacterChunker.d.ts +18 -0
- package/dist/rag/chunkers/CharacterChunker.js +28 -0
- package/dist/rag/chunkers/HTMLChunker.d.ts +19 -0
- package/dist/rag/chunkers/HTMLChunker.js +38 -0
- package/dist/rag/chunkers/JSONChunker.d.ts +19 -0
- package/dist/rag/chunkers/JSONChunker.js +68 -0
- package/dist/rag/chunkers/LaTeXChunker.d.ts +15 -0
- package/dist/rag/chunkers/LaTeXChunker.js +63 -0
- package/dist/rag/chunkers/MarkdownChunker.d.ts +15 -0
- package/dist/rag/chunkers/MarkdownChunker.js +102 -0
- package/dist/rag/chunkers/RecursiveChunker.d.ts +27 -0
- package/dist/rag/chunkers/RecursiveChunker.js +139 -0
- package/dist/rag/chunkers/SemanticMarkdownChunker.d.ts +22 -0
- package/dist/rag/chunkers/SemanticMarkdownChunker.js +138 -0
- package/dist/rag/chunkers/SentenceChunker.d.ts +19 -0
- package/dist/rag/chunkers/SentenceChunker.js +66 -0
- package/dist/rag/chunkers/TokenChunker.d.ts +19 -0
- package/dist/rag/chunkers/TokenChunker.js +61 -0
- package/dist/rag/chunkers/index.d.ts +15 -0
- package/dist/rag/chunkers/index.js +15 -0
- package/dist/rag/chunking/characterChunker.d.ts +16 -0
- package/dist/rag/chunking/characterChunker.js +142 -0
- package/dist/rag/chunking/chunkerRegistry.d.ts +67 -0
- package/dist/rag/chunking/chunkerRegistry.js +194 -0
- package/dist/rag/chunking/htmlChunker.d.ts +34 -0
- package/dist/rag/chunking/htmlChunker.js +247 -0
- package/dist/rag/chunking/index.d.ts +15 -0
- package/dist/rag/chunking/index.js +17 -0
- package/dist/rag/chunking/jsonChunker.d.ts +20 -0
- package/dist/rag/chunking/jsonChunker.js +281 -0
- package/dist/rag/chunking/latexChunker.d.ts +26 -0
- package/dist/rag/chunking/latexChunker.js +251 -0
- package/dist/rag/chunking/markdownChunker.d.ts +19 -0
- package/dist/rag/chunking/markdownChunker.js +201 -0
- package/dist/rag/chunking/recursiveChunker.d.ts +19 -0
- package/dist/rag/chunking/recursiveChunker.js +148 -0
- package/dist/rag/chunking/semanticChunker.d.ts +41 -0
- package/dist/rag/chunking/semanticChunker.js +306 -0
- package/dist/rag/chunking/sentenceChunker.d.ts +25 -0
- package/dist/rag/chunking/sentenceChunker.js +230 -0
- package/dist/rag/chunking/tokenChunker.d.ts +36 -0
- package/dist/rag/chunking/tokenChunker.js +183 -0
- package/dist/rag/document/MDocument.d.ts +198 -0
- package/dist/rag/document/MDocument.js +392 -0
- package/dist/rag/document/index.d.ts +5 -0
- package/dist/rag/document/index.js +5 -0
- package/dist/rag/document/loaders.d.ts +201 -0
- package/dist/rag/document/loaders.js +500 -0
- package/dist/rag/errors/RAGError.d.ts +244 -0
- package/dist/rag/errors/RAGError.js +274 -0
- package/dist/rag/errors/index.d.ts +6 -0
- package/dist/rag/errors/index.js +6 -0
- package/dist/rag/graphRag/graphRAG.d.ts +115 -0
- package/dist/rag/graphRag/graphRAG.js +384 -0
- package/dist/rag/graphRag/index.d.ts +4 -0
- package/dist/rag/graphRag/index.js +4 -0
- package/dist/rag/index.d.ts +103 -0
- package/dist/rag/index.js +141 -0
- package/dist/rag/metadata/MetadataExtractorFactory.d.ts +157 -0
- package/dist/rag/metadata/MetadataExtractorFactory.js +418 -0
- package/dist/rag/metadata/MetadataExtractorRegistry.d.ts +99 -0
- package/dist/rag/metadata/MetadataExtractorRegistry.js +362 -0
- package/dist/rag/metadata/index.d.ts +6 -0
- package/dist/rag/metadata/index.js +9 -0
- package/dist/rag/metadata/metadataExtractor.d.ts +69 -0
- package/dist/rag/metadata/metadataExtractor.js +277 -0
- package/dist/rag/pipeline/RAGPipeline.d.ts +235 -0
- package/dist/rag/pipeline/RAGPipeline.js +401 -0
- package/dist/rag/pipeline/contextAssembly.d.ts +126 -0
- package/dist/rag/pipeline/contextAssembly.js +337 -0
- package/dist/rag/pipeline/index.d.ts +5 -0
- package/dist/rag/pipeline/index.js +5 -0
- package/dist/rag/ragIntegration.d.ts +38 -0
- package/dist/rag/ragIntegration.js +211 -0
- package/dist/rag/reranker/RerankerFactory.d.ts +184 -0
- package/dist/rag/reranker/RerankerFactory.js +430 -0
- package/dist/rag/reranker/RerankerRegistry.d.ts +119 -0
- package/dist/rag/reranker/RerankerRegistry.js +402 -0
- package/dist/rag/reranker/index.d.ts +6 -0
- package/dist/rag/reranker/index.js +9 -0
- package/dist/rag/reranker/reranker.d.ts +71 -0
- package/dist/rag/reranker/reranker.js +277 -0
- package/dist/rag/resilience/CircuitBreaker.d.ts +215 -0
- package/dist/rag/resilience/CircuitBreaker.js +431 -0
- package/dist/rag/resilience/RetryHandler.d.ts +115 -0
- package/dist/rag/resilience/RetryHandler.js +300 -0
- package/dist/rag/resilience/index.d.ts +7 -0
- package/dist/rag/resilience/index.js +7 -0
- package/dist/rag/retrieval/hybridSearch.d.ts +94 -0
- package/dist/rag/retrieval/hybridSearch.js +313 -0
- package/dist/rag/retrieval/index.d.ts +5 -0
- package/dist/rag/retrieval/index.js +5 -0
- package/dist/rag/retrieval/vectorQueryTool.d.ts +93 -0
- package/dist/rag/retrieval/vectorQueryTool.js +289 -0
- package/dist/rag/types.d.ts +768 -0
- package/dist/rag/types.js +8 -0
- package/dist/server/index.d.ts +15 -11
- package/dist/server/index.js +55 -51
- package/dist/server/utils/validation.d.ts +8 -8
- package/dist/types/common.d.ts +0 -1
- package/dist/types/fileTypes.d.ts +1 -1
- package/dist/types/generateTypes.d.ts +42 -8
- package/dist/types/generateTypes.js +1 -1
- package/dist/types/index.d.ts +25 -24
- package/dist/types/index.js +21 -20
- package/dist/types/modelTypes.d.ts +10 -10
- package/dist/types/pptTypes.d.ts +14 -2
- package/dist/types/pptTypes.js +16 -0
- package/dist/types/streamTypes.d.ts +28 -8
- package/dist/types/streamTypes.js +1 -1
- package/dist/utils/async/delay.d.ts +40 -0
- package/dist/utils/async/delay.js +42 -0
- package/dist/utils/async/index.d.ts +23 -0
- package/dist/utils/async/index.js +23 -0
- package/dist/utils/async/retry.d.ts +141 -0
- package/dist/utils/async/retry.js +171 -0
- package/dist/utils/async/withTimeout.d.ts +73 -0
- package/dist/utils/async/withTimeout.js +96 -0
- package/dist/utils/fileDetector.d.ts +7 -1
- package/dist/utils/fileDetector.js +91 -18
- package/dist/utils/json/extract.d.ts +103 -0
- package/dist/utils/json/extract.js +248 -0
- package/dist/utils/json/index.d.ts +36 -0
- package/dist/utils/json/index.js +36 -0
- package/dist/utils/json/safeParse.d.ts +137 -0
- package/dist/utils/json/safeParse.js +190 -0
- package/dist/utils/messageBuilder.d.ts +2 -2
- package/dist/utils/messageBuilder.js +15 -7
- package/dist/utils/modelRouter.d.ts +4 -4
- package/dist/utils/modelRouter.js +4 -4
- package/dist/utils/sanitizers/filename.d.ts +137 -0
- package/dist/utils/sanitizers/filename.js +365 -0
- package/dist/utils/sanitizers/html.d.ts +170 -0
- package/dist/utils/sanitizers/html.js +325 -0
- package/dist/utils/sanitizers/index.d.ts +26 -0
- package/dist/utils/sanitizers/index.js +29 -0
- package/dist/utils/sanitizers/svg.d.ts +81 -0
- package/dist/utils/sanitizers/svg.js +482 -0
- package/package.json +2 -2
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reranker Implementation
|
|
3
|
+
*
|
|
4
|
+
* Multi-factor scoring system for reranking retrieval results.
|
|
5
|
+
* Combines semantic relevance (LLM-based), vector similarity, and position.
|
|
6
|
+
*/
|
|
7
|
+
import { logger } from "../../utils/logger.js";
|
|
8
|
+
/**
|
|
9
|
+
* Default scoring weights
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_WEIGHTS = {
|
|
12
|
+
semantic: 0.4,
|
|
13
|
+
vector: 0.4,
|
|
14
|
+
position: 0.2,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Rerank vector search results using multi-factor scoring
|
|
18
|
+
*
|
|
19
|
+
* Combines three scoring factors:
|
|
20
|
+
* 1. Semantic score: LLM-based relevance assessment
|
|
21
|
+
* 2. Vector score: Original similarity score from vector search
|
|
22
|
+
* 3. Position score: Inverse of original ranking position
|
|
23
|
+
*
|
|
24
|
+
* @param results - Vector search results to rerank
|
|
25
|
+
* @param query - Original search query
|
|
26
|
+
* @param model - Language model for semantic scoring
|
|
27
|
+
* @param options - Reranking options
|
|
28
|
+
* @returns Reranked results with detailed scores
|
|
29
|
+
*/
|
|
30
|
+
export async function rerank(results, query, model, options) {
|
|
31
|
+
const { queryEmbedding: _queryEmbedding, topK = 3, weights = DEFAULT_WEIGHTS, } = options || {};
|
|
32
|
+
if (results.length === 0) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
// Validate weights sum to 1.0
|
|
36
|
+
const totalWeight = (weights.semantic || DEFAULT_WEIGHTS.semantic) +
|
|
37
|
+
(weights.vector || DEFAULT_WEIGHTS.vector) +
|
|
38
|
+
(weights.position || DEFAULT_WEIGHTS.position);
|
|
39
|
+
if (Math.abs(totalWeight - 1.0) > 0.01) {
|
|
40
|
+
logger.warn("[Reranker] Weights do not sum to 1.0, normalizing", {
|
|
41
|
+
original: weights,
|
|
42
|
+
total: totalWeight,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const normalizedWeights = {
|
|
46
|
+
semantic: (weights.semantic || DEFAULT_WEIGHTS.semantic) / totalWeight,
|
|
47
|
+
vector: (weights.vector || DEFAULT_WEIGHTS.vector) / totalWeight,
|
|
48
|
+
position: (weights.position || DEFAULT_WEIGHTS.position) / totalWeight,
|
|
49
|
+
};
|
|
50
|
+
const rerankedResults = [];
|
|
51
|
+
// Process results in parallel batches for efficiency
|
|
52
|
+
const batchSize = 5;
|
|
53
|
+
for (let i = 0; i < results.length; i += batchSize) {
|
|
54
|
+
const batch = results.slice(i, i + batchSize);
|
|
55
|
+
const batchPromises = batch.map(async (result, batchIndex) => {
|
|
56
|
+
const globalIndex = i + batchIndex;
|
|
57
|
+
// Calculate vector score (use existing score or 0)
|
|
58
|
+
const vectorScore = result.score ?? 0;
|
|
59
|
+
// Calculate position score (inverse of position)
|
|
60
|
+
const positionScore = 1 - globalIndex / results.length;
|
|
61
|
+
// Calculate semantic score using LLM
|
|
62
|
+
const semanticResult = await calculateSemanticScore(query, result.text || result.metadata?.text || "", model);
|
|
63
|
+
// Combine scores
|
|
64
|
+
const combinedScore = normalizedWeights.semantic * semanticResult.score +
|
|
65
|
+
normalizedWeights.vector * vectorScore +
|
|
66
|
+
normalizedWeights.position * positionScore;
|
|
67
|
+
return {
|
|
68
|
+
result,
|
|
69
|
+
score: combinedScore,
|
|
70
|
+
details: {
|
|
71
|
+
semantic: semanticResult.score,
|
|
72
|
+
vector: vectorScore,
|
|
73
|
+
position: positionScore,
|
|
74
|
+
queryAnalysis: semanticResult.analysis,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const batchResults = await Promise.all(batchPromises);
|
|
79
|
+
rerankedResults.push(...batchResults);
|
|
80
|
+
}
|
|
81
|
+
// Sort by combined score descending
|
|
82
|
+
rerankedResults.sort((a, b) => b.score - a.score);
|
|
83
|
+
// Return top K results
|
|
84
|
+
return rerankedResults.slice(0, topK);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Calculate semantic relevance score using LLM
|
|
88
|
+
*
|
|
89
|
+
* @param query - Search query
|
|
90
|
+
* @param text - Document text to score
|
|
91
|
+
* @param model - Language model for scoring
|
|
92
|
+
* @returns Score between 0 and 1 with optional analysis
|
|
93
|
+
*/
|
|
94
|
+
async function calculateSemanticScore(query, text, model) {
|
|
95
|
+
const prompt = `Rate the relevance of the following text to the query on a scale of 0 to 1.
|
|
96
|
+
|
|
97
|
+
Query: ${query}
|
|
98
|
+
|
|
99
|
+
Text: ${text.slice(0, 1000)}
|
|
100
|
+
|
|
101
|
+
Respond with only a number between 0 and 1, where:
|
|
102
|
+
- 0 means completely irrelevant
|
|
103
|
+
- 0.5 means somewhat relevant
|
|
104
|
+
- 1 means highly relevant
|
|
105
|
+
|
|
106
|
+
Score:`;
|
|
107
|
+
try {
|
|
108
|
+
const result = await model.generate({
|
|
109
|
+
prompt,
|
|
110
|
+
maxTokens: 10,
|
|
111
|
+
temperature: 0,
|
|
112
|
+
});
|
|
113
|
+
const scoreText = result?.content?.trim() || "0";
|
|
114
|
+
const score = parseFloat(scoreText);
|
|
115
|
+
if (isNaN(score) || score < 0 || score > 1) {
|
|
116
|
+
return { score: 0.5 };
|
|
117
|
+
}
|
|
118
|
+
return { score };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
logger.warn("[Reranker] Semantic scoring failed, using default", {
|
|
122
|
+
error: error instanceof Error ? error.message : String(error),
|
|
123
|
+
});
|
|
124
|
+
return { score: 0.5 };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Batch rerank with optimized LLM calls
|
|
129
|
+
* Scores multiple documents in a single prompt for efficiency
|
|
130
|
+
*
|
|
131
|
+
* @param results - Results to rerank
|
|
132
|
+
* @param query - Search query
|
|
133
|
+
* @param model - Language model
|
|
134
|
+
* @param options - Reranking options
|
|
135
|
+
* @returns Reranked results
|
|
136
|
+
*/
|
|
137
|
+
export async function batchRerank(results, query, model, options) {
|
|
138
|
+
const { topK = 3, weights = DEFAULT_WEIGHTS } = options || {};
|
|
139
|
+
if (results.length === 0) {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
// Normalize weights
|
|
143
|
+
const totalWeight = (weights.semantic || DEFAULT_WEIGHTS.semantic) +
|
|
144
|
+
(weights.vector || DEFAULT_WEIGHTS.vector) +
|
|
145
|
+
(weights.position || DEFAULT_WEIGHTS.position);
|
|
146
|
+
const normalizedWeights = {
|
|
147
|
+
semantic: (weights.semantic || DEFAULT_WEIGHTS.semantic) / totalWeight,
|
|
148
|
+
vector: (weights.vector || DEFAULT_WEIGHTS.vector) / totalWeight,
|
|
149
|
+
position: (weights.position || DEFAULT_WEIGHTS.position) / totalWeight,
|
|
150
|
+
};
|
|
151
|
+
// Build batch scoring prompt
|
|
152
|
+
const documentsText = results
|
|
153
|
+
.map((r, i) => `[${i + 1}] ${(r.text || r.metadata?.text || "").slice(0, 300)}`)
|
|
154
|
+
.join("\n\n");
|
|
155
|
+
const prompt = `Rate the relevance of each document to the query on a scale of 0 to 1.
|
|
156
|
+
|
|
157
|
+
Query: ${query}
|
|
158
|
+
|
|
159
|
+
Documents:
|
|
160
|
+
${documentsText}
|
|
161
|
+
|
|
162
|
+
For each document, provide a score between 0 and 1.
|
|
163
|
+
Respond with only the scores, one per line, in order:`;
|
|
164
|
+
try {
|
|
165
|
+
const result = await model.generate({
|
|
166
|
+
prompt,
|
|
167
|
+
maxTokens: 50,
|
|
168
|
+
temperature: 0,
|
|
169
|
+
});
|
|
170
|
+
// Parse scores from response
|
|
171
|
+
const scoreLines = (result?.content || "")
|
|
172
|
+
.trim()
|
|
173
|
+
.split("\n")
|
|
174
|
+
.map((line) => line.trim())
|
|
175
|
+
.filter((line) => line.length > 0);
|
|
176
|
+
const semanticScores = [];
|
|
177
|
+
for (let i = 0; i < results.length; i++) {
|
|
178
|
+
const scoreLine = scoreLines[i];
|
|
179
|
+
if (scoreLine) {
|
|
180
|
+
const score = parseFloat(scoreLine.match(/[\d.]+/)?.[0] || "0.5");
|
|
181
|
+
semanticScores.push(isNaN(score) || score < 0 || score > 1 ? 0.5 : score);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
semanticScores.push(0.5);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Calculate combined scores
|
|
188
|
+
const rerankedResults = results.map((result, i) => {
|
|
189
|
+
const vectorScore = result.score ?? 0;
|
|
190
|
+
const positionScore = 1 - i / results.length;
|
|
191
|
+
const semanticScore = semanticScores[i] ?? 0.5;
|
|
192
|
+
const combinedScore = normalizedWeights.semantic * semanticScore +
|
|
193
|
+
normalizedWeights.vector * vectorScore +
|
|
194
|
+
normalizedWeights.position * positionScore;
|
|
195
|
+
return {
|
|
196
|
+
result,
|
|
197
|
+
score: combinedScore,
|
|
198
|
+
details: {
|
|
199
|
+
semantic: semanticScore,
|
|
200
|
+
vector: vectorScore,
|
|
201
|
+
position: positionScore,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
// Sort and return top K
|
|
206
|
+
rerankedResults.sort((a, b) => b.score - a.score);
|
|
207
|
+
return rerankedResults.slice(0, topK);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
logger.warn("[Reranker] Batch scoring failed, using individual scoring", {
|
|
211
|
+
error: error instanceof Error ? error.message : String(error),
|
|
212
|
+
});
|
|
213
|
+
// Fall back to individual scoring
|
|
214
|
+
return rerank(results, query, model, options);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Simple position-based reranker (no LLM required)
|
|
219
|
+
* Uses only vector score and position
|
|
220
|
+
*
|
|
221
|
+
* @param results - Results to rerank
|
|
222
|
+
* @param options - Reranking options
|
|
223
|
+
* @returns Reranked results
|
|
224
|
+
*/
|
|
225
|
+
export function simpleRerank(results, options) {
|
|
226
|
+
const { topK = 3, vectorWeight = 0.8, positionWeight = 0.2 } = options || {};
|
|
227
|
+
const totalWeight = vectorWeight + positionWeight;
|
|
228
|
+
const normalizedVectorWeight = vectorWeight / totalWeight;
|
|
229
|
+
const normalizedPositionWeight = positionWeight / totalWeight;
|
|
230
|
+
const rerankedResults = results.map((result, i) => {
|
|
231
|
+
const vectorScore = result.score ?? 0;
|
|
232
|
+
const positionScore = 1 - i / results.length;
|
|
233
|
+
const combinedScore = normalizedVectorWeight * vectorScore +
|
|
234
|
+
normalizedPositionWeight * positionScore;
|
|
235
|
+
return {
|
|
236
|
+
result,
|
|
237
|
+
score: combinedScore,
|
|
238
|
+
details: {
|
|
239
|
+
semantic: 0,
|
|
240
|
+
vector: vectorScore,
|
|
241
|
+
position: positionScore,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
rerankedResults.sort((a, b) => b.score - a.score);
|
|
246
|
+
return rerankedResults.slice(0, topK);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Cohere-style relevance scorer interface
|
|
250
|
+
* Placeholder for integration with Cohere's rerank API
|
|
251
|
+
*/
|
|
252
|
+
export class CohereRelevanceScorer {
|
|
253
|
+
modelName;
|
|
254
|
+
constructor(modelName = "rerank-v3.5") {
|
|
255
|
+
this.modelName = modelName;
|
|
256
|
+
}
|
|
257
|
+
async score(_query, _documents) {
|
|
258
|
+
// Placeholder - would use Cohere's rerank API
|
|
259
|
+
throw new Error("CohereRelevanceScorer requires Cohere API integration. " +
|
|
260
|
+
"Install @cohere-ai/cohere and provide API key.");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Cross-encoder style reranker interface
|
|
265
|
+
* Placeholder for integration with cross-encoder models
|
|
266
|
+
*/
|
|
267
|
+
export class CrossEncoderReranker {
|
|
268
|
+
modelName;
|
|
269
|
+
constructor(modelName = "ms-marco-MiniLM-L-6-v2") {
|
|
270
|
+
this.modelName = modelName;
|
|
271
|
+
}
|
|
272
|
+
async rerank(_query, _documents) {
|
|
273
|
+
// Placeholder - would use cross-encoder model
|
|
274
|
+
throw new Error("CrossEncoderReranker requires a cross-encoder model. " +
|
|
275
|
+
"Consider using the LLM-based rerank function instead.");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=reranker.js.map
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RAG Circuit Breaker
|
|
3
|
+
*
|
|
4
|
+
* Implements circuit breaker pattern for RAG operations including
|
|
5
|
+
* vector store queries, embeddings, and reranking calls.
|
|
6
|
+
* Provides fault tolerance and prevents cascading failures.
|
|
7
|
+
*/
|
|
8
|
+
import { TypedEventEmitter } from "../../core/infrastructure/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Circuit breaker states
|
|
11
|
+
*/
|
|
12
|
+
export type CircuitState = "closed" | "open" | "half-open";
|
|
13
|
+
/**
|
|
14
|
+
* Circuit breaker configuration
|
|
15
|
+
*/
|
|
16
|
+
export interface RAGCircuitBreakerConfig {
|
|
17
|
+
/** Number of failures before opening circuit (default: 5) */
|
|
18
|
+
failureThreshold: number;
|
|
19
|
+
/** Time in ms before attempting reset (default: 60000) */
|
|
20
|
+
resetTimeout: number;
|
|
21
|
+
/** Max calls allowed in half-open state (default: 3) */
|
|
22
|
+
halfOpenMaxCalls: number;
|
|
23
|
+
/** Operation timeout in ms (default: 30000) */
|
|
24
|
+
operationTimeout: number;
|
|
25
|
+
/** Minimum calls before calculating failure rate (default: 10) */
|
|
26
|
+
minimumCallsBeforeCalculation: number;
|
|
27
|
+
/** Time window for statistics in ms (default: 300000 - 5 minutes) */
|
|
28
|
+
statisticsWindowSize: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Circuit breaker statistics
|
|
32
|
+
*/
|
|
33
|
+
export interface RAGCircuitBreakerStats {
|
|
34
|
+
state: CircuitState;
|
|
35
|
+
totalCalls: number;
|
|
36
|
+
successfulCalls: number;
|
|
37
|
+
failedCalls: number;
|
|
38
|
+
failureRate: number;
|
|
39
|
+
windowCalls: number;
|
|
40
|
+
lastStateChange: Date;
|
|
41
|
+
nextRetryTime?: Date;
|
|
42
|
+
halfOpenCalls: number;
|
|
43
|
+
averageLatency: number;
|
|
44
|
+
p95Latency: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Circuit breaker events
|
|
48
|
+
*/
|
|
49
|
+
export type RAGCircuitBreakerEvents = {
|
|
50
|
+
stateChange: [
|
|
51
|
+
{
|
|
52
|
+
oldState: CircuitState;
|
|
53
|
+
newState: CircuitState;
|
|
54
|
+
reason: string;
|
|
55
|
+
timestamp: Date;
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
callSuccess: [{
|
|
59
|
+
duration: number;
|
|
60
|
+
timestamp: Date;
|
|
61
|
+
operationType?: string;
|
|
62
|
+
}];
|
|
63
|
+
callFailure: [
|
|
64
|
+
{
|
|
65
|
+
error: string;
|
|
66
|
+
duration: number;
|
|
67
|
+
timestamp: Date;
|
|
68
|
+
operationType?: string;
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
circuitOpen: [{
|
|
72
|
+
failureRate: number;
|
|
73
|
+
totalCalls: number;
|
|
74
|
+
timestamp: Date;
|
|
75
|
+
}];
|
|
76
|
+
circuitHalfOpen: [{
|
|
77
|
+
timestamp: Date;
|
|
78
|
+
}];
|
|
79
|
+
circuitClosed: [{
|
|
80
|
+
timestamp: Date;
|
|
81
|
+
}];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* RAG Circuit Breaker
|
|
85
|
+
*
|
|
86
|
+
* Provides circuit breaker pattern implementation for RAG operations
|
|
87
|
+
* with comprehensive statistics and event handling.
|
|
88
|
+
*/
|
|
89
|
+
export declare class RAGCircuitBreaker extends TypedEventEmitter<RAGCircuitBreakerEvents> {
|
|
90
|
+
private name;
|
|
91
|
+
private state;
|
|
92
|
+
private config;
|
|
93
|
+
private callHistory;
|
|
94
|
+
private lastFailureTime;
|
|
95
|
+
private halfOpenCalls;
|
|
96
|
+
private lastStateChange;
|
|
97
|
+
private cleanupTimer?;
|
|
98
|
+
constructor(name: string, config?: Partial<RAGCircuitBreakerConfig>);
|
|
99
|
+
/**
|
|
100
|
+
* Execute an operation with circuit breaker protection
|
|
101
|
+
*/
|
|
102
|
+
execute<T>(operation: () => Promise<T>, operationType?: string): Promise<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Record a call in the history
|
|
105
|
+
*/
|
|
106
|
+
private recordCall;
|
|
107
|
+
/**
|
|
108
|
+
* Check if failure threshold is exceeded
|
|
109
|
+
*/
|
|
110
|
+
private checkFailureThreshold;
|
|
111
|
+
/**
|
|
112
|
+
* Change circuit breaker state
|
|
113
|
+
*/
|
|
114
|
+
private changeState;
|
|
115
|
+
/**
|
|
116
|
+
* Create a timeout promise
|
|
117
|
+
*/
|
|
118
|
+
private timeoutPromise;
|
|
119
|
+
/**
|
|
120
|
+
* Clean up old call records
|
|
121
|
+
*/
|
|
122
|
+
private cleanupCallHistory;
|
|
123
|
+
/**
|
|
124
|
+
* Calculate percentile latency
|
|
125
|
+
*/
|
|
126
|
+
private calculatePercentileLatency;
|
|
127
|
+
/**
|
|
128
|
+
* Get current statistics
|
|
129
|
+
*/
|
|
130
|
+
getStats(): RAGCircuitBreakerStats;
|
|
131
|
+
/**
|
|
132
|
+
* Manually reset the circuit breaker
|
|
133
|
+
*/
|
|
134
|
+
reset(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Force open the circuit breaker
|
|
137
|
+
*/
|
|
138
|
+
forceOpen(reason?: string): void;
|
|
139
|
+
/**
|
|
140
|
+
* Get circuit breaker name
|
|
141
|
+
*/
|
|
142
|
+
getName(): string;
|
|
143
|
+
/**
|
|
144
|
+
* Check if circuit is open
|
|
145
|
+
*/
|
|
146
|
+
isOpen(): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Check if circuit is closed
|
|
149
|
+
*/
|
|
150
|
+
isClosed(): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Check if circuit is half-open
|
|
153
|
+
*/
|
|
154
|
+
isHalfOpen(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Get current state
|
|
157
|
+
*/
|
|
158
|
+
getState(): CircuitState;
|
|
159
|
+
/**
|
|
160
|
+
* Destroy the circuit breaker and clean up resources
|
|
161
|
+
*/
|
|
162
|
+
destroy(): void;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Circuit breaker manager for RAG operations
|
|
166
|
+
*/
|
|
167
|
+
export declare class RAGCircuitBreakerManager {
|
|
168
|
+
private breakers;
|
|
169
|
+
/**
|
|
170
|
+
* Get or create a circuit breaker
|
|
171
|
+
*/
|
|
172
|
+
getBreaker(name: string, config?: Partial<RAGCircuitBreakerConfig>): RAGCircuitBreaker;
|
|
173
|
+
/**
|
|
174
|
+
* Remove a circuit breaker
|
|
175
|
+
*/
|
|
176
|
+
removeBreaker(name: string): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Get all circuit breaker names
|
|
179
|
+
*/
|
|
180
|
+
getBreakerNames(): string[];
|
|
181
|
+
/**
|
|
182
|
+
* Get statistics for all circuit breakers
|
|
183
|
+
*/
|
|
184
|
+
getAllStats(): Record<string, RAGCircuitBreakerStats>;
|
|
185
|
+
/**
|
|
186
|
+
* Reset all circuit breakers
|
|
187
|
+
*/
|
|
188
|
+
resetAll(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Get health summary
|
|
191
|
+
*/
|
|
192
|
+
getHealthSummary(): {
|
|
193
|
+
totalBreakers: number;
|
|
194
|
+
closedBreakers: number;
|
|
195
|
+
openBreakers: number;
|
|
196
|
+
halfOpenBreakers: number;
|
|
197
|
+
unhealthyBreakers: string[];
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Destroy all circuit breakers
|
|
201
|
+
*/
|
|
202
|
+
destroyAll(): void;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Global circuit breaker manager for RAG operations
|
|
206
|
+
*/
|
|
207
|
+
export declare const ragCircuitBreakerManager: RAGCircuitBreakerManager;
|
|
208
|
+
/**
|
|
209
|
+
* Convenience function to get a circuit breaker
|
|
210
|
+
*/
|
|
211
|
+
export declare function getCircuitBreaker(name: string, config?: Partial<RAGCircuitBreakerConfig>): RAGCircuitBreaker;
|
|
212
|
+
/**
|
|
213
|
+
* Convenience function to execute with circuit breaker
|
|
214
|
+
*/
|
|
215
|
+
export declare function executeWithCircuitBreaker<T>(breakerName: string, operation: () => Promise<T>, operationType?: string, config?: Partial<RAGCircuitBreakerConfig>): Promise<T>;
|