modelfusion 0.0.44
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/LICENSE +21 -0
- package/README.md +429 -0
- package/composed-function/index.cjs +22 -0
- package/composed-function/index.d.ts +6 -0
- package/composed-function/index.js +6 -0
- package/composed-function/summarize/SummarizationFunction.cjs +2 -0
- package/composed-function/summarize/SummarizationFunction.d.ts +4 -0
- package/composed-function/summarize/SummarizationFunction.js +1 -0
- package/composed-function/summarize/summarizeRecursively.cjs +19 -0
- package/composed-function/summarize/summarizeRecursively.d.ts +11 -0
- package/composed-function/summarize/summarizeRecursively.js +15 -0
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +29 -0
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +24 -0
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +25 -0
- package/composed-function/use-tool/NoSuchToolError.cjs +17 -0
- package/composed-function/use-tool/NoSuchToolError.d.ts +4 -0
- package/composed-function/use-tool/NoSuchToolError.js +13 -0
- package/composed-function/use-tool/Tool.cjs +43 -0
- package/composed-function/use-tool/Tool.d.ts +15 -0
- package/composed-function/use-tool/Tool.js +39 -0
- package/composed-function/use-tool/useTool.cjs +59 -0
- package/composed-function/use-tool/useTool.d.ts +36 -0
- package/composed-function/use-tool/useTool.js +54 -0
- package/cost/Cost.cjs +38 -0
- package/cost/Cost.d.ts +16 -0
- package/cost/Cost.js +34 -0
- package/cost/CostCalculator.cjs +2 -0
- package/cost/CostCalculator.d.ts +8 -0
- package/cost/CostCalculator.js +1 -0
- package/cost/calculateCost.cjs +28 -0
- package/cost/calculateCost.d.ts +7 -0
- package/cost/calculateCost.js +24 -0
- package/cost/index.cjs +19 -0
- package/cost/index.d.ts +3 -0
- package/cost/index.js +3 -0
- package/index.cjs +25 -0
- package/index.d.ts +9 -0
- package/index.js +9 -0
- package/model-function/AbstractModel.cjs +22 -0
- package/model-function/AbstractModel.d.ts +12 -0
- package/model-function/AbstractModel.js +18 -0
- package/model-function/FunctionOptions.cjs +2 -0
- package/model-function/FunctionOptions.d.ts +6 -0
- package/model-function/FunctionOptions.js +1 -0
- package/model-function/Model.cjs +2 -0
- package/model-function/Model.d.ts +23 -0
- package/model-function/Model.js +1 -0
- package/model-function/ModelCallEvent.cjs +2 -0
- package/model-function/ModelCallEvent.d.ts +18 -0
- package/model-function/ModelCallEvent.js +1 -0
- package/model-function/ModelCallEventSource.cjs +42 -0
- package/model-function/ModelCallEventSource.d.ts +13 -0
- package/model-function/ModelCallEventSource.js +38 -0
- package/model-function/ModelCallObserver.cjs +2 -0
- package/model-function/ModelCallObserver.d.ts +5 -0
- package/model-function/ModelCallObserver.js +1 -0
- package/model-function/ModelInformation.cjs +2 -0
- package/model-function/ModelInformation.d.ts +4 -0
- package/model-function/ModelInformation.js +1 -0
- package/model-function/SuccessfulModelCall.cjs +22 -0
- package/model-function/SuccessfulModelCall.d.ts +9 -0
- package/model-function/SuccessfulModelCall.js +18 -0
- package/model-function/embed-text/TextEmbeddingEvent.cjs +2 -0
- package/model-function/embed-text/TextEmbeddingEvent.d.ts +23 -0
- package/model-function/embed-text/TextEmbeddingEvent.js +1 -0
- package/model-function/embed-text/TextEmbeddingModel.cjs +2 -0
- package/model-function/embed-text/TextEmbeddingModel.d.ts +18 -0
- package/model-function/embed-text/TextEmbeddingModel.js +1 -0
- package/model-function/embed-text/embedText.cjs +90 -0
- package/model-function/embed-text/embedText.d.ts +33 -0
- package/model-function/embed-text/embedText.js +85 -0
- package/model-function/executeCall.cjs +60 -0
- package/model-function/executeCall.d.ts +27 -0
- package/model-function/executeCall.js +56 -0
- package/model-function/generate-image/ImageGenerationEvent.cjs +2 -0
- package/model-function/generate-image/ImageGenerationEvent.d.ts +22 -0
- package/model-function/generate-image/ImageGenerationEvent.js +1 -0
- package/model-function/generate-image/ImageGenerationModel.cjs +2 -0
- package/model-function/generate-image/ImageGenerationModel.d.ts +8 -0
- package/model-function/generate-image/ImageGenerationModel.js +1 -0
- package/model-function/generate-image/generateImage.cjs +63 -0
- package/model-function/generate-image/generateImage.d.ts +23 -0
- package/model-function/generate-image/generateImage.js +59 -0
- package/model-function/generate-json/GenerateJsonModel.cjs +2 -0
- package/model-function/generate-json/GenerateJsonModel.d.ts +10 -0
- package/model-function/generate-json/GenerateJsonModel.js +1 -0
- package/model-function/generate-json/GenerateJsonOrTextModel.cjs +2 -0
- package/model-function/generate-json/GenerateJsonOrTextModel.d.ts +18 -0
- package/model-function/generate-json/GenerateJsonOrTextModel.js +1 -0
- package/model-function/generate-json/JsonGenerationEvent.cjs +2 -0
- package/model-function/generate-json/JsonGenerationEvent.d.ts +22 -0
- package/model-function/generate-json/JsonGenerationEvent.js +1 -0
- package/model-function/generate-json/NoSuchSchemaError.cjs +17 -0
- package/model-function/generate-json/NoSuchSchemaError.d.ts +4 -0
- package/model-function/generate-json/NoSuchSchemaError.js +13 -0
- package/model-function/generate-json/SchemaDefinition.cjs +2 -0
- package/model-function/generate-json/SchemaDefinition.d.ts +6 -0
- package/model-function/generate-json/SchemaDefinition.js +1 -0
- package/model-function/generate-json/SchemaValidationError.cjs +36 -0
- package/model-function/generate-json/SchemaValidationError.d.ts +11 -0
- package/model-function/generate-json/SchemaValidationError.js +32 -0
- package/model-function/generate-json/generateJson.cjs +61 -0
- package/model-function/generate-json/generateJson.d.ts +9 -0
- package/model-function/generate-json/generateJson.js +57 -0
- package/model-function/generate-json/generateJsonOrText.cjs +74 -0
- package/model-function/generate-json/generateJsonOrText.d.ts +25 -0
- package/model-function/generate-json/generateJsonOrText.js +70 -0
- package/model-function/generate-text/AsyncQueue.cjs +66 -0
- package/model-function/generate-text/AsyncQueue.d.ts +17 -0
- package/model-function/generate-text/AsyncQueue.js +62 -0
- package/model-function/generate-text/DeltaEvent.cjs +2 -0
- package/model-function/generate-text/DeltaEvent.d.ts +7 -0
- package/model-function/generate-text/DeltaEvent.js +1 -0
- package/model-function/generate-text/TextDeltaEventSource.cjs +54 -0
- package/model-function/generate-text/TextDeltaEventSource.d.ts +5 -0
- package/model-function/generate-text/TextDeltaEventSource.js +46 -0
- package/model-function/generate-text/TextGenerationEvent.cjs +2 -0
- package/model-function/generate-text/TextGenerationEvent.d.ts +22 -0
- package/model-function/generate-text/TextGenerationEvent.js +1 -0
- package/model-function/generate-text/TextGenerationModel.cjs +2 -0
- package/model-function/generate-text/TextGenerationModel.d.ts +42 -0
- package/model-function/generate-text/TextGenerationModel.js +1 -0
- package/model-function/generate-text/TextStreamingEvent.cjs +2 -0
- package/model-function/generate-text/TextStreamingEvent.d.ts +22 -0
- package/model-function/generate-text/TextStreamingEvent.js +1 -0
- package/model-function/generate-text/extractTextDeltas.cjs +23 -0
- package/model-function/generate-text/extractTextDeltas.d.ts +7 -0
- package/model-function/generate-text/extractTextDeltas.js +19 -0
- package/model-function/generate-text/generateText.cjs +67 -0
- package/model-function/generate-text/generateText.d.ts +20 -0
- package/model-function/generate-text/generateText.js +63 -0
- package/model-function/generate-text/parseEventSourceReadableStream.cjs +30 -0
- package/model-function/generate-text/parseEventSourceReadableStream.d.ts +8 -0
- package/model-function/generate-text/parseEventSourceReadableStream.js +26 -0
- package/model-function/generate-text/streamText.cjs +115 -0
- package/model-function/generate-text/streamText.d.ts +11 -0
- package/model-function/generate-text/streamText.js +111 -0
- package/model-function/index.cjs +47 -0
- package/model-function/index.d.ts +31 -0
- package/model-function/index.js +31 -0
- package/model-function/tokenize-text/Tokenizer.cjs +2 -0
- package/model-function/tokenize-text/Tokenizer.d.ts +19 -0
- package/model-function/tokenize-text/Tokenizer.js +1 -0
- package/model-function/tokenize-text/countTokens.cjs +10 -0
- package/model-function/tokenize-text/countTokens.d.ts +5 -0
- package/model-function/tokenize-text/countTokens.js +6 -0
- package/model-function/transcribe-audio/TranscriptionEvent.cjs +2 -0
- package/model-function/transcribe-audio/TranscriptionEvent.d.ts +22 -0
- package/model-function/transcribe-audio/TranscriptionEvent.js +1 -0
- package/model-function/transcribe-audio/TranscriptionModel.cjs +2 -0
- package/model-function/transcribe-audio/TranscriptionModel.d.ts +8 -0
- package/model-function/transcribe-audio/TranscriptionModel.js +1 -0
- package/model-function/transcribe-audio/transcribe.cjs +62 -0
- package/model-function/transcribe-audio/transcribe.d.ts +22 -0
- package/model-function/transcribe-audio/transcribe.js +58 -0
- package/model-provider/automatic1111/Automatic1111Error.cjs +39 -0
- package/model-provider/automatic1111/Automatic1111Error.d.ts +31 -0
- package/model-provider/automatic1111/Automatic1111Error.js +31 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +76 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +54 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +72 -0
- package/model-provider/automatic1111/index.cjs +20 -0
- package/model-provider/automatic1111/index.d.ts +2 -0
- package/model-provider/automatic1111/index.js +2 -0
- package/model-provider/cohere/CohereError.cjs +36 -0
- package/model-provider/cohere/CohereError.d.ts +22 -0
- package/model-provider/cohere/CohereError.js +28 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +172 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +119 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.js +165 -0
- package/model-provider/cohere/CohereTextGenerationModel.cjs +283 -0
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +203 -0
- package/model-provider/cohere/CohereTextGenerationModel.js +276 -0
- package/model-provider/cohere/CohereTokenizer.cjs +136 -0
- package/model-provider/cohere/CohereTokenizer.d.ts +118 -0
- package/model-provider/cohere/CohereTokenizer.js +129 -0
- package/model-provider/cohere/index.cjs +22 -0
- package/model-provider/cohere/index.d.ts +4 -0
- package/model-provider/cohere/index.js +4 -0
- package/model-provider/huggingface/HuggingFaceError.cjs +52 -0
- package/model-provider/huggingface/HuggingFaceError.d.ts +22 -0
- package/model-provider/huggingface/HuggingFaceError.js +44 -0
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +174 -0
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +75 -0
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +167 -0
- package/model-provider/huggingface/index.cjs +20 -0
- package/model-provider/huggingface/index.d.ts +2 -0
- package/model-provider/huggingface/index.js +2 -0
- package/model-provider/index.cjs +22 -0
- package/model-provider/index.d.ts +6 -0
- package/model-provider/index.js +6 -0
- package/model-provider/llamacpp/LlamaCppError.cjs +52 -0
- package/model-provider/llamacpp/LlamaCppError.d.ts +22 -0
- package/model-provider/llamacpp/LlamaCppError.js +44 -0
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +96 -0
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +40 -0
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +89 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +245 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +399 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +238 -0
- package/model-provider/llamacpp/LlamaCppTokenizer.cjs +64 -0
- package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +38 -0
- package/model-provider/llamacpp/LlamaCppTokenizer.js +57 -0
- package/model-provider/llamacpp/index.cjs +22 -0
- package/model-provider/llamacpp/index.d.ts +4 -0
- package/model-provider/llamacpp/index.js +4 -0
- package/model-provider/openai/OpenAICostCalculator.cjs +71 -0
- package/model-provider/openai/OpenAICostCalculator.d.ts +6 -0
- package/model-provider/openai/OpenAICostCalculator.js +67 -0
- package/model-provider/openai/OpenAIError.cjs +50 -0
- package/model-provider/openai/OpenAIError.d.ts +47 -0
- package/model-provider/openai/OpenAIError.js +42 -0
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +124 -0
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +113 -0
- package/model-provider/openai/OpenAIImageGenerationModel.js +119 -0
- package/model-provider/openai/OpenAIModelSettings.cjs +2 -0
- package/model-provider/openai/OpenAIModelSettings.d.ts +8 -0
- package/model-provider/openai/OpenAIModelSettings.js +1 -0
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +171 -0
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +122 -0
- package/model-provider/openai/OpenAITextEmbeddingModel.js +162 -0
- package/model-provider/openai/OpenAITextGenerationModel.cjs +326 -0
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +254 -0
- package/model-provider/openai/OpenAITextGenerationModel.js +317 -0
- package/model-provider/openai/OpenAITranscriptionModel.cjs +195 -0
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +196 -0
- package/model-provider/openai/OpenAITranscriptionModel.js +187 -0
- package/model-provider/openai/TikTokenTokenizer.cjs +86 -0
- package/model-provider/openai/TikTokenTokenizer.d.ts +35 -0
- package/model-provider/openai/TikTokenTokenizer.js +82 -0
- package/model-provider/openai/chat/OpenAIChatMessage.cjs +24 -0
- package/model-provider/openai/chat/OpenAIChatMessage.d.ts +26 -0
- package/model-provider/openai/chat/OpenAIChatMessage.js +21 -0
- package/model-provider/openai/chat/OpenAIChatModel.cjs +288 -0
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +344 -0
- package/model-provider/openai/chat/OpenAIChatModel.js +279 -0
- package/model-provider/openai/chat/OpenAIChatPrompt.cjs +143 -0
- package/model-provider/openai/chat/OpenAIChatPrompt.d.ts +108 -0
- package/model-provider/openai/chat/OpenAIChatPrompt.js +135 -0
- package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +112 -0
- package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +19 -0
- package/model-provider/openai/chat/OpenAIChatStreamIterable.js +105 -0
- package/model-provider/openai/chat/countOpenAIChatMessageTokens.cjs +28 -0
- package/model-provider/openai/chat/countOpenAIChatMessageTokens.d.ts +20 -0
- package/model-provider/openai/chat/countOpenAIChatMessageTokens.js +23 -0
- package/model-provider/openai/index.cjs +31 -0
- package/model-provider/openai/index.d.ts +13 -0
- package/model-provider/openai/index.js +12 -0
- package/model-provider/stability/StabilityError.cjs +36 -0
- package/model-provider/stability/StabilityError.d.ts +22 -0
- package/model-provider/stability/StabilityError.js +28 -0
- package/model-provider/stability/StabilityImageGenerationModel.cjs +133 -0
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +95 -0
- package/model-provider/stability/StabilityImageGenerationModel.js +129 -0
- package/model-provider/stability/index.cjs +20 -0
- package/model-provider/stability/index.d.ts +2 -0
- package/model-provider/stability/index.js +2 -0
- package/package.json +87 -0
- package/prompt/InstructionPrompt.cjs +2 -0
- package/prompt/InstructionPrompt.d.ts +7 -0
- package/prompt/InstructionPrompt.js +1 -0
- package/prompt/Llama2PromptMapping.cjs +56 -0
- package/prompt/Llama2PromptMapping.d.ts +10 -0
- package/prompt/Llama2PromptMapping.js +51 -0
- package/prompt/OpenAIChatPromptMapping.cjs +62 -0
- package/prompt/OpenAIChatPromptMapping.d.ts +6 -0
- package/prompt/OpenAIChatPromptMapping.js +57 -0
- package/prompt/PromptMapping.cjs +2 -0
- package/prompt/PromptMapping.d.ts +7 -0
- package/prompt/PromptMapping.js +1 -0
- package/prompt/PromptMappingTextGenerationModel.cjs +88 -0
- package/prompt/PromptMappingTextGenerationModel.d.ts +26 -0
- package/prompt/PromptMappingTextGenerationModel.js +84 -0
- package/prompt/TextPromptMapping.cjs +50 -0
- package/prompt/TextPromptMapping.d.ts +14 -0
- package/prompt/TextPromptMapping.js +45 -0
- package/prompt/chat/ChatPrompt.cjs +2 -0
- package/prompt/chat/ChatPrompt.d.ts +33 -0
- package/prompt/chat/ChatPrompt.js +1 -0
- package/prompt/chat/trimChatPrompt.cjs +50 -0
- package/prompt/chat/trimChatPrompt.d.ts +19 -0
- package/prompt/chat/trimChatPrompt.js +46 -0
- package/prompt/chat/validateChatPrompt.cjs +36 -0
- package/prompt/chat/validateChatPrompt.d.ts +8 -0
- package/prompt/chat/validateChatPrompt.js +31 -0
- package/prompt/index.cjs +25 -0
- package/prompt/index.d.ts +9 -0
- package/prompt/index.js +9 -0
- package/run/ConsoleLogger.cjs +12 -0
- package/run/ConsoleLogger.d.ts +6 -0
- package/run/ConsoleLogger.js +8 -0
- package/run/DefaultRun.cjs +78 -0
- package/run/DefaultRun.d.ts +24 -0
- package/run/DefaultRun.js +74 -0
- package/run/IdMetadata.cjs +2 -0
- package/run/IdMetadata.d.ts +7 -0
- package/run/IdMetadata.js +1 -0
- package/run/Run.cjs +2 -0
- package/run/Run.d.ts +27 -0
- package/run/Run.js +1 -0
- package/run/RunFunction.cjs +2 -0
- package/run/RunFunction.d.ts +13 -0
- package/run/RunFunction.js +1 -0
- package/run/Vector.cjs +2 -0
- package/run/Vector.d.ts +5 -0
- package/run/Vector.js +1 -0
- package/run/index.cjs +22 -0
- package/run/index.d.ts +6 -0
- package/run/index.js +6 -0
- package/text-chunk/TextChunk.cjs +2 -0
- package/text-chunk/TextChunk.d.ts +3 -0
- package/text-chunk/TextChunk.js +1 -0
- package/text-chunk/index.cjs +22 -0
- package/text-chunk/index.d.ts +6 -0
- package/text-chunk/index.js +6 -0
- package/text-chunk/retrieve-text-chunks/TextChunkRetriever.cjs +2 -0
- package/text-chunk/retrieve-text-chunks/TextChunkRetriever.d.ts +8 -0
- package/text-chunk/retrieve-text-chunks/TextChunkRetriever.js +1 -0
- package/text-chunk/retrieve-text-chunks/retrieveTextChunks.cjs +10 -0
- package/text-chunk/retrieve-text-chunks/retrieveTextChunks.d.ts +6 -0
- package/text-chunk/retrieve-text-chunks/retrieveTextChunks.js +6 -0
- package/text-chunk/split/SplitFunction.cjs +2 -0
- package/text-chunk/split/SplitFunction.d.ts +4 -0
- package/text-chunk/split/SplitFunction.js +1 -0
- package/text-chunk/split/splitOnSeparator.cjs +12 -0
- package/text-chunk/split/splitOnSeparator.d.ts +8 -0
- package/text-chunk/split/splitOnSeparator.js +7 -0
- package/text-chunk/split/splitRecursively.cjs +41 -0
- package/text-chunk/split/splitRecursively.d.ts +22 -0
- package/text-chunk/split/splitRecursively.js +33 -0
- package/util/DurationMeasurement.cjs +42 -0
- package/util/DurationMeasurement.d.ts +5 -0
- package/util/DurationMeasurement.js +38 -0
- package/util/ErrorHandler.cjs +2 -0
- package/util/ErrorHandler.d.ts +1 -0
- package/util/ErrorHandler.js +1 -0
- package/util/SafeResult.cjs +2 -0
- package/util/SafeResult.d.ts +8 -0
- package/util/SafeResult.js +1 -0
- package/util/api/AbortError.cjs +9 -0
- package/util/api/AbortError.d.ts +3 -0
- package/util/api/AbortError.js +5 -0
- package/util/api/ApiCallError.cjs +45 -0
- package/util/api/ApiCallError.d.ts +15 -0
- package/util/api/ApiCallError.js +41 -0
- package/util/api/RetryError.cjs +24 -0
- package/util/api/RetryError.d.ts +10 -0
- package/util/api/RetryError.js +20 -0
- package/util/api/RetryFunction.cjs +2 -0
- package/util/api/RetryFunction.d.ts +1 -0
- package/util/api/RetryFunction.js +1 -0
- package/util/api/ThrottleFunction.cjs +2 -0
- package/util/api/ThrottleFunction.d.ts +1 -0
- package/util/api/ThrottleFunction.js +1 -0
- package/util/api/callWithRetryAndThrottle.cjs +7 -0
- package/util/api/callWithRetryAndThrottle.d.ts +7 -0
- package/util/api/callWithRetryAndThrottle.js +3 -0
- package/util/api/postToApi.cjs +103 -0
- package/util/api/postToApi.d.ts +29 -0
- package/util/api/postToApi.js +96 -0
- package/util/api/retryNever.cjs +8 -0
- package/util/api/retryNever.d.ts +4 -0
- package/util/api/retryNever.js +4 -0
- package/util/api/retryWithExponentialBackoff.cjs +48 -0
- package/util/api/retryWithExponentialBackoff.d.ts +10 -0
- package/util/api/retryWithExponentialBackoff.js +44 -0
- package/util/api/throttleMaxConcurrency.cjs +65 -0
- package/util/api/throttleMaxConcurrency.d.ts +7 -0
- package/util/api/throttleMaxConcurrency.js +61 -0
- package/util/api/throttleUnlimitedConcurrency.cjs +8 -0
- package/util/api/throttleUnlimitedConcurrency.d.ts +5 -0
- package/util/api/throttleUnlimitedConcurrency.js +4 -0
- package/util/cosineSimilarity.cjs +26 -0
- package/util/cosineSimilarity.d.ts +11 -0
- package/util/cosineSimilarity.js +22 -0
- package/util/index.cjs +26 -0
- package/util/index.d.ts +10 -0
- package/util/index.js +10 -0
- package/util/never.cjs +6 -0
- package/util/never.d.ts +1 -0
- package/util/never.js +2 -0
- package/util/runSafe.cjs +15 -0
- package/util/runSafe.d.ts +2 -0
- package/util/runSafe.js +11 -0
- package/vector-index/VectorIndex.cjs +2 -0
- package/vector-index/VectorIndex.d.ts +18 -0
- package/vector-index/VectorIndex.js +1 -0
- package/vector-index/VectorIndexSimilarTextChunkRetriever.cjs +57 -0
- package/vector-index/VectorIndexSimilarTextChunkRetriever.d.ts +20 -0
- package/vector-index/VectorIndexSimilarTextChunkRetriever.js +53 -0
- package/vector-index/VectorIndexTextChunkStore.cjs +77 -0
- package/vector-index/VectorIndexTextChunkStore.d.ts +35 -0
- package/vector-index/VectorIndexTextChunkStore.js +73 -0
- package/vector-index/index.cjs +22 -0
- package/vector-index/index.d.ts +6 -0
- package/vector-index/index.js +6 -0
- package/vector-index/memory/MemoryVectorIndex.cjs +63 -0
- package/vector-index/memory/MemoryVectorIndex.d.ts +31 -0
- package/vector-index/memory/MemoryVectorIndex.js +56 -0
- package/vector-index/pinecone/PineconeVectorIndex.cjs +66 -0
- package/vector-index/pinecone/PineconeVectorIndex.d.ts +29 -0
- package/vector-index/pinecone/PineconeVectorIndex.js +62 -0
- package/vector-index/upsertTextChunks.cjs +15 -0
- package/vector-index/upsertTextChunks.d.ts +11 -0
- package/vector-index/upsertTextChunks.js +11 -0
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ThrottleFunction } from "./ThrottleFunction.js";
|
2
|
+
/**
|
3
|
+
* The `throttleMaxConcurrency` strategy limits the number of parallel API calls.
|
4
|
+
*/
|
5
|
+
export declare function throttleMaxConcurrency({ maxConcurrentCalls, }: {
|
6
|
+
maxConcurrentCalls: number;
|
7
|
+
}): ThrottleFunction;
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class MaxConcurrencyThrottler {
|
2
|
+
constructor({ maxConcurrentCalls }) {
|
3
|
+
Object.defineProperty(this, "maxConcurrentCalls", {
|
4
|
+
enumerable: true,
|
5
|
+
configurable: true,
|
6
|
+
writable: true,
|
7
|
+
value: void 0
|
8
|
+
});
|
9
|
+
Object.defineProperty(this, "activeCallCount", {
|
10
|
+
enumerable: true,
|
11
|
+
configurable: true,
|
12
|
+
writable: true,
|
13
|
+
value: void 0
|
14
|
+
});
|
15
|
+
Object.defineProperty(this, "callQueue", {
|
16
|
+
enumerable: true,
|
17
|
+
configurable: true,
|
18
|
+
writable: true,
|
19
|
+
value: void 0
|
20
|
+
});
|
21
|
+
this.maxConcurrentCalls = maxConcurrentCalls;
|
22
|
+
this.activeCallCount = 0;
|
23
|
+
this.callQueue = [];
|
24
|
+
}
|
25
|
+
async run(fn) {
|
26
|
+
return new Promise((resolve, reject) => {
|
27
|
+
const tryExecute = async () => {
|
28
|
+
if (this.activeCallCount >= this.maxConcurrentCalls)
|
29
|
+
return;
|
30
|
+
// mark as active and remove from queue:
|
31
|
+
this.activeCallCount++;
|
32
|
+
const idx = this.callQueue.indexOf(tryExecute);
|
33
|
+
if (idx !== -1)
|
34
|
+
this.callQueue.splice(idx, 1);
|
35
|
+
try {
|
36
|
+
resolve(await fn());
|
37
|
+
}
|
38
|
+
catch (error) {
|
39
|
+
reject(error);
|
40
|
+
}
|
41
|
+
finally {
|
42
|
+
this.activeCallCount--;
|
43
|
+
if (this.callQueue.length > 0) {
|
44
|
+
this.callQueue[0]();
|
45
|
+
}
|
46
|
+
}
|
47
|
+
};
|
48
|
+
this.callQueue.push(tryExecute);
|
49
|
+
if (this.activeCallCount < this.maxConcurrentCalls) {
|
50
|
+
tryExecute();
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* The `throttleMaxConcurrency` strategy limits the number of parallel API calls.
|
57
|
+
*/
|
58
|
+
export function throttleMaxConcurrency({ maxConcurrentCalls, }) {
|
59
|
+
const throttler = new MaxConcurrencyThrottler({ maxConcurrentCalls });
|
60
|
+
return (fn) => throttler.run(fn);
|
61
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.throttleUnlimitedConcurrency = void 0;
|
4
|
+
/**
|
5
|
+
* The `throttleUnlimitedConcurrency` strategy does not limit parallel API calls.
|
6
|
+
*/
|
7
|
+
const throttleUnlimitedConcurrency = () => (fn) => fn();
|
8
|
+
exports.throttleUnlimitedConcurrency = throttleUnlimitedConcurrency;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.cosineSimilarity = void 0;
|
4
|
+
/**
|
5
|
+
* Calculates the cosine similarity between two vectors. They must have the same length.
|
6
|
+
*
|
7
|
+
* @param a The first vector.
|
8
|
+
* @param b The second vector.
|
9
|
+
*
|
10
|
+
* @returns The cosine similarity between the two vectors.
|
11
|
+
*
|
12
|
+
* @see https://en.wikipedia.org/wiki/Cosine_similarity
|
13
|
+
*/
|
14
|
+
function cosineSimilarity(a, b) {
|
15
|
+
if (a.length !== b.length) {
|
16
|
+
throw new Error(`Vectors must have the same length (a: ${a.length}, b: ${b.length})`);
|
17
|
+
}
|
18
|
+
return dotProduct(a, b) / (magnitude(a) * magnitude(b));
|
19
|
+
}
|
20
|
+
exports.cosineSimilarity = cosineSimilarity;
|
21
|
+
function dotProduct(a, b) {
|
22
|
+
return a.reduce((acc, val, i) => acc + val * b[i], 0);
|
23
|
+
}
|
24
|
+
function magnitude(a) {
|
25
|
+
return Math.sqrt(dotProduct(a, a));
|
26
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* Calculates the cosine similarity between two vectors. They must have the same length.
|
3
|
+
*
|
4
|
+
* @param a The first vector.
|
5
|
+
* @param b The second vector.
|
6
|
+
*
|
7
|
+
* @returns The cosine similarity between the two vectors.
|
8
|
+
*
|
9
|
+
* @see https://en.wikipedia.org/wiki/Cosine_similarity
|
10
|
+
*/
|
11
|
+
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* Calculates the cosine similarity between two vectors. They must have the same length.
|
3
|
+
*
|
4
|
+
* @param a The first vector.
|
5
|
+
* @param b The second vector.
|
6
|
+
*
|
7
|
+
* @returns The cosine similarity between the two vectors.
|
8
|
+
*
|
9
|
+
* @see https://en.wikipedia.org/wiki/Cosine_similarity
|
10
|
+
*/
|
11
|
+
export function cosineSimilarity(a, b) {
|
12
|
+
if (a.length !== b.length) {
|
13
|
+
throw new Error(`Vectors must have the same length (a: ${a.length}, b: ${b.length})`);
|
14
|
+
}
|
15
|
+
return dotProduct(a, b) / (magnitude(a) * magnitude(b));
|
16
|
+
}
|
17
|
+
function dotProduct(a, b) {
|
18
|
+
return a.reduce((acc, val, i) => acc + val * b[i], 0);
|
19
|
+
}
|
20
|
+
function magnitude(a) {
|
21
|
+
return Math.sqrt(dotProduct(a, a));
|
22
|
+
}
|
package/util/index.cjs
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./api/AbortError.cjs"), exports);
|
18
|
+
__exportStar(require("./api/ApiCallError.cjs"), exports);
|
19
|
+
__exportStar(require("./api/RetryError.cjs"), exports);
|
20
|
+
__exportStar(require("./api/RetryFunction.cjs"), exports);
|
21
|
+
__exportStar(require("./api/ThrottleFunction.cjs"), exports);
|
22
|
+
__exportStar(require("./api/retryNever.cjs"), exports);
|
23
|
+
__exportStar(require("./api/retryWithExponentialBackoff.cjs"), exports);
|
24
|
+
__exportStar(require("./api/throttleMaxConcurrency.cjs"), exports);
|
25
|
+
__exportStar(require("./api/throttleUnlimitedConcurrency.cjs"), exports);
|
26
|
+
__exportStar(require("./cosineSimilarity.cjs"), exports);
|
package/util/index.d.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
export * from "./api/AbortError.js";
|
2
|
+
export * from "./api/ApiCallError.js";
|
3
|
+
export * from "./api/RetryError.js";
|
4
|
+
export * from "./api/RetryFunction.js";
|
5
|
+
export * from "./api/ThrottleFunction.js";
|
6
|
+
export * from "./api/retryNever.js";
|
7
|
+
export * from "./api/retryWithExponentialBackoff.js";
|
8
|
+
export * from "./api/throttleMaxConcurrency.js";
|
9
|
+
export * from "./api/throttleUnlimitedConcurrency.js";
|
10
|
+
export * from "./cosineSimilarity.js";
|
package/util/index.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
export * from "./api/AbortError.js";
|
2
|
+
export * from "./api/ApiCallError.js";
|
3
|
+
export * from "./api/RetryError.js";
|
4
|
+
export * from "./api/RetryFunction.js";
|
5
|
+
export * from "./api/ThrottleFunction.js";
|
6
|
+
export * from "./api/retryNever.js";
|
7
|
+
export * from "./api/retryWithExponentialBackoff.js";
|
8
|
+
export * from "./api/throttleMaxConcurrency.js";
|
9
|
+
export * from "./api/throttleUnlimitedConcurrency.js";
|
10
|
+
export * from "./cosineSimilarity.js";
|
package/util/never.cjs
ADDED
package/util/never.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export declare function never(_: never): void;
|
package/util/never.js
ADDED
package/util/runSafe.cjs
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.runSafe = void 0;
|
4
|
+
const runSafe = async (f) => {
|
5
|
+
try {
|
6
|
+
return { ok: true, output: await f() };
|
7
|
+
}
|
8
|
+
catch (error) {
|
9
|
+
if (error instanceof Error && error.name === "AbortError") {
|
10
|
+
return { ok: false, isAborted: true };
|
11
|
+
}
|
12
|
+
return { ok: false, error };
|
13
|
+
}
|
14
|
+
};
|
15
|
+
exports.runSafe = runSafe;
|
package/util/runSafe.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
export const runSafe = async (f) => {
|
2
|
+
try {
|
3
|
+
return { ok: true, output: await f() };
|
4
|
+
}
|
5
|
+
catch (error) {
|
6
|
+
if (error instanceof Error && error.name === "AbortError") {
|
7
|
+
return { ok: false, isAborted: true };
|
8
|
+
}
|
9
|
+
return { ok: false, error };
|
10
|
+
}
|
11
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Vector } from "../run/Vector.js";
|
2
|
+
export interface VectorIndex<DATA, INDEX> {
|
3
|
+
upsertMany(data: Array<{
|
4
|
+
id: string;
|
5
|
+
vector: Vector;
|
6
|
+
data: DATA;
|
7
|
+
}>): Promise<void>;
|
8
|
+
queryByVector(options: {
|
9
|
+
queryVector: Vector;
|
10
|
+
maxResults: number;
|
11
|
+
similarityThreshold?: number;
|
12
|
+
}): Promise<Array<{
|
13
|
+
id: string;
|
14
|
+
data: DATA;
|
15
|
+
similarity?: number;
|
16
|
+
}>>;
|
17
|
+
asIndex(): INDEX;
|
18
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.VectorIndexSimilarTextChunkRetriever = void 0;
|
4
|
+
const embedText_js_1 = require("../model-function/embed-text/embedText.cjs");
|
5
|
+
class VectorIndexSimilarTextChunkRetriever {
|
6
|
+
constructor({ vectorIndex, embeddingModel, maxResults, similarityThreshold, }) {
|
7
|
+
Object.defineProperty(this, "vectorIndex", {
|
8
|
+
enumerable: true,
|
9
|
+
configurable: true,
|
10
|
+
writable: true,
|
11
|
+
value: void 0
|
12
|
+
});
|
13
|
+
Object.defineProperty(this, "embeddingModel", {
|
14
|
+
enumerable: true,
|
15
|
+
configurable: true,
|
16
|
+
writable: true,
|
17
|
+
value: void 0
|
18
|
+
});
|
19
|
+
Object.defineProperty(this, "settings", {
|
20
|
+
enumerable: true,
|
21
|
+
configurable: true,
|
22
|
+
writable: true,
|
23
|
+
value: void 0
|
24
|
+
});
|
25
|
+
this.vectorIndex = vectorIndex;
|
26
|
+
this.embeddingModel = embeddingModel;
|
27
|
+
this.settings = {
|
28
|
+
maxResults,
|
29
|
+
similarityThreshold,
|
30
|
+
};
|
31
|
+
}
|
32
|
+
async retrieveTextChunks(query, options) {
|
33
|
+
if (options?.settings != null) {
|
34
|
+
return this.withSettings(options.settings).retrieveTextChunks(query, {
|
35
|
+
functionId: options.functionId,
|
36
|
+
run: options.run,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
const { embedding } = await (0, embedText_js_1.embedText)(this.embeddingModel, query, {
|
40
|
+
functionId: options?.functionId,
|
41
|
+
run: options?.run,
|
42
|
+
});
|
43
|
+
const queryResult = await this.vectorIndex.queryByVector({
|
44
|
+
queryVector: embedding,
|
45
|
+
maxResults: this.settings.maxResults ?? 1,
|
46
|
+
similarityThreshold: this.settings.similarityThreshold,
|
47
|
+
});
|
48
|
+
return queryResult.map((item) => item.data);
|
49
|
+
}
|
50
|
+
withSettings(additionalSettings) {
|
51
|
+
return new VectorIndexSimilarTextChunkRetriever(Object.assign({}, this.settings, additionalSettings, {
|
52
|
+
vectorIndex: this.vectorIndex,
|
53
|
+
embeddingModel: this.embeddingModel,
|
54
|
+
}));
|
55
|
+
}
|
56
|
+
}
|
57
|
+
exports.VectorIndexSimilarTextChunkRetriever = VectorIndexSimilarTextChunkRetriever;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { FunctionOptions } from "../model-function/FunctionOptions.js";
|
2
|
+
import { TextEmbeddingModel, TextEmbeddingModelSettings } from "../model-function/embed-text/TextEmbeddingModel.js";
|
3
|
+
import { TextChunk } from "../text-chunk/TextChunk.js";
|
4
|
+
import { TextChunkRetriever, TextChunkRetrieverSettings } from "../text-chunk/retrieve-text-chunks/TextChunkRetriever.js";
|
5
|
+
import { VectorIndex } from "./VectorIndex.js";
|
6
|
+
export interface VectorIndexTextChunkRetrieverSettings {
|
7
|
+
maxResults?: number;
|
8
|
+
similarityThreshold?: number;
|
9
|
+
}
|
10
|
+
export declare class VectorIndexSimilarTextChunkRetriever<CHUNK extends TextChunk, INDEX, SETTINGS extends TextEmbeddingModelSettings> implements TextChunkRetriever<CHUNK, string, VectorIndexTextChunkRetrieverSettings> {
|
11
|
+
private readonly vectorIndex;
|
12
|
+
private readonly embeddingModel;
|
13
|
+
private readonly settings;
|
14
|
+
constructor({ vectorIndex, embeddingModel, maxResults, similarityThreshold, }: {
|
15
|
+
vectorIndex: VectorIndex<CHUNK, INDEX>;
|
16
|
+
embeddingModel: TextEmbeddingModel<unknown, SETTINGS>;
|
17
|
+
} & VectorIndexTextChunkRetrieverSettings);
|
18
|
+
retrieveTextChunks(query: string, options?: FunctionOptions<TextChunkRetrieverSettings>): Promise<CHUNK[]>;
|
19
|
+
withSettings(additionalSettings: Partial<VectorIndexTextChunkRetrieverSettings>): this;
|
20
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { embedText } from "../model-function/embed-text/embedText.js";
|
2
|
+
export class VectorIndexSimilarTextChunkRetriever {
|
3
|
+
constructor({ vectorIndex, embeddingModel, maxResults, similarityThreshold, }) {
|
4
|
+
Object.defineProperty(this, "vectorIndex", {
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true,
|
8
|
+
value: void 0
|
9
|
+
});
|
10
|
+
Object.defineProperty(this, "embeddingModel", {
|
11
|
+
enumerable: true,
|
12
|
+
configurable: true,
|
13
|
+
writable: true,
|
14
|
+
value: void 0
|
15
|
+
});
|
16
|
+
Object.defineProperty(this, "settings", {
|
17
|
+
enumerable: true,
|
18
|
+
configurable: true,
|
19
|
+
writable: true,
|
20
|
+
value: void 0
|
21
|
+
});
|
22
|
+
this.vectorIndex = vectorIndex;
|
23
|
+
this.embeddingModel = embeddingModel;
|
24
|
+
this.settings = {
|
25
|
+
maxResults,
|
26
|
+
similarityThreshold,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
async retrieveTextChunks(query, options) {
|
30
|
+
if (options?.settings != null) {
|
31
|
+
return this.withSettings(options.settings).retrieveTextChunks(query, {
|
32
|
+
functionId: options.functionId,
|
33
|
+
run: options.run,
|
34
|
+
});
|
35
|
+
}
|
36
|
+
const { embedding } = await embedText(this.embeddingModel, query, {
|
37
|
+
functionId: options?.functionId,
|
38
|
+
run: options?.run,
|
39
|
+
});
|
40
|
+
const queryResult = await this.vectorIndex.queryByVector({
|
41
|
+
queryVector: embedding,
|
42
|
+
maxResults: this.settings.maxResults ?? 1,
|
43
|
+
similarityThreshold: this.settings.similarityThreshold,
|
44
|
+
});
|
45
|
+
return queryResult.map((item) => item.data);
|
46
|
+
}
|
47
|
+
withSettings(additionalSettings) {
|
48
|
+
return new VectorIndexSimilarTextChunkRetriever(Object.assign({}, this.settings, additionalSettings, {
|
49
|
+
vectorIndex: this.vectorIndex,
|
50
|
+
embeddingModel: this.embeddingModel,
|
51
|
+
}));
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.VectorIndexTextChunkStore = void 0;
|
4
|
+
const nanoid_1 = require("nanoid");
|
5
|
+
const embedText_js_1 = require("../model-function/embed-text/embedText.cjs");
|
6
|
+
class VectorIndexTextChunkStore {
|
7
|
+
constructor({ index, generateId = nanoid_1.nanoid, embeddingModel, queryFunctionId, upsertFunctionId, }) {
|
8
|
+
Object.defineProperty(this, "_index", {
|
9
|
+
enumerable: true,
|
10
|
+
configurable: true,
|
11
|
+
writable: true,
|
12
|
+
value: void 0
|
13
|
+
});
|
14
|
+
Object.defineProperty(this, "generateId", {
|
15
|
+
enumerable: true,
|
16
|
+
configurable: true,
|
17
|
+
writable: true,
|
18
|
+
value: void 0
|
19
|
+
});
|
20
|
+
Object.defineProperty(this, "embeddingModel", {
|
21
|
+
enumerable: true,
|
22
|
+
configurable: true,
|
23
|
+
writable: true,
|
24
|
+
value: void 0
|
25
|
+
});
|
26
|
+
Object.defineProperty(this, "queryFunctionId", {
|
27
|
+
enumerable: true,
|
28
|
+
configurable: true,
|
29
|
+
writable: true,
|
30
|
+
value: void 0
|
31
|
+
});
|
32
|
+
Object.defineProperty(this, "upsertFunctionId", {
|
33
|
+
enumerable: true,
|
34
|
+
configurable: true,
|
35
|
+
writable: true,
|
36
|
+
value: void 0
|
37
|
+
});
|
38
|
+
this._index = index;
|
39
|
+
this.generateId = generateId;
|
40
|
+
this.embeddingModel = embeddingModel;
|
41
|
+
this.queryFunctionId = queryFunctionId;
|
42
|
+
this.upsertFunctionId = upsertFunctionId;
|
43
|
+
}
|
44
|
+
async upsertChunk({ id = this.generateId(), chunk, }, options) {
|
45
|
+
this.upsertManyChunks({
|
46
|
+
ids: [id],
|
47
|
+
chunks: [chunk],
|
48
|
+
}, options);
|
49
|
+
}
|
50
|
+
async upsertManyChunks({ ids, chunks, }, options) {
|
51
|
+
const { embeddings } = await (0, embedText_js_1.embedTexts)(this.embeddingModel, chunks.map((chunk) => chunk.content), {
|
52
|
+
functionId: this.upsertFunctionId,
|
53
|
+
run: options?.run,
|
54
|
+
});
|
55
|
+
this._index.upsertMany(embeddings.map((embedding, i) => ({
|
56
|
+
id: ids?.[i] ?? this.generateId(),
|
57
|
+
vector: embedding,
|
58
|
+
data: chunks[i],
|
59
|
+
})));
|
60
|
+
}
|
61
|
+
async retrieveSimilarTextChunks(queryText, options) {
|
62
|
+
const { embedding } = await (0, embedText_js_1.embedText)(this.embeddingModel, queryText, {
|
63
|
+
functionId: this.queryFunctionId,
|
64
|
+
run: options?.run,
|
65
|
+
});
|
66
|
+
const queryResult = await this._index.queryByVector({
|
67
|
+
queryVector: embedding,
|
68
|
+
maxResults: 1,
|
69
|
+
similarityThreshold: undefined,
|
70
|
+
});
|
71
|
+
return queryResult.map((item) => item.data);
|
72
|
+
}
|
73
|
+
get index() {
|
74
|
+
return this._index.asIndex();
|
75
|
+
}
|
76
|
+
}
|
77
|
+
exports.VectorIndexTextChunkStore = VectorIndexTextChunkStore;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { TextEmbeddingModel, TextEmbeddingModelSettings } from "../model-function/embed-text/TextEmbeddingModel.js";
|
2
|
+
import { Run } from "../run/Run.js";
|
3
|
+
import { TextChunk } from "../text-chunk/TextChunk.js";
|
4
|
+
import { TextChunkRetrieverSettings } from "../text-chunk/retrieve-text-chunks/TextChunkRetriever.js";
|
5
|
+
import { VectorIndex } from "./VectorIndex.js";
|
6
|
+
import { FunctionOptions } from "../model-function/FunctionOptions.js";
|
7
|
+
export declare class VectorIndexTextChunkStore<CHUNK extends TextChunk, INDEX, MODEL extends TextEmbeddingModel<unknown, TextEmbeddingModelSettings>> {
|
8
|
+
private readonly _index;
|
9
|
+
private readonly generateId;
|
10
|
+
private readonly embeddingModel;
|
11
|
+
private readonly queryFunctionId?;
|
12
|
+
private readonly upsertFunctionId?;
|
13
|
+
constructor({ index, generateId, embeddingModel, queryFunctionId, upsertFunctionId, }: {
|
14
|
+
index: VectorIndex<CHUNK, INDEX>;
|
15
|
+
generateId?: () => string;
|
16
|
+
embeddingModel: MODEL;
|
17
|
+
queryFunctionId?: string;
|
18
|
+
upsertFunctionId?: string;
|
19
|
+
});
|
20
|
+
upsertChunk({ id, chunk, }: {
|
21
|
+
id?: string;
|
22
|
+
keyText: string;
|
23
|
+
chunk: CHUNK;
|
24
|
+
}, options?: {
|
25
|
+
run?: Run;
|
26
|
+
}): Promise<void>;
|
27
|
+
upsertManyChunks({ ids, chunks, }: {
|
28
|
+
ids?: Array<string | undefined>;
|
29
|
+
chunks: CHUNK[];
|
30
|
+
}, options?: {
|
31
|
+
run?: Run;
|
32
|
+
}): Promise<void>;
|
33
|
+
retrieveSimilarTextChunks(queryText: string, options?: FunctionOptions<TextChunkRetrieverSettings> | undefined): Promise<CHUNK[]>;
|
34
|
+
get index(): INDEX;
|
35
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { nanoid as createId } from "nanoid";
|
2
|
+
import { embedText, embedTexts, } from "../model-function/embed-text/embedText.js";
|
3
|
+
export class VectorIndexTextChunkStore {
|
4
|
+
constructor({ index, generateId = createId, embeddingModel, queryFunctionId, upsertFunctionId, }) {
|
5
|
+
Object.defineProperty(this, "_index", {
|
6
|
+
enumerable: true,
|
7
|
+
configurable: true,
|
8
|
+
writable: true,
|
9
|
+
value: void 0
|
10
|
+
});
|
11
|
+
Object.defineProperty(this, "generateId", {
|
12
|
+
enumerable: true,
|
13
|
+
configurable: true,
|
14
|
+
writable: true,
|
15
|
+
value: void 0
|
16
|
+
});
|
17
|
+
Object.defineProperty(this, "embeddingModel", {
|
18
|
+
enumerable: true,
|
19
|
+
configurable: true,
|
20
|
+
writable: true,
|
21
|
+
value: void 0
|
22
|
+
});
|
23
|
+
Object.defineProperty(this, "queryFunctionId", {
|
24
|
+
enumerable: true,
|
25
|
+
configurable: true,
|
26
|
+
writable: true,
|
27
|
+
value: void 0
|
28
|
+
});
|
29
|
+
Object.defineProperty(this, "upsertFunctionId", {
|
30
|
+
enumerable: true,
|
31
|
+
configurable: true,
|
32
|
+
writable: true,
|
33
|
+
value: void 0
|
34
|
+
});
|
35
|
+
this._index = index;
|
36
|
+
this.generateId = generateId;
|
37
|
+
this.embeddingModel = embeddingModel;
|
38
|
+
this.queryFunctionId = queryFunctionId;
|
39
|
+
this.upsertFunctionId = upsertFunctionId;
|
40
|
+
}
|
41
|
+
async upsertChunk({ id = this.generateId(), chunk, }, options) {
|
42
|
+
this.upsertManyChunks({
|
43
|
+
ids: [id],
|
44
|
+
chunks: [chunk],
|
45
|
+
}, options);
|
46
|
+
}
|
47
|
+
async upsertManyChunks({ ids, chunks, }, options) {
|
48
|
+
const { embeddings } = await embedTexts(this.embeddingModel, chunks.map((chunk) => chunk.content), {
|
49
|
+
functionId: this.upsertFunctionId,
|
50
|
+
run: options?.run,
|
51
|
+
});
|
52
|
+
this._index.upsertMany(embeddings.map((embedding, i) => ({
|
53
|
+
id: ids?.[i] ?? this.generateId(),
|
54
|
+
vector: embedding,
|
55
|
+
data: chunks[i],
|
56
|
+
})));
|
57
|
+
}
|
58
|
+
async retrieveSimilarTextChunks(queryText, options) {
|
59
|
+
const { embedding } = await embedText(this.embeddingModel, queryText, {
|
60
|
+
functionId: this.queryFunctionId,
|
61
|
+
run: options?.run,
|
62
|
+
});
|
63
|
+
const queryResult = await this._index.queryByVector({
|
64
|
+
queryVector: embedding,
|
65
|
+
maxResults: 1,
|
66
|
+
similarityThreshold: undefined,
|
67
|
+
});
|
68
|
+
return queryResult.map((item) => item.data);
|
69
|
+
}
|
70
|
+
get index() {
|
71
|
+
return this._index.asIndex();
|
72
|
+
}
|
73
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./VectorIndex.cjs"), exports);
|
18
|
+
__exportStar(require("./VectorIndexSimilarTextChunkRetriever.cjs"), exports);
|
19
|
+
__exportStar(require("./VectorIndexTextChunkStore.cjs"), exports);
|
20
|
+
__exportStar(require("./memory/MemoryVectorIndex.cjs"), exports);
|
21
|
+
__exportStar(require("./pinecone/PineconeVectorIndex.cjs"), exports);
|
22
|
+
__exportStar(require("./upsertTextChunks.cjs"), exports);
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export * from "./VectorIndex.js";
|
2
|
+
export * from "./VectorIndexSimilarTextChunkRetriever.js";
|
3
|
+
export * from "./VectorIndexTextChunkStore.js";
|
4
|
+
export * from "./memory/MemoryVectorIndex.js";
|
5
|
+
export * from "./pinecone/PineconeVectorIndex.js";
|
6
|
+
export * from "./upsertTextChunks.js";
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export * from "./VectorIndex.js";
|
2
|
+
export * from "./VectorIndexSimilarTextChunkRetriever.js";
|
3
|
+
export * from "./VectorIndexTextChunkStore.js";
|
4
|
+
export * from "./memory/MemoryVectorIndex.js";
|
5
|
+
export * from "./pinecone/PineconeVectorIndex.js";
|
6
|
+
export * from "./upsertTextChunks.js";
|