{"record":{"id":"f5f324cf95d95f5a","repo":"weaviate/weaviate","slug":"failed-to-get-bucket","errorCode":null,"errorMessage":"failed to get bucket","messagePattern":"failed to get bucket","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/vector/flat/metadata.go","lineNumber":275,"sourceCode":"\t\tif i > maxCursorSize {\n\t\t\tbreak\n\t\t}\n\t\ti++\n\t}\n\treturn 0\n}\n\nfunc (index *flat) setDimensions(dimensions int32) error {\n\terr := index.openMetadata()\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer index.closeMetadata()\n\n\terr = index.metadata.Update(func(tx *bolt.Tx) error {\n\t\tb := tx.Bucket([]byte(vectorMetadataBucket))\n\t\tif b == nil {\n\t\t\treturn errors.New(\"failed to get bucket\")\n\t\t}\n\t\tbuf := make([]byte, 4)\n\t\tbinary.LittleEndian.PutUint32(buf, uint32(dimensions))\n\t\treturn b.Put([]byte(\"dimensions\"), buf)\n\t})\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"set dimensions\")\n\t}\n\n\treturn nil\n}\n\n// RQ data persistence and restoration functions\n\nfunc (index *flat) persistRQData() error {\n\tif index.quantizer == nil || index.compressionType == CompressionBQ {\n\t\treturn nil\n\t}","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/vector/flat/metadata.go#L257-L293","documentation":"setDimensions writes the vector dimension count into the 'dimensions' key of the metadata bucket inside a bolt write transaction. If the bucket (created earlier by restoreMetadata) is not present in the transaction, the code aborts with this error, wrapped as 'set dimensions'.","triggerScenarios":"index.setDimensions(dims) is called (from initDimensions backwards-compatibility path when the stored dims value is missing) but tx.Bucket(vectorMetadataBucket) returns nil — i.e. the bucket was never created or the metadata DB was reopened/reset.","commonSituations":"Starting a flat index whose metadata.db was truncated or recreated without restoreMetadata running first; a crash between openMetadata and bucket creation; manually replaced metadata files.","solutions":["Ensure restoreMetadata() (which creates the bucket) runs before setDimensions in the startup path.","If the metadata file is missing the bucket, delete the shard and let the index rebuild/recalculate dimensions from stored vectors.","Restore metadata.db from backup if it was accidentally replaced or truncated.","Upgrade weaviate if this stems from an older write-order bug; the current code creates the bucket before use."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure bucket creation happened before any setDimensions call\nerr := meta.Update(func(tx *bolt.Tx) error {\n    if tx.Bucket([]byte(\"vector_metadata\")) == nil {\n        return errors.New(\"metadata bucket missing; run restoreMetadata first\")\n    }\n    return nil\n})","typeGuard":null,"tryCatchPattern":"if err := idx.SetDimensions(dims); err != nil {\n    if strings.Contains(err.Error(), \"set dimensions\") {\n        // re-run restore to (re)create the bucket, then retry once\n        if rErr := idx.RestoreMetadata(); rErr != nil { return rErr }\n        return idx.SetDimensions(dims)\n    }\n    return err\n}","preventionTips":["Always run restoreMetadata (bucket creation) before dimension writes","Do not replace or truncate metadata.db files manually","Keep startup ordering: openMetadata -> create bucket -> setDimensions","Add a unit test that setDimensions succeeds on a freshly opened metadata DB only after bucket init"],"tags":["go","bolt","storage","dimensions"],"backgroundTag":"bolt-bucket-unavailable","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}