unslothai/unsloth · error · HTTPException
Document not found
Error message
Document not found
What it means
_require_document_owner() verifies a document still belongs to a live scope: if document.kb_id is set but store.get_kb(conn, kb_id) is None, HTTP 404 'Document not found' is raised. It prevents acting on documents whose owning knowledge base has been deleted (even if the document row lingers).
Source
Thrown at studio/backend/routes/rag.py:359
exists = store.get_kb(conn, scope_id) is not None
else:
owner_conn = _rag_connection()
try:
exists = store.get_kb(owner_conn, scope_id) is not None
finally:
owner_conn.close()
detail = "Knowledge base not found"
else:
from storage.studio_db import get_chat_project
exists = get_chat_project(scope_id) is not None
detail = "Project not found"
if not exists:
raise HTTPException(status_code = 404, detail = detail)
def _require_document_owner(conn: sqlite3.Connection, document: dict) -> None:
if document.get("kb_id") and store.get_kb(conn, document["kb_id"]) is None:
raise HTTPException(status_code = 404, detail = "Document not found")
if document.get("project_id"):
from storage.studio_db import get_chat_project
if get_chat_project(document["project_id"]) is None:
raise HTTPException(status_code = 404, detail = "Document not found")
def _create_linked_folder(scope_type: str, scope_id: str, payload: LinkFolderRequest) -> dict:
path, signed_identity = _resolve_linked_folder_path(payload.native_path_lease)
try:
with folder_sync.scope_lock(_scope_for_owner(scope_type, scope_id)):
_require_scope_owner(scope_type, scope_id)
folder, job_id = folder_sync.create_folder_with_sync(
scope_type = scope_type,
scope_id = scope_id,
path = path,
expected_identity = signed_identity,
name = payload.name,
auto_sync = payload.auto_sync,View on GitHub (pinned to 203007d190)
Solutions
- Reload the documents from a live knowledge base and drop references to documents of the deleted one.
- If the KB should still exist, check the KB list / deletion job logs (retire_and_delete_kb may have completed asynchronously).
- Clean orphaned document rows if the KB deletion was itself interrupted.
Defensive patterns
Strategy: type-guard
Validate before calling
const docs = await api.listDocuments(kbId); // 404 here means the KB is gone
const live = docs.some(d => d.id === wantedId);
if (!live) { removeFromUi(wantedId); } Try / catch
if (e.status === 404 && e.detail === 'Document not found') { removeDocumentRow(documentId); } Prevention
- Drop document references as soon as their owning KB disappears from the list.
- After deleting a KB, clear every cached document of its scope.
- Consider KB-deleted events to push-invalidate open document panels.
When it happens
Trigger: Requesting a document (download, delete, status) whose kb_id references a knowledge base that no longer exists — typically a KB deleted while the document list was still open in the UI.
Common situations: KB deleted in another tab/session after the document list loaded; orphaned document rows from an interrupted KB deletion; stale document ID from a previous workspace.
Related errors
- Knowledge base not found
- Knowledge base is being deleted
- RAG is unavailable: the sqlite-vec extension could not be lo
- Unsupported file type '{ext}'. Allowed: {sorted(config.UPLOA
- File exceeds the {cap // (1024 * 1024)} MB upload limit.
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/0814eea2066d4345.
Report an issue: GitHub.