feat(rerank): forward max_tokens_per_doc to providers that support it - #3002
Open
chethanuk wants to merge 2 commits into
Open
feat(rerank): forward max_tokens_per_doc to providers that support it#3002chethanuk wants to merge 2 commits into
chethanuk wants to merge 2 commits into
Conversation
chethanuk
force-pushed
the
feat/rerank-forward-token-truncate
branch
from
July 4, 2026 02:57
d4f3784 to
aad66f7
Compare
Contributor
Author
|
Please review cc: @qin-ctx @ZaynJarvis @zhoujh01 @yufeng201 @chenjw - Please let me know if you require any changes, or if the project is currently accepting contributions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the
max_chars_per_doccap (#2880). A character cap is provider-agnostic but cannot bound tokens: for CJK text, N characters can be far more than N tokens, so a char cap can still overflow a token-limited reranker. Providers that expose native token truncation should use it.Adds
RerankConfig.max_tokens_per_doc(default0) and forwards it asmax_tokens_per_docto the providers whose APIs accept it. VikingDB/doubao has no truncation field and is intentionally left untouched (usemax_chars_per_docthere).How it works
flowchart TD A["RerankConfig.max_tokens_per_doc"] --> B{"value > 0 ?"} B -- "0 (default) → omit field" --> Z["every provider: byte-identical request"] B -- "> 0" --> C["from_config forwards value"] C --> D["Cohere v2 → /v2/rerank request body"] C --> E["OpenAI-compatible (DashScope / vLLM / TEI) → request body"] C --> F["LiteLLM → litellm.rerank(...) kwarg"] C -. "not wired (no token field)" .-> G["VikingDB / doubao: unchanged"]Notes
> 0, so default requests are byte-identical to before — asserted per-provider.req_bodydict so the field can be added conditionally).Field(default=0, ge=0, strict=True);extra="forbid"keeps typos fatal.Tests / docs
Each client asserts it forwards the value when set and omits it when
0, plusfrom_configwiring, config validation, and a guard that VikingDB ignores the field.en+zhdoc rows added. Unit suite green;ruffclean.Review
The mirror PR received no actionable inline review-bot comments (automated review returned "no issues found").