{"record":{"id":"de7edfedcaf971b8","repo":"agentscope-ai/agentscope","slug":"credential-record-data-embedding-model-config-cre","errorCode":null,"errorMessage":"Credential {record.data.embedding_model_config.credential_id!r} for knowledge base {knowledge_base_id!r} not found.","messagePattern":"Credential (.+?) for 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":197,"sourceCode":"            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            )\n        embedding_model = build_embedding_model(\n            credential_record=credential_record,\n            config=record.data.embedding_model_config,\n        )\n        return KnowledgeBase(\n            name=record.data.name,\n            description=record.data.description,\n            embedding_model=embedding_model,\n            vector_store=self._vector_store,\n            collection=record.data.collection_name,\n            metadata_filter=None,\n        )\n","sourceCodeStart":179,"sourceCodeEnd":214,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/rag/knowledge_base_manager/_collection_per_kb.py#L179-L214","documentation":"After a knowledge base record is found, get_knowledge loads the embedding model credential referenced by record.data.embedding_model_config.credential_id. If that credential was deleted (or never existed), it also raises KnowledgeBaseNotFoundError — deliberately reusing the 'KB not found' type so a dangling credential renders the KB unresolvable rather than failing later at model-build time.","triggerScenarios":"Calling manager.get_knowledge for a KB whose embedding credential_id points to a deleted/rotated credential record in storage; common after credential rotation scripts or manual DB cleanup that orphaned KB configs.","commonSituations":"Credential rotation that deletes old entries while KBs still reference them; tenant data imported without credentials; admin deleting API keys from a console without checking dependent KBs; user_id mismatch when reading the credential.","solutions":["Re-create or re-link the credential and update the KB's embedding_model_config.credential_id","Audit for orphaned credential references: iterate KBs and verify each credential_id resolves","When rotating credentials, upsert the new one and repoint KBs before deleting the old","Surface this to users as 'knowledge base is misconfigured — reconnect your embedding provider'"],"exampleFix":"# before\nkb = await manager.get_knowledge(user_id, kb_id)\n# KnowledgeBaseNotFoundError: Credential '...' for knowledge base ... not found.\n\n# after\n# repair: re-point the KB at a valid credential, then\nkb = await manager.get_knowledge(user_id, kb_id)","handlingStrategy":"try-catch","validationCode":"record = await storage.get_knowledge_base(user_id, kb_id)\ncred = await storage.get_credential(user_id, record.data.embedding_model_config.credential_id)\nif cred is None:\n    raise RuntimeError(f'KB {kb_id} references missing credential; repair config')","typeGuard":"null","tryCatchPattern":"from agentscope.app.rag import KnowledgeBaseNotFoundError\ntry:\n    kb = await manager.get_knowledge(user_id, kb_id)\nexcept KnowledgeBaseNotFoundError as e:\n    if 'Credential' in str(e):\n        ...  # KB config is broken: re-link credential\n    else:\n        ...  # KB genuinely missing","preventionTips":["Rotate credentials with upsert + repoint before deleting old ones","Run a periodic audit that resolves every KB's credential_id","When importing tenant data, import credentials first"],"tags":["rag","knowledge-base","credential","dangling-reference","not-found"],"backgroundTag":"dangling-foreign-key","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}