IndexingRun.document() re-reads the journal and atomically rewrites the
whole .indexing-run.json on every call. The LlamaIndex loader marks each
accepted source "embedding" in a synchronous loop on the event loop, and
publication marks every loaded Document (one per page) "completed" the
same way, so recording n statuses costs O(n^2) bytes of I/O with no
await in between. On a 4,320-document reindex this held the loop for
over 100 s, /health/ready stopped answering, and the desktop supervisor
killed the core.
Add IndexingRun.documents(sources, status, **details), which applies one
status to many sources under a single ownership check and a single
journal write, and use it from the loader, the LlamaIndex publication
step and the RAG service's indexed-file callback. document() now
delegates to it, so single updates behave as before.
Fixes#3046
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
A KB-list / get_info sweep probes every version-N directory of every KB,
because the UI renders readiness per version. The docstore count cache is
keyed per version directory, so its capacity has to cover the whole
catalogue, not a single KB's worth.
At the old fixed 128 slots a real installation (13 KBs, 310 version
directories -- #2772) exceeded the working set on every sweep: each probe
evicted exactly what it had just read, the hit rate stayed at a permanent
0%, and every UI navigation re-parsed every multi-MB docstore.json. On a
memory-constrained host that showed up as a pinned event loop and hundreds
of GB of disk reads.
Raise the capacity to 4096. Each entry is a path plus an int, so this costs
about a megabyte even well above the working set.
Reproduced against v1.7.3 with a fixture matching the report (13 KBs, 310
versions, 52 MiB of docstore.json), replaying inspect_kb_versions() per KB:
before: 310 / 310 / 310 / 310 / 310 docstore parses per sweep, 0.0% hit rate
after: 310 / 0 / 0 / 0 / 0 docstore parses per sweep, 100% warm
A rewritten docstore still invalidates correctly (doc_count 400 -> 1), and
unchanged versions stay cached. The new regression test builds 2 KBs x 100
versions, which is above the old cap, and fails on the unfixed code
(400 parses instead of 200).
Closes#2772
* 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>
* fix(rag): keep figure captions out of the chunk metadata budget
Figure documents carried the caption, asset ids, bbox, source locator and
absolute path in metadata that LlamaIndex counts against every chunk. A long
caption (common for CJK textbook figures) pushed the metadata past the
default 512-token chunk size, so SentenceSplitter raised "Metadata length
(...) is longer than chunk size (512)" and the whole indexing run failed.
Keep those keys on the node for citations and pixel delivery, but exclude
them from the embed and LLM metadata text. The caption is already part of
the document text, so retrieval content is unchanged.
Closes#2865
* test(rag): split sentences without NLTK in the caption budget test
The new regression test ran SentenceSplitter with its default punkt
tokenizer, which loads NLTK data. CI runners refuse that data, so the
test failed with LookupError on all Python versions. Pass a regex
sentence splitter instead. The test still fails without the loader fix.
EngineDetail renders the readiness panel for every engine, and its check button calls /api/knowledge-bases/rag-pipelines/{provider}/preflight, which runs engine_preflight() -> _PREFLIGHTS[normalize_provider_name(provider)]().
weknora and kiwix are in KNOWN_PROVIDERS but were never registered in _PREFLIGHTS, so the lookup raised KeyError and the route answered 500 for those engine pages.
One shared _connected_preflight now reports them ready: each knowledge base supplies its own server URL and credentials, validated by the connect probe, so nothing is configured account-wide. This matches doctor.py, which already skips these providers in its preflight loop.
The new test walks KNOWN_PROVIDERS and asserts every entry returns a report, so a future provider constant cannot silently miss the registry again.
Co-authored-by: enlightenmengt2 <227120787+enlightenmengt2@users.noreply.github.com>
* fix(rag): avoid NLTK regex CPU timeout during splitting and clean failed version dirs
* fix(rag): construct PunktSentenceTokenizer directly without globals_helper stopwords
Batch resumable embedding checkpoints and write the BM25 sidecar once after the final checkpoint, carrying over #2903. 45 targeted tests passed with the PR applied to dev. A 19-source rebuild retrieved the last source from the persisted BM25 index.
#2708 set enable_rerank from whether a rerank model is wired, which also
overrode LightRAG's RERANK_BY_DEFAULT switch once a reranker exists. Only
turn rerank off when no model is wired and otherwise leave LightRAG's
default in place.
LightRAG 1.5.7 defaults enable_rerank on, so query_with_sources emitted a
per-query warning whenever no rerank model was configured. Gate the flag
on the presence of a callable rerank_model_func so the default deployment
stops warning without changing behavior for anyone who wired a reranker.
Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>
Integrate AleFlyX's staged sidecar write from PR #2903 with the batched checkpoints in PR #2837. Rebuild the sidecar after the final checkpoint, including when resuming a fully checkpointed candidate.
Declare document-scope support at the pipeline contract and reject unsupported scoped queries before rewrite/retrieval; verify empty scopes also fail closed (29 retrieval tests and 10 service tests passed).
A knowledge base whose data files are unreadable (for example root-owned
files in a container whose app runs as uid 1000) used to take down the
entire KB catalogue: list_kb_versions() -> _read_json() -> Path.exists()
raised PermissionError, so list_knowledge_bases() and the web-source
scheduler failed for every KB.
- _read_json() opens the file directly and treats FileNotFoundError as
"no metadata"; other OSError/ValueError degrades to a warning. This also
avoids Path.exists(), which propagates EACCES on Python >= 3.8.
- _is_storage_ready(), _flat_version_dirs() and list_kb_versions() skip
unreadable versions with a warning instead of raising.
- KnowledgeBaseManager._list_knowledge_bases() isolates per-KB failures
and an unreadable base directory, keeping the rest of the catalogue.
Tests cover unreadable metadata, an unreadable version dir, an unreadable
storage probe, and a manager listing with one unreadable KB.
Co-Authored-By: Claude Code <noreply@anthropic.com>
source_path alone is a document scope, not a visual request: an ordinary
text query with no page, figure, region or asset_id selector now stays on
the text retrieval path, restricted to that one document, instead of
entering exact-source visual inspection and failing reference_required.
- RAGTool routes source_path-only queries to a scoped semantic search that
verifies the source exists (and its source_hash when given), forwards
document_keys to the backend, and never falls back to a whole-KB search:
a backend that cannot enforce the scope, or a document with no matching
passage, fails explicitly (source_scope_unsupported /
source_scope_no_match) with foreign passages withheld.
- LlamaIndex scoped retrieval now recognises plain-text documents, which
carry only file_path metadata, by their raw-relative position — never by
bare basename, so sub/notes.txt does not leak into a notes.txt scope —
and admits nodes without a page_status.
- Tool schema description and en/zh prompt hints state the contract;
selector-contract tests cover the scoped text path and a new suite
covers raw-relative scope matching.
The first KB query builds the embedding adapter (provider SDK import and client construction) inside the coroutine, which blocks every other task on the loop for seconds. Run it in a worker thread; scoped embedding configs keep their ContextVar branch inline.
_hydrate now records a precise failure for sources skipped for their
title's format instead of leaving them as bare content_unavailable.
Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
Legacy Office documents and other engine-only formats pass the IMA title
check but can never yield text through the built-in extractor, so a full-text
fetch only burns the 4-document hydration budget ahead of extractable
matches. Skip them at target selection and report them as
unsupported_format instead of an unexplained content_unavailable (#2338).
Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
search_knowledge returns folder matches inside info_list with a folder_
media id and media_type 99, and no folder_id. Those were parsed as
documents, so retrieval spent the hydration budget on get_media_info
failures and reported content_unavailable.
Fixes#2326
The LightRAG index probe reported doc_count=None for every native-layout
index. _lightrag_doc_count read kv_store_doc_status.json from the version
root, but native LightRAG keeps its KV stores under a deeptutor_<hash>
workspace subdir; every other reader (has_output, failure_summary,
document_error) resolves that subdir via storage._store_root first.
Move the count into the storage module as a public doc_count() that
resolves the store root the same way, and have index_probe delegate to it.
A ready native index now reports its real count instead of None, so the KB
version list, last_indexed_count and linked-folder probe stop falling back
to a raw-file guess.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
build_pdf_documents() ignored MinerU list_items, so bibliography entries
on type=list / sub_type=ref_text blocks never reached the chunker.
Page-number, header, and footer blocks were indexed instead.
Fixes#2222
Linked-folder sync wrote a full snapshot for every file and never deleted the old ones. Index a staged batch in one publish and keep the newest three snapshots per embedding signature.
Co-authored-by: Cursor <cursoragent@cursor.com>
BM25Retriever returns its top-k nodes even when no query term matches.
With the default whitespace tokenizer that happens for every Japanese or
Chinese query, and reciprocal-rank fusion ranks those score-0 nodes like
real lexical hits, so unrelated chunks land in the top results.
Wrap the lexical side of both fusion retrievers so only hits with a
positive score are fused. Queries that do share terms are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Retain exact exercise lookup with scoped canonical page evidence and fall back when provenance is unavailable. Cover real lesson preparation and selection boundaries.
The visual-coverage report and recovered usage reports are UTF-8 JSON
written by this codebase, but were read through the locale default.
Non-ASCII titles made coverage fall back to unverified and cost recovery
silently lose per-model details on Chinese Windows.