Files
lipeh1 681b23766f feat(rag): support local rerankers for LightRAG queries (#3009)
* feat(rag): support local rerankers for LightRAG queries

Allow administrators to select a cross-encoder alongside the native LightRAG role models. Run scoring in a reusable worker and partition cached answers by reranker so model changes take effect on existing indexes.

Refs #2701

* fix(api): refresh the router index for LightRAG settings

* fix(rag): run LightRAG reranking in the shared reranker worker

anyio's process pool re-runs the server's __main__ file by path. When the
backend runs as `python -m deeptutor_cli.main serve` (the desktop app),
that file's relative imports fail, so every rerank call failed with
'Error during worker process initialization' and LightRAG silently kept
the original chunk order. Reuse the python -m reranker worker that the
LlamaIndex pipeline already uses.

---------

Co-authored-by: lipeih <lipeihan@eazytec.com>
Co-authored-by: zszz3 <zszz3@users.noreply.github.com>
2026-11-30 18:46:49 +08:00
..

LightRAG role models

In Knowledge Center, open the native LightRAG engine and choose a base model. The saved base is independent of the chat model and the embedding model. Shared engine settings require administrator access when authentication is enabled.

Role Used for Available sources
EXTRACT Entity/relation extraction, structured tables and equations Base or explicit model
KEYWORD Query keyword extraction Base or explicit model
QUERY Answer generation Base or explicit model
VLM Requested image analysis Disabled, base or explicit vision model

The Models section also accepts an optional SentenceTransformers cross-encoder, such as BAAI/bge-reranker-base. Install the rag-rerank extra to use it. The model scores retrieved chunks on the next query, including queries against existing indexes. Clear the field to disable reranking.

Fresh settings are distinguished from historical settings. Choose and save a LightRAG base in Settings before querying or creating a knowledge base. New role configurations disable VLM by default. Inheriting the base for VLM requires a model that supports image inputs. Disabling VLM preserves text, table and equation processing. An explicit image-analysis request on a disabled index fails with full-rebuild guidance.

Each enabled role can override supported reasoning effort. Auto leaves reasoning controls to the provider; none explicitly disables reasoning where supported. An inherited role follows the base reasoning unless it has its own override. Restoring an older pinned index retains its recorded reasoning semantics. Unsupported choices are rejected without substituting another model or reasoning level. Concurrency and timeout limits apply per role to subsequent tasks and do not require rebuilding. Accepted tasks keep their effective models, reasoning and limits while queued and running.

DeepTutor forwards LightRAG structured-output requests, including the JSON object contracts used by EXTRACT, KEYWORD and VLM, through its provider capability filter. Provider reasoning is controlled by the saved role effort. DeepTutor intentionally omits provider reasoning traces from the returned answer even when LightRAG requests its COT output format.

Creating, appending and rebuilding

Configure role models in Settings. Creation and full rebuild do not offer per-index role overrides, but retain per-knowledge-base embedding selection. An idle, unpublished empty knowledge base follows current valid role defaults until its first accepted indexing task freezes the configuration, retaining its embedding binding.

Before rebuilding, review the selected embedding model/dimension and current default EXTRACT/VLM models and reasoning. The existing embedding binding is retained unless another model is selected. If the selected configuration changes before submission, review and confirm the refreshed configuration. Accepted tasks retain the same embedding and role settings through execution and version publication. Failed-task retry actions also use this confirmation flow.

After publication, uploads and folder/GitHub sync use the index's pinned EXTRACT and VLM identities. Changing engine defaults does not change an existing index. Enabling, disabling or replacing VLM, or replacing EXTRACT or their reasoning configuration, requires a full rebuild. If a valid VLM was pinned before the first image, later image uploads can use it without another rebuild.

Index versions show their version identifier, state, timestamp and actual embedding, EXTRACT and VLM configuration. The display distinguishes provider-default reasoning, explicit none and disabled VLM. Returning from Settings refreshes default-role summaries. Unavailable pinned indexing models require restoring access or rebuilding with new defaults, but do not unconditionally block existing text retrieval. A failed or cancelled rebuild keeps the previous published index. A queued operation whose target changed fails before writing; resubmit it against the current index. Concurrent writers for one knowledge base are rejected, so wait for the active operation to finish before resubmitting.

Existing settings and indexes

Legacy engine settings are prefilled from an accessible existing selection. Saving detaches the LightRAG base from chat. Missing or inaccessible selections must be replaced explicitly.

Verifiable legacy single-model indexes retain their original model fingerprint and recorded vision state without a format-only rebuild. Unknown historical identity remains queryable but blocks incremental writes until a full rebuild. Malformed policies and models that have been deleted, changed identity or lost access cannot silently acquire current defaults. Credential rotation alone does not change the pinned identity; credentials are resolved privately for execution and are excluded from persisted index policy and public provenance.