{"record":{"id":"56bf43694deb4084","repo":"Budibase/budibase","slug":"knowledge-base-not-found-56bf43","errorCode":null,"errorMessage":"Knowledge base not found","messagePattern":"Knowledge base not found","errorType":"http","errorClass":"HTTPError","httpStatus":404,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts","lineNumber":56,"sourceCode":"  buffer: Buffer\n  uploadedBy: string\n}\n\nconst buildKnowledgeBaseFileObjectStoreKey = (\n  workspaceId: string,\n  knowledgeBaseId: string,\n  fileId: string,\n  filename: string\n) =>\n  `${workspaceId}/ai/knowledge-bases/${knowledgeBaseId}/files/${fileId}/${filename}`\n\nexport const uploadKnowledgeBaseFile = async (\n  input: UploadKnowledgeBaseFileInput\n): Promise<KnowledgeBaseFile> => {\n  const workspaceId = context.getOrThrowWorkspaceId()\n  const knowledgeBase = await findKnowledgeBase(input.knowledgeBaseId)\n  if (!knowledgeBase) {\n    throw new HTTPError(\"Knowledge base not found\", 404)\n  }\n\n  const fileId = docIds.generateKnowledgeBaseFileID(input.knowledgeBaseId)\n  const objectStoreKey = buildKnowledgeBaseFileObjectStoreKey(\n    workspaceId,\n    input.knowledgeBaseId,\n    fileId,\n    input.filename\n  )\n  const startedAtMs = Date.now()\n  console.log(\"Starting knowledge base file upload\", {\n    workspaceId,\n    knowledgeBaseId: input.knowledgeBaseId,\n    fileId,\n    filename: input.filename,\n    mimetype: input.mimetype,\n    size: input.size ?? input.buffer.byteLength,\n    sourceType: input.source?.type,","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts#L38-L74","documentation":"uploadKnowledgeBaseFile first resolves the target knowledge base via findKnowledgeBase(input.knowledgeBaseId); if no such knowledge base doc exists in the workspace DB, it throws HTTPError 404 before writing anything to object storage. This prevents orphaned files being uploaded to a non-existent KB.","triggerScenarios":"Calling uploadKnowledgeBaseFile with a knowledgeBaseId that does not exist in the current workspace DB — wrong ID, deleted KB, or the request running against the wrong workspace context.","commonSituations":"Client kept a form open after the KB was deleted; ID copied from another app/workspace; missing or wrong workspace ID in request context so findKnowledgeBase looks in the wrong DB; typo in knowledgeBaseId in an API call.","solutions":["Verify the knowledgeBaseId exists (list knowledge bases or fetch it) before uploading","Ensure the request carries the correct workspace/app context so context.getOrThrowWorkspaceId resolves the right DB","If the KB was deleted, recreate it or discard the upload","Correct any typo'd/mismatched knowledgeBaseId in the client call"],"exampleFix":"// before\nawait uploadKnowledgeBaseFile({ knowledgeBaseId: staleId, ... }) // 404\n// after\nconst kbs = await sdk.ai.knowledgeBase.list()\nif (!kbs.some(kb => kb._id === knowledgeBaseId)) throw new Error(\"Pick a valid KB\")\nawait uploadKnowledgeBaseFile({ knowledgeBaseId, ... })","handlingStrategy":"validation","validationCode":"import { find as findKnowledgeBase } from \"./crud\"\nconst kb = await findKnowledgeBase(knowledgeBaseId).catch(() => null)\nif (!kb) throw new Error(`Knowledge base ${knowledgeBaseId} does not exist`)","typeGuard":null,"tryCatchPattern":"try {\n  await uploadKnowledgeBaseFile({ knowledgeBaseId, ... })\n} catch (e) {\n  if (e instanceof HTTPError && e.status === 404) {\n    // prompt user to select/recreate a knowledge base\n  }\n}","preventionTips":["Resolve KBs from the server list, never from stale client state","Refresh KB selections after any delete","Ensure requests carry the correct workspace/app context headers"],"tags":["http-404","not-found","validation"],"backgroundTag":"resource-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}