mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 11:09:46 +08:00
Asked how many files a knowledge base holds, or whether some document is in it, the model had only `rag` — and retrieval cannot answer either question: the passages it returns say nothing about the size of the collection they came from, so the model guessed from whichever chunks the query happened to match. PageIndex KBs already answered correctly (their doc list is injected into the system prompt) and Obsidian vaults have `list_notes`, which makes this a wiring gap in the default engines rather than a limit of retrieval. `deeptutor/knowledge/manifest.py` now owns a KB's document inventory as facts read off disk, with two consumers that cannot disagree: - the chat system prompt carries a per-KB inventory (count plus a truncated name list), so a count costs no tool round-trip — the failure mode where a weaker model never emits the call at all (cf. #532). Built once per turn on a worker thread, keeping the prompt byte-stable for the whole turn; - a new `kb_files` tool enumerates on demand with glob / substring filtering, mounted under `rag`'s gate (a KB is attached) and deniable per partner the same way. The inventory reports the document set and the KB's index status, and stops there. It deliberately does not report how many documents reached the index: every per-file record available is unreliable — LlamaIndex's docstore.json counts nodes (chunk-level, so it drifts with the chunking config, and costs a multi-MB parse to read), metadata.json's file_hashes is only written on the incremental-add path, and last_indexed_count is the last batch's size rather than a total. A confidently wrong count is worse than none. The prompt block also states the rule that retrieved passages must never be used to infer how many documents a KB holds or whether one exists in it. Connected KBs degrade honestly instead of reporting zero: linked folders and Obsidian vaults are enumerated in place, while a remote LightRAG server and a connected subagent are declared unlistable. Hidden OS/editor entries (.DS_Store, .obsidian/) stop counting as documents, and get_info's raw_documents reads the same definition, so the KB page and the chat answer can no longer disagree about the same KB. Deep Research is untouched: its block loop narrows tools to the four that produce block-level evidence, and a file list is not evidence for a subtopic.