Forward embedding-batch progress through DocumentAdder so LlamaIndex folder
syncs and multi-file uploads no longer stay at 0% until the whole batch returns.
Co-authored-by: zhouyao01 <zhouyao01@mucang.cn>
* fix(knowledge): drop visual assets on every document-delete path
Extracted figures are tracked in `visual_assets/` (manifest + image files) and
were only cleaned by the HTTP delete-file route, which called
`VisualAssetStore.remove_source` itself. `remove_raw_document` has three
callers - that route plus the GitHub and web source syncs - so the two sync
paths deleted the document and left its figures and manifest entries behind
forever. Images are capped at 5 MB each, so a sync that drops figure-heavy
documents leaks a lot of disk.
Reproduced before the fix: a KB with one raw PDF and a matching asset entry,
then `remove_raw_document(kb, doc)` (exactly what both syncs do) -> the doc was
gone while the asset file and its manifest entry both remained.
Cleanup now happens in `remove_raw_document`, the single layer all three
deletion paths share, keyed by the module's existing `_raw_hash_key` - the same
rule indexing uses to record `source_path`, so nested raw/ paths cannot be
missed. The route's now-redundant call is removed rather than left as a second
owner: it also removes a second, lexical relative-path computation, and the old
uncaught call could 500 a delete on a corrupt manifest, which contradicts the
"cleanup never fails a user's delete" contract.
Best-effort like the surrounding code: a corrupt or read-only manifest logs a
warning and never turns a delete into an error. `VisualAssetStore.__init__`
only assigns paths, and `remove_source` returns before writing when no entry
matches, so KBs that never had images are not given an empty `visual_assets/`
directory (pinned by a test).
Verified: 7 new tests; mutation check shows disabling the cleanup fails 4 of
them. Independent checks: nested `papers/2024/` asset removed while a sibling
document's asset is preserved; no `visual_assets/` created for an image-free
KB; re-running the original repro now reports no leak.
Tests: 264 passed (knowledge, visual assets, source sync, HTTP file deletion).
Note: assets for an older parser signature are deliberately kept so a rollback
to an older index version still resolves its figures; that is retention, not a
leak, and is unchanged here.
* fix(api): 更新路由索引指纹
重新生成 knowledge 路由变更后的索引。原生引擎和路由加载器的 18 个测试均已通过。
---------
Co-authored-by: zszz3 <zszz3@users.noreply.github.com>
The parse cache is content-addressed and has no eviction of any kind: no size
cap, no TTL, no LRU, no CLI command, no settings entry. Neither deleting a raw
document nor deleting a whole knowledge base removed anything from it, and the
only cleanup that exists (clean_rag_storage) removes index storage - not the
parse cache - and is CLI-only. A deleted KB therefore kept its entire derived
parse output on disk forever.
Measured with a realistic document: a 30-page PDF with ~18 extracted images
leaves about 6.5 MB under parse_cache/. 64 such documents accumulate ~418 MB
that is never reclaimed; the directory only grows.
cache.reclaim_sources(paths, cache_root=...) removes the
<parse_cache>/<hash[:2]>/<hash>/ shard for each document being deleted - every
parser signature for that source, since the cache is derived and the next parse
recreates what it needs. It hashes the bytes while they still exist, because
the cache key is the content hash. Wired into two call sites, both before the
bytes disappear:
- remove_raw_document (single file, before unlink())
- KnowledgeBaseManager.delete_knowledge_base (every raw document, before the
KB directory is removed)
The cache root is derived from the KB directory (a sibling of knowledge_bases/)
rather than from the ambient path service, because requests served from the
knowledge-base library run in the account workspace scope. Deriving it from the
request scope would reclaim another workspace's cache while leaking this KB's
own. KB deletion enumerates exactly what rmtree removes: dotfiles included,
symlinks skipped because only the link goes away.
Reclaiming is scoped strictly to the hashes of the files being deleted, so
nothing else under the cache root is touched. The cache is shared across all
parse consumers in the workspace (KB indexing, chat attachments, reading
figures), so a byte-identical copy loses its entry too and is re-parsed once on
next use - slower, never incorrect. Proving liveness would mean hashing every
live source on every delete, and metadata.json only records documents that
indexed successfully; that tradeoff is documented on the helper and at both
call sites. The key is a truncated 64-bit hash; a collision costs one extra
re-parse, never wrong output.
Best-effort by contract: an unreadable source, a locked shard (a stale Windows
handle is the common case) or a missing cache root is logged and skipped, and
both call sites additionally wrap the call, so no cache failure can fail a
user's delete.
Note: this reclaims on delete; it does not bound growth of the live cache. A
size cap / LRU sweeper is a separate change and should be its own issue (the
scope split is recorded on #2946).
Verified on the current dev base (14796c70f): 14 new tests; mutation checks show
disabling the helper at either call site fails its positive-reclamation test.
A workspace/library-view reproduction (real ContentWorkspaceService, account
scope, KB stored in a workspace) confirms the KB's own shard is now reclaimed
while an account-level lookalike shard is left alone. tests/knowledge: 205
passed, 6 pre-existing failures (same as dev, missing llama_index/jose). ruff
check/format clean with the pinned 0.16.0.
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>
`kb create --docs-dir` staged every source at `raw/<basename>` with an
unconditional copy, so a docs tree with one `full.md` per volume kept only
the last file and still reported success. Both KB entry points now share one
staging rule (`knowledge/staging.py`): a taken name is reused only when the
content matches, otherwise the newcomer gets a free sibling name, so nothing
the user asked to index is dropped.
Issue: #2041
Combine knowledge bootstrap coverage and preserve later progress-isolation tests, native notebook tooltip, and locale-aware tool-hint fallback. Regenerate frontend contracts and align test fixtures with merged APIs.
Bind mastery drafts before their opening turn and preserve stored session modes.
Track chat duration from submission through terminal completion. Run async reading
extensions on their event loop and allow retries after cancellable timeouts.
Allow first uploads into empty LlamaIndex knowledge bases, preserve Telegram
thread routing, parse embedding Retry-After dates, and enforce robots rules and
host pacing during documentation crawls, including redirects.
Fixes#1461Fixes#1458Fixes#1451Fixes#1448Fixes#1392Fixes#1429
Refs #1435, #1412
Reuses contributions from PRs #1462, #1452 and #1403.
Co-authored-by: sjagadee <srini.jagadeesh@gmail.com>
Co-authored-by: AoHanBei <dongaohan21@gmail.com>
Co-authored-by: Gao-Chenkai <DevChenkai@outlook.com>
Empty LlamaIndex KBs and UID-mismatched volumes were reported as
"not initialized". Fail-fast on unwritable data dirs and remap the
non-root deeptutor user instead of swallowing chown failures.
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat(knowledge): add GitHub source sync
* fix(github-sync): contain downloaded paths inside the KB raw dir
Destinations were built as `raw_dir / rel` where `rel` is derived from the
GitHub tree/compare response — remote input. Two shapes escaped: a `..`
segment, and an absolute path, which is the quieter one because
`Path("/kb") / "/etc/x"` is `/etc/x`, silently discarding the base. The only
filters in the way checked the file extension and the glob, so a matching
path would have been written — and, on the removal branch, deleted — outside
the knowledge base.
git rejects both shapes in tree entries today, so this is defence in depth
rather than a live exploit; a downloader still should not delegate to the
remote the question of where it writes. One `_contained_dest` seam now guards
the full-sync write, the incremental write, and the removal, and logs what it
refused.
---------
Co-authored-by: XZH <cto@xzh.ai>
Co-authored-by: Frank <bingxizhao@novix.science>
Every progress line the knowledge log box shows was a hardcoded English
string — 22 producers across the initializer, the document adder and the
router, rendered verbatim in the UI. #933 added one more ("Describing
images: m/n"), which is what surfaced the class.
Indexing runs detached from any request, so the backend has no viewer
language and the language of record lives in the browser anyway. So the
wire now carries the English `{{name}}` template plus its values, and the
frontend renders it with `t()` where the language is actually known.
`ProgressTracker.update` fills `message` from that same template, so
every consumer without i18n of its own — logs, the persisted snapshot,
the CLI — reads what it read before, and no call site spells the string
twice.
Untouched producers keep working: `progressMessage()` falls back to the
rendered `message` when no template is named.
Builds on #899, which stopped a linked folder's subdirectories from
collapsing into raw/'s top level. Preserving structure removes most name
clashes but not the one #866 actually hit: a folder too large to sync at
once is added one subfolder at a time, and each batch roots at its own
folder, so `cli/README.md` and `events/README.md` both want raw/README.md.
The second was skipped as a "filename collision" — a document the user
asked to index, dropped with nothing in the response to say so.
A clash between different bytes now stages under a free sibling name.
Identical bytes still recover the staged copy, and content-level dedup via
file_hashes is untouched, so a repeated sync neither duplicates nor churns.
The staging log also reports the path a file actually landed at rather than
its source basename, which is no longer the same thing.
Adds PageIndex OSS as a knowledge-base type and moves PageIndex retrieval from traditional RAG to reasoning-based retrieval: a small workflow-owned agent loop reads the document tree instead of going through the built-in MCP server, which this removes.
Fixes#866. DocumentAdder staged every externally-sourced file at raw/<basename>, collapsing a linked folder's subdirectories and colliding same-named files. Pass the sync root through so each file stages at its path relative to it.
Batch-uploading files stalled every other request — chat WebSockets included
— for the whole duration of the batch. Two blocking paths, both in an async
context:
* ``_save_uploaded_files`` blocks end to end (a chunked write of every
uploaded byte, zip extraction, plus a synchronous HTTP upload per file
when PocketBase is on) and was called inline from the upload and
create-KB routes;
* the follow-up work runs in a FastAPI ``BackgroundTasks`` entry declared
``async def``, which starlette awaits ON the loop — only *sync* callables
reach its threadpool — so the staging pass (a full-content hash per file
plus a copy) and the per-file re-hash blocked there too.
Each of those moves to a worker thread. Reading ``UploadFile.file`` off-loop
is safe: it is the plain SpooledTemporaryFile, never the async API. The
provider index itself already ran through an executor, and the remaining
small JSON writes are left inline rather than paying a thread hop each.
Extends the #619 follow-up to the remaining plain truncate-writes of
metadata.json (add_documents, initializer, reindex task) and replaces
progress_tracker's hand-rolled fixed-name temp+replace with the shared
atomic_write_json. _mark_kb_queued_for_processing gains a status kwarg
so the reindex endpoint's pre-dispatch write uses the same seam as
upload/sync instead of an 11-line inline block.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Knowledge Center: remove a single raw document from a knowledge base —
even one stuck in an error state — instead of deleting and rebuilding
the whole base. A file that failed to parse (e.g. one over the cloud
parser's page limit) can now be dropped in place, with replace/retry.
- backend: remove_raw_document() decoupled from DocumentAdder (needs no
ready index) + DELETE /{kb_name}/files/{filename:path}; shared
_read_metadata / _write_metadata / _raw_hash_key helpers so indexing
and removal agree on the hash key. Connected/legacy KBs still rejected.
- web: deleteKbFile() API, per-file delete in the Files tab, and
error-state KBs unlocked for drop / upload-replacement / retry.
- release notes ver1-5-1.md (old notes archived to past_releases/),
__version__ bump to 1.5.1, README Releases row + one-week fold.
- README KB prose + all 10 translations synced; docs knowledge page
updated separately in site/.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A broad consolidation release across four product surfaces.
- Learning Space: Space becomes a learning dashboard; My Agents imports
local Claude Code / Codex chat history into resumable agents (with an
objective explore_context briefing so the tutor never role-plays the
user); Memory is promoted to a top-level /memory route; Partner
conversations flow into Memory; EduHub skills install inline.
- Knowledge Center: /knowledge rebuilt as a console with per-engine
detail pages; GraphRAG / PageIndex / LightRAG engines join LlamaIndex;
linked-KB read-only mounts; Obsidian live-vault capability.
- Settings: pluggable document parsing (MinerU / Docling / MarkItDown)
with a content-addressed cache and MinerU cloud/local backends; voice
TTS/STT; image & video generation; rebuilt settings navigation.
- Platform: per-user capability gating by assigned model; Solve rebuilt
on the chat loop with a per-step gate and mid-run failure fallback;
username login + inline errors; CLI skill publish/update; picker
polish; math-before-citation render fix.
Docs were split out to a standalone site, so site/ is now landing-page
only. Bumps __version__ to 1.4.6 and adds assets/releases/ver1-4-6.md.
Folds in mypy fixes surfaced by pre-commit (mineru/local Path typing,
knowledge/manager no-redef, explore_context token kwargs, CLI
set_dist_tag capability probe) plus prettier reformatting of
previously-committed web files.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Stability release after v1.3.0 covering safer RAG/KB routing, stronger
embedding validation, more reliable Docker/TutorBot restarts, Web UX
fixes, and Windows/encoding hardening. See assets/releases/ver1-3-1.md
for the full notes.
Made-with: Cursor