v4 tokenizer truncates every embedding input to 128 tokens
Describe the bug
The v4 tokenizer file (tokenizer.json in Zeolit/lettuce-emb-768d-v4, stored as v4-tokenizer.json) contains:
"truncation": { "direction": "Right", "max_length": 128, "strategy": "LongestFirst", "stride": 0 }
Tokenizer::from_file keeps this setting, and compute_embedding_with_session does not override it. Every input is therefore cut to 128 tokens before the app applies max_seq_length, which is resolved from embeddingMaxTokens and clamped to 512–4096. The embedding max tokens setting has no effect.
This matters most for memory retrieval with context enrichment. build_enriched_query builds the query as second_last + "\n" + last. With right-side truncation at 128 tokens, a previous reply of about 800 characters already pushes the newest message out of the query completely:
| previous reply | query tokens | newest message kept |
|---|---|---|
| 828 chars, English | 128 | no |
| 804 chars, Russian | 128 | no |
Roleplay replies are usually much longer than that, so retrieval is driven by the opening of the previous reply rather than by what the user just wrote. Non-English text is affected more because the WordPiece vocabulary splits Cyrillic words into single characters.
To Reproduce
from tokenizers import Tokenizer
t = Tokenizer.from_file("v4-tokenizer.json")
reply = "The rain kept falling over the old harbor while the lanterns swayed. " * 12
query = reply + "\n" + "Where did Lena hide the silver key?"
enc = t.encode(query)
print(len(enc.ids)) # 128
print("silver" in t.decode(enc.ids, skip_special_tokens=True)) # False
Expected behavior
Inputs are truncated at the configured max_seq_length, and the newest message always contributes to the retrieval query.
Possible fixes
- Call
tokenizer.with_truncation(None)after loading the v4 tokenizer so the existingmax_seq_lengthslice applies, or remove the truncation block from the published tokenizer. - Put the newest message first in
build_enriched_query, or truncate each part separately, so the user's message survives truncation.
Environment
- LettuceAI 2.2.5 desktop. The code path is unchanged on
mainat b9d1728. - v4 embedding model and tokenizer as downloaded by the app.
This issue is resolved in LettuceAI Next.