{"record":{"id":"d56e222f992bb3d6","repo":"Budibase/budibase","slug":"knowledge-base-id-not-set","errorCode":null,"errorMessage":"Knowledge base id not set","messagePattern":"Knowledge base id not set","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts","lineNumber":160,"sourceCode":"      error,\n    })\n    await objectStore\n      .deleteFile(ObjectStoreBuckets.APPS, objectStoreKey)\n      .catch(() => {\n        // Ignore, it might not exist\n      })\n    throw error\n  }\n}\n\nexport const resetKnowledgeBaseStore = async (\n  knowledgeBase: GeminiKnowledgeBase\n): Promise<void> => {\n  const db = context.getWorkspaceDB()\n  const workspaceId = context.getOrThrowWorkspaceId()\n  const knowledgeBaseId = knowledgeBase._id\n  if (!knowledgeBaseId) {\n    throw new HTTPError(\"Knowledge base id not set\", 400)\n  }\n\n  const newGoogleFileStoreId = await createGeminiFileStore(knowledgeBase.name)\n\n  const updated: GeminiKnowledgeBase = {\n    ...knowledgeBase,\n    config: { googleFileStoreId: newGoogleFileStoreId },\n  }\n  const { rev } = await db.put(updated)\n  updated._rev = rev\n\n  await deleteGeminiVectorStore(knowledgeBase.config.googleFileStoreId).catch(\n    (error: any) => {\n      if (error?.status !== 403 && error?.status !== 404) {\n        console.error(\"Failed to delete old Gemini vector store\", {\n          vectorStoreId: knowledgeBase.config.googleFileStoreId,\n          error,\n        })","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts#L142-L178","documentation":"resetKnowledgeBaseStore recreates a Gemini file store for a knowledge base and re-enqueues all of its files. It is typed to accept a GeminiKnowledgeBase that has been persisted, so an _id is expected. This guard throws a 400 HTTPError when the passed document has no _id, i.e. it is an unsaved object rather than a fetched/persisted knowledge base record.","triggerScenarios":"Calling resetKnowledgeBaseStore with a knowledge base object that was constructed in memory (spread/merged or newly created) and never written to the workspace DB, so knowledgeBase._id is undefined.","commonSituations":"Code that builds a new knowledge base doc before db.put, or clones an existing doc into a new variable and loses the _id field, then calls reset on it. Also possible when deserialization drops the _id field.","solutions":["Persist (or fetch) the knowledge base so it has an _id before calling resetKnowledgeBaseStore.","Verify the object passed in is not a fresh literal — spread operations copy _id only if present on the source.","Log knowledgeBase before the call to confirm _id and _rev are present."],"exampleFix":"// before\nawait resetKnowledgeBaseStore({ name: \"Docs KB\", config: oldConfig })\n// after\nconst kb = await db.get<GeminiKnowledgeBase>(existingKbId)\nawait resetKnowledgeBaseStore(kb)","handlingStrategy":"validation","validationCode":"if (!knowledgeBase?._id) {\n  throw new Error(\"Cannot reset a knowledge base that has not been saved\")\n}\nawait resetKnowledgeBaseStore(knowledgeBase)","typeGuard":"const isPersistedKnowledgeBase = (\n  kb: GeminiKnowledgeBase\n): kb is GeminiKnowledgeBase & { _id: string } =>\n  typeof kb._id === \"string\" && kb._id.length > 0","tryCatchPattern":null,"preventionTips":["Always fetch knowledge bases from the workspace DB before resetting them, never pass in-memory literals.","After db.put, refresh _id/_rev on your local variable before further SDK calls."],"tags":["validation","knowledge-base","missing-id","http-400"],"backgroundTag":"missing-entity-id","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}