256 Commits

Author SHA1 Message Date
Axton Ji
04eb2ac82e fix: batch indexing journal writes for per-document status updates (#3137)
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>
2026-12-01 16:56:02 +08:00
zhang.kom
a4d1cf7499 fix: allow inferred embedding dimensions in LlamaIndex preflight (#3138) 2026-12-01 09:33:49 +08:00
Leveling
41fdf08b92 fix(rag): size the docstore count cache to the catalogue, not one KB (#2777)
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
2026-11-30 23:21:42 +08:00
AleFlyX
fea1be2c97 Merge PR #3092: fix(rag): reuse completed BM25 sidecars on rebuild retry
Verified that the retry published the index with one BM25 write across both attempts. The simulated merge into dev passed 40 targeted tests.
2026-11-30 19:08:21 +08:00
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
Benjamin Schwing
b7dd96d453 fix(mastery): grade concept objectives within covered and own scope (#2363, #2364) (#2366)
* fix(mastery): grade within the objective's covered and own scope

- Reuse the preserved objective-scoped packet for an objective request
  after a focus preparation replaced the live slot, and do not rebuild
  an incomplete objective packet whose fingerprints are unchanged (#2363).
- mastery_assess grades a concept/design explanation against the covered
  facets of an incomplete objective packet, records that scope, and
  returns a structured coverage_gap result instead of a bare refusal.
- Tell the learner when an answer was not recorded or was graded only
  against the covered part.
- Give the judge sibling objectives as out of scope and return the
  single missing element with a next_step to ask for exactly it (#2364).

* test(mastery): cover the focus-only assessment deadlock from #2905

A complete focus-scoped packet with no assessment slot gets a structured
coverage_gap on every repeated mastery_assess, with no judge call and no
recorded evidence. One objective preparation then grades the retained
explanation together with the next reply.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(mastery): make the missing-element step the assess instruction

Since dev added a generic instruction to every final mastery_assess
payload, a non-passing verdict carried two competing moves: next_step
asked for exactly the named missing element (#2364) and instruction
asked the learner to explain the objective again. While the gate is not
cleared, the targeted step is now also the instruction, and it says to
record the reply with mastery_assess.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(mastery): say when an unclear explanation is kept for grading

A non-final verdict in a session keeps the explanation and grades it
together with the follow-up, so the generic "not recorded, progress
unchanged" notice misled the learner into repeating the whole answer.
Add an assessment_needs_clarification notice (en/zh) for that case; an
explanation outside a session keeps the not_recorded notice.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(mastery): preserve the missing assessment element on replay

---------

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
Co-authored-by: Qiuner <wdst3635@163.com>
2026-11-30 06:32:56 -03:00
Gaurav Dubey
8b4191b7d1 fix(rag): keep figure captions out of the chunk metadata budget (#2870)
* 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.
2026-11-30 04:18:49 -03:00
AleFlyX
813827448b fix: 重试知识库重建时复用已完成的 BM25 索引
变更
- 重试时校验 BM25 与当前文档存储是否匹配,缺失、截断或过期时补建。
- 覆盖旧快照、截断文件和中断后清理失败的回归场景。

验证
- 76 项 LlamaIndex 和 BM25 定向测试通过。
- 缩短超时的复现中,修复后只写一次 BM25,重试成功发布。
- Ruff 检查、格式检查和 git diff --check 通过。

Related to #2837
2026-11-30 14:57:12 +08:00
muhamedaldias
084d311302 fix(rag): skip CancelledError results in SmartRetriever.retrieve (#2981)
Co-authored-by: muhamedaldias <296670347+muhamedaldias@users.noreply.github.com>
2026-11-30 14:18:33 +08:00
enlightenmengt2
9ec5815df5 fix(rag): register connected engines in the preflight registry (#3027)
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>
2026-11-30 14:17:55 +08:00
Leon Lei
9db50a7601 fix(rag): avoid NLTK regex CPU timeout in sentence splitting and clean failed version dirs (#3036)
* fix(rag): avoid NLTK regex CPU timeout during splitting and clean failed version dirs

* fix(rag): construct PunktSentenceTokenizer directly without globals_helper stopwords
2026-11-30 14:17:37 +08:00
Carl
c1ae1bbe2a fix(rag): isolate LlamaIndex cross-encoder reranker in a worker process (#3005) 2026-11-30 14:17:26 +08:00
AleFlyX
be2fe9104d Merge PR #2837: fix(rag): batch LlamaIndex rebuild checkpoints
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.
2026-11-29 16:32:15 +08:00
Chen jizhou
4d4a0b7524 fix: preserve embedding checkpoint pointer across preflight failures (#2698)
Co-authored-by: chen-12-03 <184723954+chen-12-03@users.noreply.github.com>
2026-11-28 18:23:30 +08:00
iQuantum
88f38c02bf fix(learning): read the index each knowledge base's provider publishes (#2898)
Mastery Path preparation looked up a knowledge base's index by the global embedding signature. PageIndex, GraphRAG and LightRAG versions carry a provider signature instead, and a LlamaIndex knowledge base can be bound to another embedding, so a ready index was rejected with 'no compatible completed index'. Preparation now resolves the index the way the provider reads it: the KB's bound embedding for LlamaIndex, the newest provider-ready version otherwise. Fixes #2895.
2026-11-28 18:23:13 +08:00
游标卡尺
cac05140f5 fix(mastery): name the recovery action for mis-scoped evidence (#2854)
* fix(mastery): name the recovery step when assessment evidence is mis-scoped

The focused-teaching refusal that blocks mastery_assess said only to prepare
assessment-bound evidence, so a session that had only ever prepared focused
packets retried the same call and the learner stayed stuck. Point the refusal
at the preparation that actually clears the gate.

* fix(mastery): avoid misleading recovery for incomplete evidence

Split focus-scoped and incomplete objective-scoped assessment refusals so
only focused packets are told to prepare without a focus. Surface missing
coverage for incomplete objective packets and pin the diagnostic with a
regression test.

---------

Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>
2026-11-28 18:17:47 +08:00
wojiecihuo
3035ab27e0 fix(rag): keep RERANK_BY_DEFAULT when a LightRAG reranker is wired (#2994)
#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.
2026-11-26 22:50:37 +08:00
游标卡尺
186accef49 fix(rag): only request LightRAG rerank when a rerank model is wired (#2708)
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>
2026-11-26 22:30:07 +08:00
AleFlyX
9199e923cf fix(rag): persist BM25 once after the final rebuild checkpoint
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.
2026-11-23 22:48:55 -03:00
Qiuner
9186666b43 fix(rag): batch resumable LlamaIndex checkpoints 2026-11-20 23:25:11 -03:00
Bingxi Zhao (Frank)
18e491d346 fix(rag): surface IMA content restrictions and seed retrieval failures 2026-11-15 01:04:25 +08:00
Bingxi Zhao (Frank)
92a26ae3cc fix(storage): isolate attachment writes and settle document parsing
Local dev repairs for #2244, #2245, #2255, #2426, #2453. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:09 +08:00
Bingxi Zhao (Frank)
794f1c7399 Merge PR #2545: fix: scope text source_path RAG to the requested document (#2374)
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).
2026-11-14 23:16:26 +08:00
Bingxi Zhao (Frank)
3a8524b073 Merge PR #2565: fix(knowledge): skip unreadable index versions instead of failing the KB list
Format the unreadable-index regression tests; targeted suite passed.
2026-11-14 23:04:54 +08:00
Bingxi Zhao (Frank)
0a80fb5403 Merge PR #2609: fix: skip a missing neighbour page instead of discarding the lesson 2026-11-14 22:58:02 +08:00
Bingxi Zhao (Frank)
e9835ea372 Merge PR #2607: fix: trim over-long lesson page selections instead of failing 2026-11-14 22:58:02 +08:00
Bingxi Zhao (Frank)
ef44b97564 Merge PR #2651: fix(mastery): keep an issued question gradable after its KB is re-indexed (#2650) 2026-11-14 22:58:02 +08:00
Benjamin Schwing
2ba6b5d75c fix(mastery): keep an issued question gradable after its KB is re-indexed (#2650)
A pending quiz card stores the source snapshot it was verified against,
including a fingerprint of the whole published KB index. Adding any
document to that KB changed the fingerprint, so every grade failed with
"Prepare the lesson again" - which refreshes only the lesson packet,
never the card - and the learner's answer could not be recorded.

An issued question is now bound to the pages it cites: when the index
changed but each cited page (KB, document, page, source digest) is still
published unchanged, the question validates and is graded. If a cited
page did change, the error says so and names the recovery tools.
Lesson packets and question issuance keep the strict whole-index check;
objective, answer-key and scope gates are unchanged.
2026-11-12 16:49:56 +00:00
elvisgraho
208335be20 fix: skip a missing neighbour page instead of discarding the lesson
The source selector may ask for an adjacent page ("neighbor": -1 or 1) as
figure/table context. When that page does not exist, for example past the
last page of a PDF, located_sources raised "The requested neighboring page is
unavailable" and the whole preparation was discarded, including the pages
that were actually chosen. On a real course this failed preparation for 4 of
19 concept/design objectives; with the fix, 3 of them prepared complete
lessons and the fourth reached an unrelated coverage gap.

Skip the unavailable context page and keep the chosen pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:43:06 +01:00
elvisgraho
55442c3bb5 fix: trim over-long lesson page selections instead of failing
prepare_lesson tells the model to pick at most MAX_LESSON_PAGES pages, but
models regularly return more (a free reasoning model did so in most runs on a
real course). The whole preparation then failed with "Invalid source selection
count: too many distinct physical pages", and the tutor retried it in a loop.

Keep the model's ranked picks within the cap and drop context-only neighbour
pages first. The lesson stays bounded; every kept page is still inspected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:02:47 +01:00
lazytalk
9e20ebc9d7 fix(knowledge): skip unreadable index versions instead of failing the KB list
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>
2026-11-09 22:49:11 +08:00
markxu
fdae1dfdf0 fix: sync and index MDX documentation in knowledge bases
GitHub source sync kept only .md and .markdown, so a docs glob of *.mdx
reported success with zero files and left raw/ empty. Re-index then failed
because no supported source files were present. Treat .mdx as text next to
Markdown in the sync filter, the knowledge-base file router, and the chat
attachment list that mirrors it.

Fixes #2552
2026-11-09 14:09:57 +00:00
evan188199-tech
1cd7e2e150 fix: match scoped RAG sources by exact path (#2374) 2026-11-09 16:28:24 +08:00
evan188199-tech
2103f2523c fix: scope text source_path RAG queries to their document (#2374)
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.
2026-11-09 15:07:50 +08:00
Bingxi Zhao (Frank)
81ed91a8c3 Keep scoped embedding clients on their calling operation and split mastery-only UI 2026-11-06 02:25:50 +08:00
Bingxi Zhao (Frank)
823aa1a8b3 Validate launcher, retrieval, migration, and responsive reader behavior 2026-11-06 02:04:53 +08:00
Bingxi Zhao (Frank)
ce6a5fbc87 Merge #2353 from stefanielizeth73-art 2026-11-06 02:04:53 +08:00
Bingxi Zhao (Frank)
8602605976 Merge #2336 from remote-controlled-man 2026-11-06 01:56:40 +08:00
Bingxi Zhao (Frank)
2c60615a04 Merge #2410 from chen-12-03 2026-11-06 01:56:25 +08:00
Bingxi Zhao (Frank)
d374d7e26a Merge #2332 from markjoin123 2026-11-06 01:56:23 +08:00
chen-12-03
739f6406a3 fix: avoid quadratic source image path matching 2026-11-03 21:01:09 +08:00
stefanielizeth73-art
879421710d feat(embedding): add NVIDIA NIM retrieval embeddings 2026-11-02 15:23:22 +08:00
Steven Huang
466649209a fix: handle adjacent identifiers and reuse BM25 rebuilds 2026-11-02 11:04:42 +08:00
Steven Huang
02339d5065 fix: preserve dotted identifiers in BM25 retrieval 2026-11-02 10:32:25 +08:00
markxu
db014f0ed8 fix(ima): route search folder-name hits away from document hydration
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
2026-11-02 02:04:30 +00:00
Rudy Celekli
b71c2b7e3a fix(rag): count LightRAG docs from the native workspace store
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>
2026-11-01 09:10:24 -05:00
Bingxi Zhao
94d71357bf Merge pull request #2188 from Zhi-Xiang-Guo/fix/rag-exercise-scope-evidence
fix(rag): preserve selected-document exercise retrieval and usable page evidence
2026-10-31 18:27:09 +08:00
Bingxi Zhao
8e6c40cab0 Merge pull request #2223 from markjoin123/cursor/fix-pdf-ref-list-indexing-29e3
fix(rag): index MinerU reference lists and skip page furniture
2026-10-31 17:54:24 +08:00
Bingxi Zhao
ac75e456f1 Merge pull request #2211 from Rimcat-JA/fix/rag-drop-unmatched-bm25
fix(rag): keep zero-score BM25 hits out of hybrid fusion
2026-10-31 17:32:50 +08:00
markxu
17104645cd fix(rag): index MinerU reference lists and skip page furniture
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
2026-10-31 02:07:06 +00:00