From 78b4906f7af27a43336995dac4a4238cc787c176 Mon Sep 17 00:00:00 2001 From: buua436 Date: Wed, 17 Jun 2026 14:18:02 +0800 Subject: [PATCH] fix: tighten embedding truncation threshold (#16123) ### What problem does this PR solve? Use a 95% max_length threshold before truncating embedding inputs, which reduces the chance of provider-side invalid-parameter errors on near-limit chunks. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/db/services/llm_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/db/services/llm_service.py b/api/db/services/llm_service.py index 02852fa137..f651729806 100644 --- a/api/db/services/llm_service.py +++ b/api/db/services/llm_service.py @@ -137,7 +137,7 @@ class LLMBundle(LLM4Tenant): safe_texts.append("None") continue token_size = num_tokens_from_string(text) - if token_size > self.max_length: + if token_size > self.max_length * 0.95: target_len = int(self.max_length * 0.95) safe_texts.append(text[:target_len]) else: