Skip to content

Issue #18: LightRAG option parity (embedding token limit, dimensions gate, Cohere rerank chunking)#19

Merged
joonsoome merged 2 commits into
mainfrom
16-fix-qwen3-reranker-tokenizer-lacks-pad_token-for-batch-requests
Feb 10, 2026
Merged

Issue #18: LightRAG option parity (embedding token limit, dimensions gate, Cohere rerank chunking)#19
joonsoome merged 2 commits into
mainfrom
16-fix-qwen3-reranker-tokenizer-lacks-pad_token-for-batch-requests

Conversation

@joonsoome

Copy link
Copy Markdown
Owner

LightRAG recently added new embedding/rerank options via env vars. embed-rerank previously ignored or didn’t correctly apply these options, which could break LightRAG compatibility. This PR adds env parity and wires the options into the OpenAI embeddings and Cohere rerank flows while keeping default behavior unchanged when options are unset.

What Changed

  • Config/env parity (config.py)
    • Added env aliases:
    • EMBEDDING_TOKEN_LIMIT -> default_max_tokens_override (alias of DEFAULT_MAX_TOKENS_OVERRIDE )
    • EMBEDDING_SEND_DIM -> embedding_send_dim (gate for honoring OpenAI dimensions )
    • RERANK_ENABLE_CHUNKING -> rerank_enable_chunking
    • RERANK_MAX_TOKENS_PER_DOC -> rerank_max_tokens_per_doc (min 1, default 4096)
  • Embeddings (openai_router.py, embedding_service.py)
    • /v1/embeddings now forwards max_tokens_per_text to internal EmbedRequest.max_tokens_override
    • Token limit selection now follows: request override > env default override > model recommended
      Overrides are clamped to absolute max (warn + clamp; no error)
    • dimensions pad/truncate is now gated by EMBEDDING_SEND_DIM (default: enabled, preserving current behavior)
  • Cohere rerank chunking (cohere_router.py, rerank_chunking.py)
    • Optional server-side document chunking controlled by env
    • Chunk-level scoring with doc-level aggregation ( max ), deterministic sort (score desc, index asc)
    • top_n is applied after aggregation (document-level semantics)
    • Guardrail: if chunking produces more than MAX_PASSAGES_PER_RERANK , return 400 with guidance
    • Cohere endpoints now also prefer the dedicated cross-encoder backend when configured (main.py)
  • Docs
    • Updated .env.example and README.md with the new LightRAG parity options

Backward Compatibility

  • No API request/response schema changes.
  • Defaults remain unchanged when new env vars are unset.
  • Cohere chunking is disabled by default.
  • OpenAI dimensions behavior remains enabled by default (same as before).

Tests

  • Added/updated tests:
    • test_settings_aliases.py
    • test_openai_embeddings_options.py
    • test_rerank_chunking.py
  • Ran locally:
    • test_openai_embeddings_options.py
    • test_ci_quick.py

@joonsoome joonsoome self-assigned this Feb 10, 2026
@joonsoome joonsoome added the enhancement New feature or request label Feb 10, 2026
@joonsoome joonsoome linked an issue Feb 10, 2026 that may be closed by this pull request
@joonsoome
joonsoome merged commit d7eb80c into main Feb 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Qwen3 reranker tokenizer lacks pad_token for batch requests

1 participant