Budibase/budibase · error · HTTPError

Knowledge base id not set

Error message

Knowledge base id not set

What it means

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.

Source

Thrown at packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts:160

      error,
    })
    await objectStore
      .deleteFile(ObjectStoreBuckets.APPS, objectStoreKey)
      .catch(() => {
        // Ignore, it might not exist
      })
    throw error
  }
}

export const resetKnowledgeBaseStore = async (
  knowledgeBase: GeminiKnowledgeBase
): Promise<void> => {
  const db = context.getWorkspaceDB()
  const workspaceId = context.getOrThrowWorkspaceId()
  const knowledgeBaseId = knowledgeBase._id
  if (!knowledgeBaseId) {
    throw new HTTPError("Knowledge base id not set", 400)
  }

  const newGoogleFileStoreId = await createGeminiFileStore(knowledgeBase.name)

  const updated: GeminiKnowledgeBase = {
    ...knowledgeBase,
    config: { googleFileStoreId: newGoogleFileStoreId },
  }
  const { rev } = await db.put(updated)
  updated._rev = rev

  await deleteGeminiVectorStore(knowledgeBase.config.googleFileStoreId).catch(
    (error: any) => {
      if (error?.status !== 403 && error?.status !== 404) {
        console.error("Failed to delete old Gemini vector store", {
          vectorStoreId: knowledgeBase.config.googleFileStoreId,
          error,
        })

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Persist (or fetch) the knowledge base so it has an _id before calling resetKnowledgeBaseStore.
  2. Verify the object passed in is not a fresh literal — spread operations copy _id only if present on the source.
  3. Log knowledgeBase before the call to confirm _id and _rev are present.

Example fix

// before
await resetKnowledgeBaseStore({ name: "Docs KB", config: oldConfig })
// after
const kb = await db.get<GeminiKnowledgeBase>(existingKbId)
await resetKnowledgeBaseStore(kb)
Defensive patterns

Strategy: validation

Validate before calling

if (!knowledgeBase?._id) {
  throw new Error("Cannot reset a knowledge base that has not been saved")
}
await resetKnowledgeBaseStore(knowledgeBase)

Type guard

const isPersistedKnowledgeBase = (
  kb: GeminiKnowledgeBase
): kb is GeminiKnowledgeBase & { _id: string } =>
  typeof kb._id === "string" && kb._id.length > 0

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/d56e222f992bb3d6. Report an issue: GitHub.