{"record":{"id":"db64a66c24890932","repo":"litedb-org/LiteDB","slug":"0-db64a6","errorCode":"0","errorMessage":"Vector data block is corrupted.","messagePattern":"Vector data block is corrupted\\.","errorType":"exception","errorClass":"LiteException","httpStatus":null,"severity":"critical","filePath":"LiteDB/Engine/Services/VectorIndexService.cs","lineNumber":722,"sourceCode":"                return Array.Empty<float>();\n            }\n\n            var totalBytes = dimensions * sizeof(float);\n            var vector = new float[dimensions];\n            var bytesCopied = 0;\n\n            foreach (var slice in this.GetVectorDataService().Read(node.ExternalVector))\n            {\n                if (bytesCopied >= totalBytes)\n                {\n                    break;\n                }\n\n                var available = Math.Min(slice.Count, totalBytes - bytesCopied);\n\n                if ((available & 3) != 0)\n                {\n                    throw new LiteException(0, \"Vector data block is corrupted.\");\n                }\n\n                Buffer.BlockCopy(slice.Array, slice.Offset, vector, bytesCopied, available);\n                bytesCopied += available;\n            }\n\n            if (bytesCopied != totalBytes)\n            {\n                throw new LiteException(0, \"Vector data block is incomplete.\");\n            }\n\n            return vector;\n        }\n\n        private PageAddress StoreVector(float[] vector)\n        {\n            if (vector.Length == 0)\n            {","sourceCodeStart":704,"sourceCodeEnd":740,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Engine/Services/VectorIndexService.cs#L704-L740","documentation":"Thrown by VectorIndexService.ReadExternalVector when a byte slice read from the vector data block has a length not aligned to 4 bytes (sizeof(float)). Vector data is floats, so any non-multiple-of-4 region indicates the stored vector data block is byte-level corrupted or was truncated mid-float.","triggerScenarios":"Reading a vector index node whose external vector data pages were corrupted: physical disk corruption, a partial/unflushed write, an interrupted checkpoint, or a file edited outside LiteDB. Also possible after a version/format mismatch in the vector index layout.","commonSituations":"Power loss or process kill during a vector index write without WAL recovery; copying a .db file while open; storage hardware errors; upgrading across incompatible vector-index formats; concurrent manual file access.","solutions":["Restore the database from a known-good backup.","Run db.Rebuild() (full checkpoint + rebuild) to drop/recreate indexes; then recreate the vector index.","Ensure clean shutdowns and that no external process touches the .db/-log files while open.","Enable and verify WAL checkpoint completion before backups."],"exampleFix":"// before - read hits corrupted vector pages\nvar v = collection.VectorFind(\"emb\", query);\n\n// after - rebuild indexes then retry\nusing var db = new LiteDatabase(\"app.db\");\ndb.Rebuild();                       // rebuilds/drops corrupt indexes\ncollection.EnsureVectorIndex(\"emb\", 128);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var results = collection.VectorFind(\"emb\", q); }\ncatch (LiteException ex) when (ex.Message.Contains(\"Vector data block is corrupted\")) {\n    // rebuild vector index, then retry or report\n    collection.DropIndex(\"emb\"); collection.EnsureVectorIndex(\"emb\", dims);\n}","preventionTips":["Keep backups and run db.Rebuild() after suspected corruption.","Prevent external processes from touching open .db files.","Ensure clean shutdowns so WAL checkpoints complete."],"tags":["vector-index","corruption","storage","read"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}