Modify budget calculation for text limit safety margin

Adjust budget calculation to use 92% margin for token estimation.
This commit is contained in:
jinliyl 2026-07-14 11:05:08 +08:00 committed by GitHub
parent 07d4527a0d
commit b5e0ec2d8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -46,7 +46,7 @@ class BaseEmbeddingStore(BaseComponent):
return text[:limit]
# Reserve a 5% safety margin for token estimation.
budget = limit * 2 * 95 // 100
budget = limit * 2 * 92 // 100
used = 0
for index, char in enumerate(text):
used += 3 if unicodedata.east_asian_width(char) in {"W", "F"} else 2