From a7f6003277143c25f838ae26165d9a8a5fb69f50 Mon Sep 17 00:00:00 2001 From: timothycarambat <rambat1010@gmail.com> Date: Tue, 19 Dec 2023 16:20:34 -0800 Subject: [PATCH] fix: set lower maxChunk limit on native embedder to stay within resource constraints chore: update comment for what embedding chunk means --- server/utils/EmbeddingEngines/azureOpenAi/index.js | 2 +- server/utils/EmbeddingEngines/localAi/index.js | 2 +- server/utils/EmbeddingEngines/native/index.js | 4 ++-- server/utils/EmbeddingEngines/openAi/index.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/utils/EmbeddingEngines/azureOpenAi/index.js b/server/utils/EmbeddingEngines/azureOpenAi/index.js index 8959b0007..3f36b576b 100644 --- a/server/utils/EmbeddingEngines/azureOpenAi/index.js +++ b/server/utils/EmbeddingEngines/azureOpenAi/index.js @@ -14,7 +14,7 @@ class AzureOpenAiEmbedder { ); this.openai = openai; - // The maximum amount of "inputs" that OpenAI API can process in a single call. + // Limit of how many strings we can process in a single pass to stay with resource or network limits // https://learn.microsoft.com/en-us/azure/ai-services/openai/faq#i-am-trying-to-use-embeddings-and-received-the-error--invalidrequesterror--too-many-inputs--the-max-number-of-inputs-is-1---how-do-i-fix-this-:~:text=consisting%20of%20up%20to%2016%20inputs%20per%20API%20request this.embeddingMaxChunkLength = 16; } diff --git a/server/utils/EmbeddingEngines/localAi/index.js b/server/utils/EmbeddingEngines/localAi/index.js index 0f43cc7dc..68fe66544 100644 --- a/server/utils/EmbeddingEngines/localAi/index.js +++ b/server/utils/EmbeddingEngines/localAi/index.js @@ -17,7 +17,7 @@ class LocalAiEmbedder { }); this.openai = new OpenAIApi(config); - // Arbitrary limit of string size in chars to ensure we stay within reasonable POST request size. + // Limit of how many strings we can process in a single pass to stay with resource or network limits this.embeddingMaxChunkLength = maximumChunkLength(); } diff --git a/server/utils/EmbeddingEngines/native/index.js b/server/utils/EmbeddingEngines/native/index.js index 2081e3fde..81189d4e2 100644 --- a/server/utils/EmbeddingEngines/native/index.js +++ b/server/utils/EmbeddingEngines/native/index.js @@ -13,8 +13,8 @@ class NativeEmbedder { ); this.modelPath = path.resolve(this.cacheDir, "Xenova", "all-MiniLM-L6-v2"); - // Arbitrary limit of string size in chars to ensure we stay within reasonable POST request size. - this.embeddingMaxChunkLength = 1_000; + // Limit of how many strings we can process in a single pass to stay with resource or network limits + this.embeddingMaxChunkLength = 50; // Make directory when it does not exist in existing installations if (!fs.existsSync(this.cacheDir)) fs.mkdirSync(this.cacheDir); diff --git a/server/utils/EmbeddingEngines/openAi/index.js b/server/utils/EmbeddingEngines/openAi/index.js index 8cfa23516..6ba38c898 100644 --- a/server/utils/EmbeddingEngines/openAi/index.js +++ b/server/utils/EmbeddingEngines/openAi/index.js @@ -10,7 +10,7 @@ class OpenAiEmbedder { const openai = new OpenAIApi(config); this.openai = openai; - // Arbitrary limit of string size in chars to ensure we stay within reasonable POST request size. + // Limit of how many strings we can process in a single pass to stay with resource or network limits this.embeddingMaxChunkLength = 1_000; } -- GitLab