Skip to content

feat: Switch tokenizer based on embedding model - #53

Open
cableman wants to merge 1 commit into
upstream/v0.9.6from
feature/embed-tokenizer
Open

feat: Switch tokenizer based on embedding model#53
cableman wants to merge 1 commit into
upstream/v0.9.6from
feature/embed-tokenizer

Conversation

@cableman

@cableman cableman commented Jul 1, 2026

Copy link
Copy Markdown

UPDATE: Open-webui has made the same fix in open-webui@bb6b2db


When the RAG token splitter is enabled (RAG_TEXT_SPLITTER=token), Open WebUI measures CHUNK_SIZE / CHUNK_OVERLAP with tiktoken (cl100k_base, OpenAI's GPT tokenizer) - regardless of which embedding model is actually configured.

We embed with multilingual locally hosted embedding, which use a completely different (XLM-RoBERTa / SentencePiece) tokenizer. On multilingual (Danish) text the two tokenizers disagree substantially on how many tokens a piece of text is, so the chunk sizes we compute don't match what the embedding endpoint actually sees.

Effect:

Chunks can exceed the model's max sequence length (eg. 512 tokens) -> the embedding server thorws out-of-index error

Fix:

New config RAG_TOKENIZER_MODEL names the HuggingFace tokenizer repo to use. Empty that falls back to RAG_EMBEDDING_MODEL, then to tiktoken.

@cableman cableman added Patch (do not merge) WIP Work in progress labels Jul 1, 2026
@cableman
cableman marked this pull request as ready for review July 1, 2026 13:13
@lilosti
lilosti requested a review from ghbm-itk July 3, 2026 06:46
Comment thread backend/open_webui/routers/retrieval.py Outdated
Comment thread backend/open_webui/routers/retrieval.py
Comment thread backend/open_webui/routers/retrieval.py
Comment thread backend/open_webui/routers/retrieval.py Outdated
Comment thread backend/open_webui/routers/retrieval.py
@ghbm-itk

ghbm-itk commented Jul 6, 2026

Copy link
Copy Markdown

This project could really use a linter...

@cableman
cableman force-pushed the feature/embed-tokenizer branch from 1c256de to 8acd529 Compare July 8, 2026 08:55
@cableman

cableman commented Jul 8, 2026

Copy link
Copy Markdown
Author

This project could really use a linter...

yes, but that is way out-of-scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants