{"record":{"id":"71c821a6feb4a0f7","repo":"agentscope-ai/agentscope","slug":"knowledge-base-knowledge-base-id-r-not-found-71c821","errorCode":null,"errorMessage":"Knowledge base {knowledge_base_id!r} not found.","messagePattern":"Knowledge base (.+?) not found\\.","errorType":"exception","errorClass":"KnowledgeBaseNotFoundError","httpStatus":null,"severity":"error","filePath":"src/agentscope/app/rag/knowledge_base_manager/_collection_per_kb.py","lineNumber":183,"sourceCode":"                The owner user id.\n            knowledge_base_id (`str`):\n                The knowledge base id.\n\n        Returns:\n            `KnowledgeBase`:\n                A runtime handle bound to this knowledge base.\n\n        Raises:\n            `KnowledgeBaseNotFoundError`:\n                If the record does not exist or does not belong to\n                the authenticated user.\n        \"\"\"\n        record = await self._storage.get_knowledge_base(\n            user_id,\n            knowledge_base_id,\n        )\n        if record is None:\n            raise KnowledgeBaseNotFoundError(\n                f\"Knowledge base {knowledge_base_id!r} not found.\",\n            )\n\n        # KB manager is an owner-internal path: the credential lives\n        # under the same owner as the knowledge base, so we read it\n        # directly from storage rather than routing through the access\n        # service (which is only relevant when the viewer differs from\n        # the owner).\n        credential_record = await self._storage.get_credential(\n            record.user_id,\n            record.data.embedding_model_config.credential_id,\n        )\n        if credential_record is None:\n            raise KnowledgeBaseNotFoundError(\n                f\"Credential \"\n                f\"{record.data.embedding_model_config.credential_id!r} for \"\n                f\"knowledge base {knowledge_base_id!r} not found.\",\n            )","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/rag/knowledge_base_manager/_collection_per_kb.py#L165-L201","documentation":"CollectionPerKbManager.get_knowledge looks up the knowledge base by (user_id, knowledge_base_id) in storage; when the record is missing it raises KnowledgeBaseNotFoundError. This is the canonical 'no such KB' signal for the KB-manager path, thrown before any embedding/credential resolution happens.","triggerScenarios":"Calling await manager.get_knowledge(user_id, kb_id) with a kb_id that was never created, was deleted, or belongs to a different user_id (per-user isolation makes cross-user ids appear missing).","commonSituations":"Stale kb ids cached in client state after the KB was deleted; passing an internal id where a public/slug id is expected; multi-tenant bugs passing the wrong user_id; race where the KB is deleted between listing and fetching.","solutions":["Re-list knowledge bases for the user to confirm the id exists and is in scope","Verify you are passing the correct user_id that owns the knowledge base","Treat KnowledgeBaseNotFoundError as 404: clean up references/caches that hold the dead id","If a race is possible (delete during use), catch and retry the list-then-get flow"],"exampleFix":"# before\nkb = await manager.get_knowledge(user_id, kb_id)  # KnowledgeBaseNotFoundError\n\n# after\nfrom agentscope.app.rag import KnowledgeBaseNotFoundError\ntry:\n    kb = await manager.get_knowledge(user_id, kb_id)\nexcept KnowledgeBaseNotFoundError:\n    logger.warning(\"kb %s missing for user %s\", kb_id, user_id)\n    return None","handlingStrategy":"try-catch","validationCode":"kbs = await manager.list_knowledge_bases(user_id)  # or equivalent listing API\nids = {kb.knowledge_base_id for kb in kbs}\nif kb_id not in ids:\n    raise LookupError(f'kb {kb_id} not present for user')","typeGuard":"null","tryCatchPattern":"from agentscope.app.rag import KnowledgeBaseNotFoundError\ntry:\n    kb = await manager.get_knowledge(user_id, kb_id)\nexcept KnowledgeBaseNotFoundError:\n    kb = None  # map to HTTP 404 in your API layer","preventionTips":["Always pair user_id with the kb_id that owns it; never share ids across tenants","Purge cached kb ids when a KB is deleted","Treat KnowledgeBaseNotFoundError as 404, not as an internal error"],"tags":["rag","knowledge-base","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}