mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #1533] [Feature]: Add tokenizer-backed estimates for lorebook and knowledge budgets #777
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#777
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Xelvanis on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1533
Originally assigned to: @SpicyMarinara on GitHub.
What problem does this solve?
Lorebook prompt injection and agent knowledge retrieval still use rough character-count token estimates. That can mis-budget prompts for Unicode/multibyte text and boundary cases.
Proposed behavior
Add a tokenizer-backed estimation path when tokenizer support is available, with regression coverage for Unicode/multibyte text, boundary strings, and budget behavior across lorebook and knowledge retrieval paths.
Expected owner or impact area
Refactor branch considerations
Known heuristic sites from the local audit:
src/engine/generation-core/lorebooks/prompt-injector.tsestimates tokens fromtotalChars / 4.src/engine/agents-runtime/knowledge/knowledge-retrieval.tsusesMath.ceil(text.length / 4).Keep this in React-free engine code and avoid pulling UI/provider dependencies into the estimator.
Alternatives considered
Keep the current heuristic until tokenizer support exists, but keep the limitation publicly tracked so prompt-budget bugs are easier to triage.
Additional context
Low priority unless prompt-budget behavior starts causing visible truncation or retrieval-quality failures.
Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:
@cha1latte commented on GitHub (May 29, 2026):
Triage note: labeling this as
scope-riskbecause tokenizer-backed estimates affect lorebook activation and agent knowledge budget contracts across prompt assembly paths.A good next step is to choose the tokenizer availability/fallback contract and test Unicode plus boundary cases before replacing rough estimates.
@SpicyMarinara commented on GitHub (Jun 1, 2026):
We would need to include tokenizers with our files for that. I, in all honesty, have no clue where to find the updated ones for models such as new GPTs or Gemini. I don't think they're even released.
@SpicyMarinara commented on GitHub (Jun 1, 2026):
Closed as not planned for the refactor branch for now. Added docs/token-budget-estimates.md and linked it from the README to record the current heuristic-estimate behavior, why provider-exact tokenizer bundles are not safe to add without maintained model-family assets, and the requirements for a future tokenizer-backed implementation.